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

Automatically compact DB #435

Merged
merged 3 commits into from
Mar 13, 2023

Conversation

uprendis
Copy link
Contributor

@uprendis uprendis commented Mar 7, 2023

  • automatically compact DB during genesis processing, legacy migration and DB transformation in order to avoid compaction-related performance issues during data insertion

Fix #433

@uprendis uprendis requested review from hadv, thaarok, jmpike and rus-alex March 7, 2023 12:56
@uprendis uprendis requested a review from andrecronje as a code owner March 7, 2023 12:56
@@ -264,7 +264,7 @@ func transformComponent(datadir string, dbTypes, tmpDbTypes map[multidb.TypeName
return err
}
toMove[dbLocatorOf(e.New)] = true
newDB = batched.Wrap(newDB)
newDB = batched.Wrap(autocompact.Wrap(autocompact.Wrap(newDB, 1*opt.GiB), 16*opt.GiB))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why we always need to double wrap with difference limit like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So that we it would automatically compact every 1 GB of added AND every 16 GB of inserted data

}

func (s *Batch) Put(key []byte, value []byte) error {
s.written += uint64(len(key) + len(value) + 64)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain, please, why you add up 64 here?

Copy link
Contributor Author

@uprendis uprendis Mar 8, 2023

Choose a reason for hiding this comment

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

Storage overheads, related to adding/deleting a record, wouldn't be only proportional to length of key and value. E.g. if one adds 10 records with length of 2, it will be more expensive than 1 record with length 20
Now, 64 wasn't really calculated but is rather a guesstimation

@uprendis
Copy link
Contributor Author

uprendis commented Mar 8, 2023

Added constraints for autocompact in order to prevent an accidental misuse. Now, it only allows monotonic datasets (or series of monotonic datasets). In a case if input keys aren't monotonic, it prints a warning and disables auto-compaction for the DB instance

@uprendis uprendis force-pushed the feature/autocompact branch from 2c68189 to c2cc618 Compare March 9, 2023 18:30
@cyberbono3
Copy link
Contributor

Added constraints for autocompact in order to prevent an accidental misuse. Now, it only allows monotonic datasets (or series of monotonic datasets). In a case if input keys aren't monotonic, it prints a warning and disables auto-compaction for the DB instance

It would be great to add some test coverage as some complexity has been introduced

@uprendis uprendis merged commit cf51fea into Fantom-foundation:develop Mar 13, 2023
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.

3 participants