forked from tecbot/gorocksdb
-
Notifications
You must be signed in to change notification settings - Fork 7
Add a new MergeMultiOperator interface which supports PartialMergeMulti #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
02e913e
Adding PartialMergeMulti
jamesbibby b554c6b
fixing the test
jamesbibby 39c1afb
taking a more opinionated approach and just ditching the left right o…
jamesbibby 1384bf7
Update PartialMerge to be PartialMergeMulti
jamesbibby a3b2f44
New MergeMultiOperator interface
jamesbibby 20539af
Don't embed the MergeOperator in MergeMultiOperator
jamesbibby c1b2da7
Adding a test for merge multi
jamesbibby d0110a4
Separate the interfaces
jamesbibby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package gorocksdb | ||
|
|
||
| // #include "rocksdb/c.h" | ||
| import "C" | ||
|
|
||
| // MergeMultiOperator implements PartialMergeMulti(key []byte, operands [][]byte) ([]byte, err) | ||
| // When a MergeOperator implements this interface, PartialMergeMulti | ||
| // will be used instead of PartialMerge | ||
| type MergeMultiOperator interface { | ||
| // PartialMerge performs merge on multiple operands | ||
| // when all of the operands are themselves merge operation types | ||
| // that you would have passed to a db.Merge() call in the same order | ||
| // (i.e.: db.Merge(key,operand[0]), followed by db.Merge(key,operand[1]), | ||
| // ... db.Merge(key, operand[n])). | ||
| // | ||
| // PartialMerge should combine them into a single merge operation. | ||
| // The return value should be constructed such that a call to | ||
| // db.Merge(key, new_value) would yield the same result as a call | ||
| // to db.Merge(key,operand[0]), followed by db.Merge(key,operand[1]), | ||
| // ... db.Merge(key, operand[n])). | ||
| // | ||
| // If it is impossible or infeasible to combine the operations, return false. | ||
| // The library will internally keep track of the operations, and apply them in the | ||
| // correct order once a base-value (a Put/Delete/End-of-Database) is seen. | ||
| PartialMergeMulti(key []byte, operands [][]byte) ([]byte, bool) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package gorocksdb | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/facebookgo/ensure" | ||
| ) | ||
|
|
||
| func TestMergeMultiOperator(t *testing.T) { | ||
| var ( | ||
| givenKey = []byte("hello") | ||
| startingVal = []byte("foo") | ||
| mergeVal1 = []byte("bar") | ||
| mergeVal2 = []byte("baz") | ||
| fMergeResult = []byte("foobarbaz") | ||
| pMergeResult = []byte("barbaz") | ||
| ) | ||
|
|
||
| merger := &mockMergeMultiOperator{ | ||
| fullMerge: func(key, existingValue []byte, operands [][]byte) ([]byte, bool) { | ||
| ensure.DeepEqual(&fatalAsError{t}, key, givenKey) | ||
| ensure.DeepEqual(&fatalAsError{t}, existingValue, startingVal) | ||
| ensure.DeepEqual(&fatalAsError{t}, operands[0], pMergeResult) | ||
| return fMergeResult, true | ||
| }, | ||
| partialMerge: func(key, leftOperand, rightOperand []byte) ([]byte, bool) { | ||
| t.FailNow() // this should never be called | ||
| return nil, false | ||
| }, | ||
| partialMergeMulti: func(key []byte, operands [][]byte) ([]byte, bool) { | ||
|
akrylysov marked this conversation as resolved.
|
||
| ensure.DeepEqual(&fatalAsError{t}, key, givenKey) | ||
| ensure.DeepEqual(&fatalAsError{t}, operands[0], mergeVal1) | ||
| ensure.DeepEqual(&fatalAsError{t}, operands[1], mergeVal2) | ||
| return pMergeResult, true | ||
| }, | ||
| } | ||
| db := newTestDB(t, "TestMergeOperator", func(opts *Options) { | ||
| opts.SetMergeOperator(merger) | ||
| }) | ||
| defer db.Close() | ||
|
|
||
| wo := NewDefaultWriteOptions() | ||
| defer wo.Destroy() | ||
|
|
||
| // insert a starting value and compact to trigger merges | ||
| ensure.Nil(t, db.Put(wo, givenKey, startingVal)) | ||
|
|
||
| // trigger a compaction to ensure that a merge is performed | ||
| db.CompactRange(Range{nil, nil}) | ||
|
|
||
| // we expect these two operands to be passed to merge multi | ||
| ensure.Nil(t, db.Merge(wo, givenKey, mergeVal1)) | ||
| ensure.Nil(t, db.Merge(wo, givenKey, mergeVal2)) | ||
|
|
||
| // trigger a compaction to ensure that a | ||
| // partial and full merge are performed | ||
| db.CompactRange(Range{nil, nil}) | ||
|
|
||
| ro := NewDefaultReadOptions() | ||
| v1, err := db.Get(ro, givenKey) | ||
| defer v1.Free() | ||
| ensure.Nil(t, err) | ||
| ensure.DeepEqual(t, v1.Data(), fMergeResult) | ||
|
|
||
| } | ||
|
|
||
| type mockMergeMultiOperator struct { | ||
| fullMerge func(key, existingValue []byte, operands [][]byte) ([]byte, bool) | ||
| partialMerge func(key, leftOperand, rightOperand []byte) ([]byte, bool) | ||
| partialMergeMulti func(key []byte, operands [][]byte) ([]byte, bool) | ||
| } | ||
|
|
||
| func (m *mockMergeMultiOperator) Name() string { return "gorocksdb.test" } | ||
| func (m *mockMergeMultiOperator) FullMerge(key, existingValue []byte, operands [][]byte) ([]byte, bool) { | ||
| return m.fullMerge(key, existingValue, operands) | ||
| } | ||
| func (m *mockMergeMultiOperator) PartialMerge(key, leftOperand, rightOperand []byte) ([]byte, bool) { | ||
| return m.partialMerge(key, leftOperand, rightOperand) | ||
| } | ||
| func (m *mockMergeMultiOperator) PartialMergeMulti(key []byte, operands [][]byte) ([]byte, bool) { | ||
| return m.partialMergeMulti(key, operands) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.