-
Notifications
You must be signed in to change notification settings - Fork 652
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
ensure hashmap init clears maps #794
Conversation
ae047db
to
7ca2922
Compare
freelist_test.go
Outdated
f := newTestFreelist() | ||
f.readIDs([]common.Pgid{5, 6, 8}) | ||
|
||
p := (*common.Page)(unsafe.Pointer(&buf[0])) |
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.
p := (*common.Page)(unsafe.Pointer(&buf[0])) | |
p := common.LoadPage(buf) |
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.
applied
freelist_test.go
Outdated
@@ -179,6 +179,29 @@ func TestFreelist_releaseRange(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestFreeList_reload_page_dedupe(t *testing.T) { | |||
var buf [4096]byte |
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.
var buf [4096]byte | |
buf := make([]byte, 4096) |
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.
applied
freelist_test.go
Outdated
f2.free(common.Txid(5), common.NewPage(5, common.LeafPageFlag, 0, 4)) | ||
// reload should deduplicate as a pending page when reading from p's freelist | ||
f2.reload(p) | ||
|
||
if len(f2.getFreePageIDs()) != 0 { | ||
t.Fatalf("expected empty; got=%v", f2.getFreePageIDs()) | ||
} | ||
if exp := []common.Pgid{5, 6, 7, 8, 9}; !reflect.DeepEqual(exp, f2.pending[5].ids) { | ||
t.Fatalf("exp=%v; got=%v", exp, f2.pending[5].ids) | ||
} |
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 test is a little misleading.
- If you reload (line 195) freelist, then you should also init/
readIDs
the freelist (f2) in the first place. - In real production use case, the only case to call
reload
if when we need to rollback a writing TXN. But in this case, you do not rollback the freelist before callingreload
.
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.
Added your first suggestion. As for the second, we should hide the reload behind a Rollback
as another refactoring step for #789
As of today, nothing stops you from reloading without the rollback.
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.
Happy to hear other suggestions on how to replicate that inconsistent behavior though, feel free to send an alternative unit test.
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.
As of today, nothing stops you from reloading without the rollback.
It means the interface isn't well designed. We need to continue to refactor the interface from users perspective. Will think about it.
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've rebased it against the refactoring now, let me know whether this is worth fixing or not. Otherwise we can close.
7ca2922
to
6f4711a
Compare
6f4711a
to
1c3873f
Compare
1c3873f
to
8e104b4
Compare
f2.Free(common.Txid(5), common.NewPage(5, common.LeafPageFlag, 0, 4)) | ||
|
||
// reload should deduplicate as a pending page when reading from p's freelist | ||
f2.Reload(p) |
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.
When you reload the freelist from a page, it means you already read the freelist from the page in the first place.
Please see the proposed unit test cases. We can revisit them when we update the interface later.
|
Works for me, there's still some nil/empty inconsistency:
similar to here, I had to fix it with: |
5801f43
to
23807ad
Compare
This reorders some statements in the hashmap initialization to ensure we always start fresh, even when no pageids were passed to it. fixes etcd-io#791 Signed-off-by: Thomas Jungblut <[email protected]>
23807ad
to
cb0ecea
Compare
okay that required a bit more empty/nil changes unfortunately. I'll leave those as a separated commit now.... |
This also rectifies a bunch of nil/empty differences between the implementation that show up during init and page releases. Signed-off-by: Thomas Jungblut <[email protected]>
cb0ecea
to
f4de460
Compare
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.
LGTM
cc @fuweid
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahrtr, tjungblu The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This reorders some statements in the hashmap initialization to ensure we always start fresh, even when no pageids were passed to it.
fixes #791
--
Might be better to fix this before #775? would make an easier backport.