Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compatibility] Added BZMPOP, BZPOPMAX and BZPOPMIN commands #884

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Vijay-Nirmal
Copy link
Contributor

Adding the BZMPOP, BZPOPMAX and BZPOPMIN commands to garnet

  • Add BZMPOP, BZPOPMAX and BZPOPMIN commands
  • Add Integration Test cases and ACL Test
  • Add documentation

@@ -20,6 +20,12 @@ public CollectionItemResult(byte[] key, byte[][] items)
Items = items;
}

public CollectionItemResult(byte[] key, (double Score, byte[] Element)[] scoredItems)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to create a separate PR in future to remove CollectionItemResult class and replace it with SpanByteAndMemory, Let me know if there is any issue with that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It'd make the code less readable. I'd leave it as-is.

@Vijay-Nirmal Vijay-Nirmal changed the title Added BZMPOP, BZPOPMAX and BZPOPMIN commands [Compatibility] Added BZMPOP, BZPOPMAX and BZPOPMIN commands Dec 16, 2024
Copy link
Contributor

@TalZaccai TalZaccai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice PR! Thanks for the contribution. Added a few comments.

@@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Intrinsics.X86;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mistake?

@@ -886,6 +887,19 @@ private void SortedSetRank(ref ObjectInput input, ref SpanByteAndMemory output,
}
}

public (double Score, byte[] Element) Pop(bool popMaxScoreElement = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an XML comment

@@ -886,6 +887,19 @@ private void SortedSetRank(ref ObjectInput input, ref SpanByteAndMemory output,
}
}

public (double Score, byte[] Element) Pop(bool popMaxScoreElement = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rename this to PopMinOrMax for clarity

@@ -2,6 +2,7 @@
// Licensed under the MIT license.

using System;
using System.Linq;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary using

keysBytes[i] = parseState.GetArgSliceByRef(i).SpanByte.ToByteArray();
}

if (!parseState.TryGetDouble(parseState.Count - 1, out var timeout))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do this verification (as well as the itemBroker one) before the keysBytes allocation

}
else
{
_ = EXPIRE(destinationKey, TimeSpan.Zero, out _, StoreType.Object, ExpireOption.None,
ref lockableContext, ref objectContext);
}

itemBroker.HandleCollectionUpdate(destinationKeyBty);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about SortedSetUnionStore & SortedSetIntersectStore?

@@ -10,7 +10,7 @@

namespace Garnet.test
{
public class RespBlockingListTests
public class RespBlockingTests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming: RespBlockingCollectionTests might be a bit more informative

@@ -20,6 +20,12 @@ public CollectionItemResult(byte[] key, byte[][] items)
Items = items;
}

public CollectionItemResult(byte[] key, (double Score, byte[] Element)[] scoredItems)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It'd make the code less readable. I'd leave it as-is.

/// <summary>
/// Scored items retrieved from collection, where each item has an associated score.
/// </summary>
internal (double Score, byte[] Element)[] ScoredItems { get; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of doing this we should re-use the Item & Items properties to store the elements & have matching double Score and double[] Scores properties.

@@ -389,14 +389,154 @@ public void BlmpopBlockingWithCountTest()
var pushingTask = taskFactory.StartNew(() =>
{
using var lcr = TestUtils.CreateRequest();
Task.Delay(TimeSpan.FromSeconds(2)).Wait();
Task.Delay(TimeSpan.FromSeconds(5)).Wait();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to choose smaller time constants here, as this affects the CI runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants