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

Add segmented transaction get method #6484

Closed
wants to merge 6 commits into from

Conversation

jframe
Copy link
Contributor

@jframe jframe commented Jan 29, 2024

PR description

Add segmented transaction get method. This is needed to fully implement the reference counting for code storage changes to move to hashing by code hash.

Fixed Issue(s)

Copy link

github-actions bot commented Jan 29, 2024

  • I thought about documentation and added the doc-change-required label to this PR if updates are required.
  • I thought about the changelog and included a changelog update if required.
  • If my PR includes database changes (e.g. KeyValueSegmentIdentifier) I have thought about compatibility and performed forwards and backwards compatibility tests

Signed-off-by: Jason Frame <[email protected]>
@jframe jframe added the TeamGroot GH issues worked on by Groot Team label Jan 29, 2024
@jframe jframe marked this pull request as ready for review January 30, 2024 00:34
Copy link
Contributor

@siladu siladu left a comment

Choose a reason for hiding this comment

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

LGTM. Like the tests. I will leave for a storage expert to approve

}

@Test
void txGet_returnsUpdatedValueAfterPutPut() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Love the name 😁

@Override
public Optional<byte[]> get(final SegmentIdentifier segmentId, final byte[] key)
throws StorageException {
checkState(active, "Cannot invoke get() on a completed transaction.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we invoke get on a completed transaction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For a get maybe it is fine? I was just following the pattern that the other methods did which was not operations on a completed transaction. Hopefully, a storage expert will know the answer.

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 it makes sense to throw in this case cause we want to avoid returning values we are uncertain if it's going to be committed or not. Think chances are minimal but there is a scenario where this could happen. @garyschulte what you reckon?

public Optional<byte[]> get(final SegmentIdentifier segmentIdentifier, final byte[] key) {
return updatedValues
.computeIfAbsent(segmentIdentifier, __ -> new HashMap<>())
.getOrDefault(Bytes.wrap(key), Optional.empty());
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking my understanding...if we are computing empty HashMap if absent, then can we ever actually return Optional.empty() here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we use this InMemory class for writing data to the database (i.e. persisting this state) or only for reading data and/or unit tests?

Copy link
Contributor Author

@jframe jframe Jan 30, 2024

Choose a reason for hiding this comment

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

Just checking my understanding...if we are computing empty HashMap if absent, then can we ever actually return Optional.empty() here?

We can return an Optional.empty() because this is used to create the Map holding values for a particular segment identifier. And if we try and get a value for a segment identifier that doesn't have any updates then we create the new map and return an Optional.empty()

@jframe jframe removed the TeamGroot GH issues worked on by Groot Team label Jan 31, 2024
@jframe
Copy link
Contributor Author

jframe commented Feb 5, 2024

No longer needed with current approach of not deleting self-destruct from code column

@jframe jframe closed this Feb 5, 2024
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