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

Move method freePages into freelist.go #783

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

ahrtr
Copy link
Member

@ahrtr ahrtr commented Jul 1, 2024

The motivation is to get all freelist related logic included in freelist.go. We are going to introduce freelist interface in the next step.

The freePages is the most important logic of freelist management, but it's outside of freelist management. Moving it into freelist.go is the base for introducing freelist interface and introduce more dedicated test cases.

cc @tjungblu @fuweid @ivanvc

@ahrtr
Copy link
Member Author

ahrtr commented Jul 1, 2024

Link to #773

@ahrtr ahrtr force-pushed the refactor_freelist_20240701 branch from f219a03 to f2b2bba Compare July 1, 2024 14:35
@@ -24,6 +24,7 @@ type pidSet map[common.Pgid]struct{}
type freelist struct {
freelistType FreelistType // freelist type
ids []common.Pgid // all free and available free page ids.
readonlyTXIDs []common.Txid // all readonly transaction IDs.
Copy link
Contributor

Choose a reason for hiding this comment

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

do we really need this? this seems tracked in the pending map already

Copy link
Contributor

Choose a reason for hiding this comment

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

okay now I get it, this is a subset of the transactions in the pending map. I think we need to refactor a dedicated transaction tracker

Copy link
Member Author

Choose a reason for hiding this comment

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

The TXIDs included in pending are actually writing TXIDs.

freelist is one of the most sensitive & important parts of bbolt, let's do it step by step. We need to ensure each step is well understood.

last := len(f.readonlyTXIDs) - 1
f.readonlyTXIDs[i] = f.readonlyTXIDs[last]
f.readonlyTXIDs = f.readonlyTXIDs[:last]
break
Copy link
Contributor

@tjungblu tjungblu Jul 2, 2024

Choose a reason for hiding this comment

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

there's slices.Delete() which we can use. I'm wondering if it's better to have a map here too, so we can also panic on duplicated transactions. This removal would just delete the first occurrence.

Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if it's better to have a map here too

It's trade-off. The freePages needs to sort before use. If I understand it correctly, freePages needs to allocate memory for sort.

Copy link
Member Author

Choose a reason for hiding this comment

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

there's slices.Delete() which we can use.

slices.Delete is O(len(s)-i) and it copes/moves all elements after the removed element, while our implementation is O(1).

I'm wondering if it's better to have a map here too, so we can also panic on duplicated transactions.

No, we can't. Multiple readonly TXNs may have the same txid, and it's expected.

freelist.go Outdated Show resolved Hide resolved
Copy link
Member

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

last := len(f.readonlyTXIDs) - 1
f.readonlyTXIDs[i] = f.readonlyTXIDs[last]
f.readonlyTXIDs = f.readonlyTXIDs[:last]
break
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if it's better to have a map here too

It's trade-off. The freePages needs to sort before use. If I understand it correctly, freePages needs to allocate memory for sort.

The motivation is to get all freelist related logic included
in freelist.go. We are going to introduce freelist interface
in the next step.

Signed-off-by: Benjamin Wang <[email protected]>
@ahrtr ahrtr force-pushed the refactor_freelist_20240701 branch from f2b2bba to 263e75d Compare July 2, 2024 09:04
Copy link
Contributor

@tjungblu tjungblu left a comment

Choose a reason for hiding this comment

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

/lgtm

thanks for the clarification!

@ahrtr ahrtr merged commit d537eff into etcd-io:main Jul 2, 2024
17 checks passed
@ahrtr ahrtr deleted the refactor_freelist_20240701 branch July 2, 2024 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants