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

core/rawdb/freezer: subtract size of hidden items from AncientSize() #27950

Closed
wants to merge 5 commits into from

Conversation

karloku
Copy link

@karloku karloku commented Aug 18, 2023

This PR changes how Freezer.AncientSize() reports the total data size, as the issue addressed in #27483 .

It introduces two changes:

  1. A new function freezerTable.sizeHidden() return the total data size of the hidden items by summing up the sizes from the hidden indexEntrys (indices from itemOffset to itemHidden).
  2. The return value of Freezer.AncientSize() is now size - sizeHidden to get the actual size of the live items.

…zerTable

core/rawdb/freezer: sizeHidden should be subtracted from Freezer.AncientSize
Comment on lines 861 to 866
return t.sizeHiddenNoLock()
}

// sizeHiddenNoLock returns the total data size of hidden items in the freezer table
// without obtaining the mutex first.
func (t *freezerTable) sizeHiddenNoLock() (uint64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return t.sizeHiddenNoLock()
}
// sizeHiddenNoLock returns the total data size of hidden items in the freezer table
// without obtaining the mutex first.
func (t *freezerTable) sizeHiddenNoLock() (uint64, error) {

Haven't looked at the correctness of the implementation yet, but this stood out to me. Why even have the NoLock method when we're not using it - it just makes the api surface more complicated IMO.

Copy link
Author

Choose a reason for hiding this comment

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

I saw the sizeNoLock function and thought there was the design to leave the NoLock version. Yes, it was not necessary in this change. I would remove it later.

@fjl
Copy link
Contributor

fjl commented Aug 18, 2023

Note, a similar change was already submitted in #27700

return 0, nil
}

indices, err := t.getIndices(offsetItems, hiddenItems-offsetItems)
Copy link
Member

Choose a reason for hiding this comment

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

You don't really need to resolve all the hidden items and calculate the total hidden data size.
Instead, you can just retrieve the offset corresponds to the first non-hidden item, and the
offset is actually the hidden data size.

// sizeHidden returns the total data size of hidden items in the freezer table.
func (t *freezerTable) sizeHidden() (uint64, error) {
	t.lock.RLock()
	defer t.lock.RUnlock()

	hidden, offset := t.itemHidden.Load(), t.itemOffset.Load()
	if hidden <= offset {
		return 0, nil
	}
	indices, err := t.getIndices(hidden, 1)
	if err != nil {
		return 0, err
	}
	return uint64(indices[0].offset), nil
}

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the advice! I will try this method.

It seems my test cases failed on Windows environments in AppVeyor builds. The files were not dropped when there were only hidden items after truncation. Is it by design or a bug? It might fail this method.

Copy link
Author

@karloku karloku Aug 21, 2023

Choose a reason for hiding this comment

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

Thank you for the advice! I will try this method.

It seems my test cases failed on Windows environments in AppVeyor builds. The files were not dropped when there were only hidden items after truncation. Is it by design or a bug? It might fail this method.

The truncateTail call itself failed in the first place with rename C:\Users\appveyor\AppData\Local\Temp\1\336933468 C:\Users\appveyor\AppData\Local\Temp\1\truncate-tail-12670623878883326278.ridx: Access is denied. https://ci.appveyor.com/project/karloku/go-ethereum/builds/47842081/job/tlckukoxk9mi3j7a#L969

I will try to fix it.

@@ -662,87 +662,92 @@ func TestTruncateTail(t *testing.T) {
t.Parallel()
rm, wm, sg := metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge()
fname := fmt.Sprintf("truncate-tail-%d", rand.Uint64())
var maxFileSize uint32 = 50
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for changing the file size? I don't think it should be changed just for adding a new non-hidden-size check?

Copy link
Author

Choose a reason for hiding this comment

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

No, it is just for checking the hidden size. I would change the data sizes instead.

@rjl493456442 rjl493456442 self-assigned this Aug 28, 2023
@rjl493456442
Copy link
Member

Closed it because #28525

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants