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 Merge Operator support to WriteBatchWithIndex #8135

Closed
wants to merge 12 commits into from

Conversation

mrambacher
Copy link
Contributor

The WBWI has two differing modes of operation dependent on the value
of the constructor parameter overwrite_key.
Currently, regardless of the parameter, neither mode performs as
expected when using Merge. This PR remedies this by correctly invoking
the appropriate Merge Operator before returning results from the WBWI.

Examples of issues that exist which are solved by this PR:

Example 1 with overwrite_key=false

Currently, from an empty database, the following sequence:

Put('k1', 'v1')
Merge('k1', 'v2')
Get('k1')

Incorrectly yields v2, that is to say that the Merge behaves like a Put.

Example 2 with overwrite_key=true

Currently, from an empty database, the following sequence:

Put('k1', 'v1')
Merge('k1', 'v2')
Get('k1')

Incorrectly yields ERROR: kMergeInProgress.

Example 3 with overwrite_key=false

Currently, with a database containing ('k1' -> 'v1'), the following sequence:

Merge('k1', 'v2')
GetFromBatchAndDB('k1')

Incorrectly yields v1,v2

Example 4 with overwrite_key=true

Currently, with a database containing ('k1' -> 'v1'), the following sequence:

Merge('k1', 'v1')
GetFromBatchAndDB('k1')

Incorrectly yields ERROR: kMergeInProgress.

Example 5 with overwrite_key=false

Currently, from an empty database, the following sequence:

Put('k1', 'v1')
Merge('k1', 'v2')
GetFromBatchAndDB('k1')

Incorrectly yields v1,v2

Example 6 with overwrite_key=true

Currently, from an empty database, ('k1' -> 'v1'), the following sequence:

Put('k1', 'v1')
Merge('k1', 'v2')
GetFromBatchAndDB('k1')

Incorrectly yields ERROR: kMergeInProgress.

Copy link
Contributor

@pdillinger pdillinger left a comment

Choose a reason for hiding this comment

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

Also update HISTORY.md

@@ -176,6 +176,11 @@ class WriteBatchWithIndex : public WriteBatchBase {
Iterator* NewIteratorWithBase(ColumnFamilyHandle* column_family,
Iterator* base_iterator,
const ReadOptions* opts = nullptr);
Iterator* NewIteratorWithBase(DB* db, Iterator* base_iterator,
Copy link
Contributor

Choose a reason for hiding this comment

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

When is the DB parameter needed? (This is public API.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The DB option is used similarly to the DB option for "GetFromBatchAndBase". Without the DB option, if you see a Merge without a preceding Put/Delete, you cannot get the "initial" value for the key without the DB. If the other signatures are used (without the DB) and a Merge is encountered without a root, then a "MergeInProgress" error is returned.

I can update the comment appropriately when I figure out the wording...

Copy link
Contributor

Choose a reason for hiding this comment

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

Although I don't know this area well, the rest of the PR LGTM, seems like a clear improvement even if it's not perfect.

Someone questioned whether it's a good idea for WBWI to effectively re-implement all the DB logic (without persistence, etc.). I believe it's potentially useful for finding bugs on both sides if we compare them.

@facebook-github-bot
Copy link
Contributor

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

Found a solution that did not require the new API signature.  Updated the code accordingly.  Updated HISTORY
@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@pdillinger pdillinger left a comment

Choose a reason for hiding this comment

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

OK with me!

db/merge_context.h Show resolved Hide resolved
@facebook-github-bot
Copy link
Contributor

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot pushed a commit that referenced this pull request Apr 26, 2021
Summary:
Moves some of the structural refactoring from #8135 into this PR.
This just cleans up the code by moving implementation out of the .h file and into the .cc file.

Should be considered for merge before both #7214 and #8135

Pull Request resolved: #8229

Reviewed By: jay-zhuang

Differential Revision: D27999669

Pulled By: mrambacher

fbshipit-source-id: 6eccecbf1f11bb9f5a173e86d1e7bc448bc96071
@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Attempt to improve code coverage...
@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@mrambacher has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mrambacher merged this pull request in ff46374.

facebook-github-bot pushed a commit that referenced this pull request Jul 24, 2023
Summary:
Remove obsolete comment.

Support for WriteBatchWithIndex::NewIteratorWithBase when overwrite_key=false is added in #8135, as you can clearly see in the HISTORY.md.

Pull Request resolved: #11636

Reviewed By: jowlyzhang

Differential Revision: D47722955

Pulled By: ajkr

fbshipit-source-id: 4fa44a309d9708e9f4a1530918a9aaf7114c9032
rockeet pushed a commit to topling/toplingdb that referenced this pull request Dec 18, 2023
Summary:
Remove obsolete comment.

Support for WriteBatchWithIndex::NewIteratorWithBase when overwrite_key=false is added in facebook/rocksdb#8135, as you can clearly see in the HISTORY.md.

Pull Request resolved: facebook/rocksdb#11636

Reviewed By: jowlyzhang

Differential Revision: D47722955

Pulled By: ajkr

fbshipit-source-id: 4fa44a309d9708e9f4a1530918a9aaf7114c9032
rockeet pushed a commit to topling/toplingdb that referenced this pull request Sep 1, 2024
Summary:
Remove obsolete comment.

Support for WriteBatchWithIndex::NewIteratorWithBase when overwrite_key=false is added in facebook/rocksdb#8135, as you can clearly see in the HISTORY.md.

Pull Request resolved: facebook/rocksdb#11636

Reviewed By: jowlyzhang

Differential Revision: D47722955

Pulled By: ajkr

fbshipit-source-id: 4fa44a309d9708e9f4a1530918a9aaf7114c9032
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants