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

Support non-single DB migration #954

Merged
merged 9 commits into from
May 14, 2021

Conversation

KimKyungup
Copy link
Contributor

@KimKyungup KimKyungup commented May 4, 2021

Proposed changes

This PR implements the non-single DB migration like LocalDB to LocalDB/RemoteDB.
This can migrate a DB to a DB which has different state trie shards like 4 shards to 16 shards.

Minor change

  • Change max shard value from 16 to 256

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

  • Please leave the issue numbers or links related to this PR here.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

storage/database/db_manager.go Outdated Show resolved Hide resolved
// make a report
if fetched%reportCycle == 0 {
if fetched%(IdealBatchSize*20) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you change reportCycle to IdealBatchSize*20?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The log are too much. So I changed it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If so, how about increasing reportCycle as it is not used now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reflected.


srcIter.Release()
if err := srcIter.Error(); err != nil { // any accumulated error from iterator
return errors.Wrap(err, "failed to iterate")
Copy link
Contributor

Choose a reason for hiding this comment

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

errors.Wrap returns an error annotating err with a stack trace.
Do we need stack trace here?

// Wrap returns an error annotating err with a stack trace
// at the point Wrap is called, and the supplied message.
// If err is nil, Wrap returns nil.
func Wrap(err error, message string) error {
	if err == nil {
		return nil
	}
	err = &withMessage{
		cause: err,
		msg:   message,
	}
	return &withStack{
		err,
		callers(),
	}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

The stack trace is returned when +v is used in format. It is not returned in Klaytn log.
errors.Wrap can be replaced with errors.WithMessage which is errors.Wrap without the stack trace.

Copy link
Contributor

Choose a reason for hiding this comment

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

@winnie-byun If we don't print out stack trace in Klaytn, I think there's no need to use errors.Wrap instead of erros.WithMessage. How do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think both ways are fine :)

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 errors.Wrap(err, "failed to iterate")
return errors.withMessage(err, "failed to iterate")

KimKyungup and others added 2 commits May 7, 2021 13:05
Co-authored-by: yumiel yoomee1313 <yumiel.ko@groundx.xyz>
Co-authored-by: jk-jeongkyun <45347815+jeongkyun-oh@users.noreply.github.com>
jeongkyun-oh
jeongkyun-oh previously approved these changes May 10, 2021
ehnuje
ehnuje previously approved these changes May 10, 2021
Copy link
Contributor

@ehnuje ehnuje left a comment

Choose a reason for hiding this comment

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

Just minor comments, other than that, LGTM.

// make a report
if fetched%reportCycle == 0 {
if fetched%(IdealBatchSize*20) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

If so, how about increasing reportCycle as it is not used now?

@@ -52,7 +52,7 @@ type sdbBatchResult struct {
// newShardedDB creates database with numShards shards, or partitions.
// The type of database is specified DBConfig.DBType.
func newShardedDB(dbc *DBConfig, et DBEntryType, numShards uint) (*shardedDB, error) {
const numShardsLimit = 16
const numShardsLimit = 256
Copy link
Contributor

Choose a reason for hiding this comment

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

How about moving this variable outside the function to package level constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reflected.

@KimKyungup KimKyungup dismissed stale reviews from ehnuje and jeongkyun-oh via 84ee1aa May 10, 2021 23:53
joowon-byun
joowon-byun previously approved these changes May 11, 2021
storage/database/db_migration.go Outdated Show resolved Hide resolved
Co-authored-by: Winnie (Joowon) <joowon7508@gmail.com>
@KimKyungup
Copy link
Contributor Author

KimKyungup commented May 13, 2021

@ehnuje @jeongkyun-oh PTAL

@KimKyungup KimKyungup merged commit 224e369 into klaytn:dev May 14, 2021
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.

None yet

5 participants