-
Notifications
You must be signed in to change notification settings - Fork 665
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
Move sub bucket #625
Move sub bucket #625
Conversation
…nother bucket Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
bucket_test.go
Outdated
if v == nil { | ||
t.Fatal() | ||
} | ||
//curDst := dstBucket.Cursor() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to use seek()
to verify the subBucket is moved correctly, but I got stuck :/
I still need to
- check for cornet cases
- verify that
// 1. the sub-bucket cannot be found in the source bucket;
// 2. or the key already exists in the destination bucket;
// 3. the key represents a non-bucket value.
ptal if i am on the right path, otherwise correct me please ( fail fast ) :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @ahrtr ^^
381b51e
to
accffe2
Compare
@ahrtr i finished the test, i covered all the possible cases iiuc :) ptal |
// 1. the sub-bucket cannot be found in the source bucket; | ||
// 2. or the key already exists in the destination bucket; | ||
// 3. the key represents a non-bucket value. | ||
func (tx *Tx) MoveSubBucket(name []byte, src *Bucket, dst *Bucket) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems tx
is unused here. I think we don't need this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
I was thinking to support moving top level bucket. In that case, no need to provide the source bucket, the signature & implementation will be below,
func (tx *Tx) MoveSubBucket(name []byte, src *Bucket, dst *Bucket) error {
if src != nil {
return src.MoveSubBucket(name, dst)
}
return tx.root.MoveSubBucket(name, dst)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Elbehery Could you help to update it in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. tx.root
is root bucket.
name string | ||
srcBucketName string | ||
subBucketName string | ||
subBucketKey string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add a case to create non-inline sub bucket here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u mean to use the src bucket as root
bucket ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the bucket, if the key or sub-bucket is small, the bucket can store those in value. It' s inline type.
If the key/value is large enough to allocate new page(s) for that, the bucket value only stores the root page id.
Just want to verify these two cases.
Yeah, since you change the tx.MoveSubBucket
to support root bucket, it should add some cases to cover that.
t.Fatalf("dst bucket %s does not exist: %v", tc.dstBucketName, berrors.ErrBucketNotFound) | ||
} | ||
|
||
mvErr := tx.MoveSubBucket([]byte(tc.subBucketName), srcBucket, dstBucket) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accffe2
to
51e0df3
Compare
Signed-off-by: Mustafa Elbehery <melbeher@redhat.com>
51e0df3
to
148da9e
Compare
nil, | ||
}, | ||
{ | ||
"subBucket not exist in root bucket", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dst could be nil as well. Please take a look at the original PR.
subBucketExistDstBucket bool | ||
keyNoSubBucketSrcBucket bool | ||
keyNoSubBucketDstBucket bool | ||
expErr error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, it looks good to me.
For the test case, I was thinking about that introducing slice to define the path, since it's hard to follow the code with too many bools here.
During preparing data, that test case can use srcBucketPath []string
to define depth of bucket. For instance,
[x, y, z]
. The bucket will be like root -> x -> y -> z
. srcKeyValues [][2]string
is to define key value in the srcBucketPath
. If it's empty, That z
doesn't contain any key values. It also applies to dst
.
If there is no expected error, the root -> x -> y -> z
should be not found and that z
should show in dstBucketPath
. And all the srcKeyValues
should be stored in dstBucketPath -> z
.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can change it, but i think the booleans are easier for a reader to understand the what & how
maybe the bool names needs to be more self explanatory
wdyt @ahrtr @serathius @tjungblu
I updated the original PR #621, Please take a look. |
High level the test workflow including three steps make sense,
Comments:
|
Sorry, the PR is automatically closed after renaming the master to main. Please feel free to submit a new PR. |
cc @ahrtr