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

2nd leveldb database instance removal #168

Merged
merged 2 commits into from
Mar 27, 2024

Conversation

oliverbundalo
Copy link

Description

Removed 2nd leveldb instance. Now all data goes into 1 database, as it was earlier.

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)

Breaking changes

Please complete this section if any breaking changes have been made, otherwise delete it

Checklist

  • I have assigned this PR to myself
  • I have added at least 1 reviewer
  • I have added the relevant labels
  • I have updated the official documentation
  • I have added sufficient documentation in code

Testing

  • I have tested this code with the official test suite
  • I have tested this code manually

Manual tests

Please complete this section if you ran manual tests for this functionality, otherwise delete it

Documentation update

Please link the documentation update PR in this section if it's present, otherwise delete it

Additional comments

Please post additional comments in this section if you have them, otherwise delete it

@oliverbundalo oliverbundalo added the feature New feature label Mar 27, 2024
@oliverbundalo oliverbundalo self-assigned this Mar 27, 2024
Copy link

@Stefan-Ethernal Stefan-Ethernal left a comment

Choose a reason for hiding this comment

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

LGTM, aside from the nitpicks.

blockchain/storagev2/leveldb/leveldb.go Show resolved Hide resolved
blockchain/storagev2/leveldb/leveldb.go Show resolved Hide resolved
ldbs[0] = &levelDB{maindb}
ldbs[1] = &levelDB{lookup}
ldbs[1] = nil

Choose a reason for hiding this comment

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

Will this cause us some issues? IMO it would be better if we would follow a null object pattern and therefore create the NoOpDatabase implementation, that would implement the following interface:

type Database interface {
	Close() error
	Get(t uint8, k []byte) ([]byte, bool, error)
	NewBatch() Batch
}

...and eliminate the nil checks in the storagev2/storage.go. WDYT?

Copy link
Author

Choose a reason for hiding this comment

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

I need some indication do we have 2 instances or one. If we have only one, then we should always default to index 0 for all read/write operations. So if the 2nd element of array is nil then we know we should pickup db instance with index 0. With this dummy interface implementation we can't accomplish that

Method doing database mapping:
func (s *Storage) getDB(t uint8) Database {
i := getIndex(t)
if s.db[i] != nil {
return s.db[i]
}

return s.db[MAINDB_INDEX]

}

Copy link

@Stefan-Ethernal Stefan-Ethernal Mar 27, 2024

Choose a reason for hiding this comment

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

But again, instead of checking if it is nil, you can check whether the concrete type is the NoOpDatabase.

But in the other places, it would be safe to invoke the function against the instance (and remove the nil checks), because it would not be nil.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe, but that way we will not know if we are calling a bad instance or a good one. In my opinion it is better to crash then to call interface doing nothing. But anyway it will never happen to call a nil instance because all calls must go through this getDB mapper first.

@oliverbundalo oliverbundalo merged commit 111586d into develop Mar 27, 2024
10 checks passed
@oliverbundalo oliverbundalo deleted the remove-multiple-leveldb-instances branch March 27, 2024 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants