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

DynamoDB Reminders load using GSI #7437

Merged
merged 4 commits into from Jan 6, 2022

Conversation

michaeltdaniels
Copy link
Contributor

@michaeltdaniels michaeltdaniels commented Dec 10, 2021

Fixes #7434

Microsoft Reviewers: Open in CodeFlow

@dnfadmin
Copy link

dnfadmin commented Dec 10, 2021

CLA assistant check
All CLA requirements met.

Copy link
Member

@galvesribeiro galvesribeiro left a comment

Choose a reason for hiding this comment

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

Good catch! Thanks! LGTM

{ $":Begin{GRAIN_HASH_PROPERTY_NAME}", new AttributeValue { N = begin.ToString() } },
{ $":End{GRAIN_HASH_PROPERTY_NAME}", new AttributeValue { N = end.ToString() } }
};
expression = $"{SERVICE_ID_PROPERTY_NAME} = :{SERVICE_ID_PROPERTY_NAME} AND {GRAIN_HASH_PROPERTY_NAME} BETWEEN :Begin{GRAIN_HASH_PROPERTY_NAME} AND :End{GRAIN_HASH_PROPERTY_NAME}";
Copy link
Member

Choose a reason for hiding this comment

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

Please correct me if I'm wrong, but I believe this changes the query semantics. It's supposed to be > Begin && <= End (non-inclusive lower bound, inclusive upper), but BETWEEN is equivalent to => Begin && <= End (inclusive bounds)

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 you're correct. Since performing a dynamodb query with an AND is not possible, would it be sufficient to pass the end attribute value as end-1 and still use BETWEEN?

Copy link
Member

Choose a reason for hiding this comment

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

@ReubenBond is correct. The query semantics are changed. I've overlooked this. The original one was correct. Are you sure this passed the unit tests? I remember the reminder tests being very nitpick about this.

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 missed an unrelated change in DynamoDBStorage that has now been corrected.
AWUtils.Tests.RemindersTest passes with the questionable code as-is, and also if I change line 167 to (end - 1).ToString(), which I believe is the correct change to make.

Copy link
Member

@ReubenBond ReubenBond Jan 6, 2022

Choose a reason for hiding this comment

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

Shouldn't it be begin + 1, rather than end - 1? The lower bound is supposed to be exclusive, not the upper bound.
It will work but please wrap the expression in unchecked(...) , since it's possible for it to overflow, just to make it extra obvious that it's expected behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, thank you - vacation brain hasn't recovered yet.

Copy link
Member

Choose a reason for hiding this comment

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

No sweat, I'm in the same boat

Copy link
Member

Choose a reason for hiding this comment

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

Of course... it's impossible for both begin < end and begin == uint.MaxValue to be true at the same time, so the unchecked is entirely meaningless as no overflow is possible 😅

{ $":{SERVICE_ID_PROPERTY_NAME}", new AttributeValue(this.serviceId) },
{ $":End{GRAIN_HASH_PROPERTY_NAME}", new AttributeValue { N = end.ToString() } }
};
expression = $"{SERVICE_ID_PROPERTY_NAME} = :{SERVICE_ID_PROPERTY_NAME} AND {GRAIN_HASH_PROPERTY_NAME} <= :End{GRAIN_HASH_PROPERTY_NAME}";
Copy link
Member

Choose a reason for hiding this comment

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

This query should be <= End || > Begin (since "end" is smaller than "begin", it's a wrap-around query).

Here's a graphical depiction of the two queries, where a circle represents an exclusive bound and a bar represents an inclusive bound:

image

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, the original query had this right: > Begin or <= End: it's a conjunction of two queries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally, this was performing a scan. I don't believe you can perform a query with the "or" clause, and thus I split the scan into two queries, then combine the results.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see now. That's an odd limitation, but nevertheless this seems fine.

@ReubenBond ReubenBond added this to the 3.6.0 milestone Jan 6, 2022
@ReubenBond ReubenBond merged commit 7dca60e into dotnet:3.x Jan 6, 2022
@ReubenBond
Copy link
Member

Needs to be ported to main

@michaeltdaniels michaeltdaniels deleted the fix/dynamodb-reminders/gsi branch January 6, 2022 21:28
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request May 5, 2022
* DynamoDB Reminders load using GSI

* Update DynamoDBStorage.cs

* Update DynamoDBReminderTable.cs

* Update DynamoDBReminderTable.cs

Co-authored-by: Reuben Bond <203839+ReubenBond@users.noreply.github.com>
ReubenBond added a commit that referenced this pull request May 5, 2022
* DynamoDB Reminders load using GSI

* Update DynamoDBStorage.cs

* Update DynamoDBReminderTable.cs

* Update DynamoDBReminderTable.cs

Co-authored-by: Reuben Bond <203839+ReubenBond@users.noreply.github.com>

Co-authored-by: michaeltdaniels <45430678+michaeltdaniels@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Dec 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants