-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
There was a problem hiding this 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.
ldbs[0] = &levelDB{maindb} | ||
ldbs[1] = &levelDB{lookup} | ||
ldbs[1] = nil |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]
}
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
Description
Removed 2nd leveldb instance. Now all data goes into 1 database, as it was earlier.
Changes include
Breaking changes
Please complete this section if any breaking changes have been made, otherwise delete it
Checklist
Testing
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