-
Notifications
You must be signed in to change notification settings - Fork 649
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 freelist interface unit tests #786
Conversation
a7742ab
to
e00d49d
Compare
23d74f2
to
4a12741
Compare
815322f
to
c4a4b8e
Compare
Please put the changes for freelist.go amd shared.go into a separate PR, which should be able to be merged soon. thx |
Reload and NoSyncReload have duplicated code, this unifies both for later refactoring. This PR is split from etcd-io#786, where the tests found differences on reloading and nil/empty initializations. Added some more clarifications in godocs for certain panic behavior and expected returns on the interface. Signed-off-by: Thomas Jungblut <[email protected]>
Reload and NoSyncReload have duplicated code, this unifies both for later refactoring. This PR is split from etcd-io#786, where the tests found differences on reloading and nil/empty initializations. Added some more clarifications in godocs for certain panic behavior and expected returns on the interface. Signed-off-by: Thomas Jungblut <[email protected]>
629ac9c
to
e53f4c4
Compare
e53f4c4
to
9dc0684
Compare
Thanks @tjungblu . Please signoff the commit, I will take a look later. |
9dc0684
to
24b3ed5
Compare
done, sorry some debug commit got in between |
|
||
func TestInvalidArrayAllocation(t *testing.T) { | ||
f := NewArrayFreelist() | ||
ids := []common.Pgid{1} |
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.
ids := []common.Pgid{1} | |
// page 0 and 1 are reserved for meta pages, so they should never be free pages. | |
ids := []common.Pgid{1} |
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
internal/freelist/freelist_test.go
Outdated
require.Empty(t, f.pendingPageIds()) | ||
require.False(t, f.Freed(12)) | ||
|
||
// we still hold an allotx reference to page 12 through txid 99 - let's try to free it again |
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.
why txid 99? :) page 12 might be allocated by any txid which is < 100.
// we still hold an allotx reference to page 12 through txid 99 - let's try to free it again | |
// Let's try to free it again |
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 removed this comment. txid 99 was because we had this little hack:
d72e6bf#diff-d722be595713f8fc49d086ab1968ff45f223c2b1f99bc0f7ae65fbdde3132c40L70-L73
internal/freelist/freelist_test.go
Outdated
freelist.Free(common.Txid(10), common.NewPage(10, common.LeafPageFlag, 0, 2)) | ||
freelist.Free(common.Txid(11), common.NewPage(20, common.LeafPageFlag, 0, 2)) | ||
freelist.Free(common.Txid(12), common.NewPage(30, common.LeafPageFlag, 0, 2)) |
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.
This doesn't make sense. Only one RW TXN is allowed at a time. The three Free
calls are for three different TXID, it means there are 3 concurrent RW TXNs.
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's a simple test setup, we can sprinkle the free calls around the AddReadOnlyTXID
if this is more sensible and readable for you.
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 think we need to satisfy the following conditions,
- Only one RW TXN is allowed at a time. So yon can't call
Free
with a higher txid before you commit the previous RW TXN. - When you create a readonly TXN, its TXID should equal to the latest committed RW TXN's txid.
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.
shall we add an assertion for this in a separate 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.
shall we add an assertion for this in a separate PR?
It's hard to add such assertion/verification in freelist layer, because the semantics is guaranteed by upper layer (bbolt) instead of freelist. It's also an indication that the freelist API isn't well designed.
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.
Can you move this test into a separate PR so that we can merge this PR? thx
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.
yep, will do. brb
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.
removed
freelist.Free(common.Txid(5), common.NewPage(5, common.LeafPageFlag, 0, 4)) | ||
freelist.Reload(p) | ||
requirePages(t, freelist, common.Pgids{}, common.Pgids{5, 6, 7, 8, 9}) |
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.
We can keep it as it's for now. But actually reload is only used in rollback case, so there should be a rollback operation. We can revisit this when we refactor the interface.
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.
ack
24b3ed5
to
e457dac
Compare
e457dac
to
ca560a1
Compare
@tjungblu please rebase this PR. thx |
ca560a1
to
7348ab8
Compare
adding more unit tests for better coverage of the interface. Signed-off-by: Thomas Jungblut <[email protected]>
7348ab8
to
3ce0fd0
Compare
done, thanks @ahrtr |
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
Thanks @tjungblu
[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 |
Reload and NoSyncReload have duplicated code, this unifies both for later refactoring. This PR is split from etcd-io#786, where the tests found differences on reloading and nil/empty initializations. Added some more clarifications in godocs for certain panic behavior and expected returns on the interface. Signed-off-by: Thomas Jungblut <[email protected]> Signed-off-by: samuelbartels20 <[email protected]>
No description provided.