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

[Fix]: keyPrefix in DataCache.Find can be all 0xff. #3681

Closed

Conversation

nan01ab
Copy link
Contributor

@nan01ab nan01ab commented Jan 20, 2025

Description

  1. DataCache.Find(keyPrefix, SeekDirection.Forward) start from the first key if keyPrefix is null or empty.
    But DataCache.Find(keyPrefix, SeekDirection.Backword) throws an Exception.
    It's better to keep a similar logic with different SeekDirection.

  2. Allow all 0xff keyPrefix.

This PR depends on #3680

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

action.Should().Throw<ArgumentException>();
action = () => myDataCache.Find(new byte[] { }, SeekDirection.Backward);
action.Should().Throw<ArgumentException>();
// Action action = () => myDataCache.Find(null, SeekDirection.Backward);
Copy link
Member

Choose a reason for hiding this comment

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

Better adjust the logic instead of comment it

@nan01ab nan01ab force-pushed the fix.DataCache-Find-keyPrefix branch from b8b9481 to 06cd75c Compare January 20, 2025 17:09
@nan01ab nan01ab changed the title [Fix]: keyPrefix in DataCache.Find can be null, empty, or all 0xff. [Fix]: keyPrefix in DataCache.Find can be all 0xff. Jan 20, 2025
{
throw new ArgumentException($"{nameof(key_prefix)} with all bytes being 0xff is not supported now");
// This case is rare
seekPrefix = new byte[ApplicationEngine.MaxStorageKeySize + 1];
Copy link
Contributor Author

@nan01ab nan01ab Jan 20, 2025

Choose a reason for hiding this comment

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

MaxStorageKeySize.
Maybe not long enough.

throw new ArgumentException($"{nameof(key_prefix)} with all bytes being 0xff is not supported now");
// This case is rare
seekPrefix = new byte[ApplicationEngine.MaxStorageKeySize + 1];
Array.Fill(seekPrefix, (byte)0xff);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a logic change @shargon?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it is

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 think it doesn't matter.

@nan01ab
Copy link
Contributor Author

nan01ab commented Jan 21, 2025

A better fix #3688

@nan01ab nan01ab closed this Jan 21, 2025
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.

3 participants