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

No need to handle freelist as a specical case when freeing a page #788

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

ahrtr
Copy link
Member

@ahrtr ahrtr commented Jul 8, 2024

Read #67 (comment)

When the page ID to be freed isn't included in f.allocs, then it means it must be allocated before opening the db this time, and the write transaction is the very first write TXN after opening the db. So it (the page ID to be freed) must be visible to all readonly transactions. We just need to use the default value 0 for such case, in the same way as we did for other page types.

Will rebase this PR once #775 gets merged.

The existing test cases already cover the sanity test. We will add more dedicated test cases for freelist management later.

cc @tjungblu @fuweid @ivanvc

Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
Copy link
Member

@ivanvc ivanvc left a comment

Choose a reason for hiding this comment

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

LGTM. However, I'd suggest having @tjungblu review this PR, too :), as I'm not an expert on freelist.

@@ -67,9 +67,6 @@ func (t *shared) Free(txid common.Txid, p *common.Page) {
allocTxid, ok := t.allocs[p.Id()]
if ok {
delete(t.allocs, p.Id())
} else if p.IsFreelistPage() {
// Freelist is always allocated by prior tx.
allocTxid = txid - 1
Copy link
Member

@fuweid fuweid Jul 18, 2024

Choose a reason for hiding this comment

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

The Line 79 txp.alloctx = append(txp.alloctx, allocTxid) could append zero into alloctx.

There are two cases we should consider:

Rollback

The zero value will be covered by the rollback. So it looks fine.

tx := txp.alloctx[i]
if tx == 0 {
continue
}

Release by opening new writable TX

This change looks safe to me because the page will be free after all the read-only TX are closed.
I think the original Freelist is always allocated by prior tx. might free the page which can be read by opening read-only TX.

for i := 0; i < len(txp.ids); i++ {
if atx := txp.alloctx[i]; atx < begin || atx > end {
continue
}
m = append(m, txp.ids[i])

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

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahrtr, fuweid, ivanvc

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tjungblu
Copy link
Contributor

/lgtm

Thanks @ahrtr - I'll adjust the testcases accordingly.

@ahrtr ahrtr merged commit d72e6bf into etcd-io:main Jul 22, 2024
18 checks passed
@ahrtr ahrtr deleted the simply_free_20240708 branch July 22, 2024 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

5 participants