-
Notifications
You must be signed in to change notification settings - Fork 328
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
[db] fix Size() and refactor counting index interface #4490
base: master
Are you sure you want to change the base?
Conversation
2673dd6
to
7642dea
Compare
db/counting_index.go
Outdated
@@ -31,8 +31,14 @@ type ( | |||
CountingIndex interface { | |||
// Size returns the total number of keys so far | |||
Size() uint64 | |||
// Add inserts a value into the index | |||
Add([]byte, bool) error | |||
// AddOne inserts one entry into the 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.
suggest following interface, it seems more clear:
CountingIndex interface{
Size() uint64
Add([]byte, bool) error
Get(uint64) ([]byte, error)
Range(uint64, uint64) ([][]byte, error)
Revert(uint64) error
Close()
// batch support
BatchAdd(batch, []byte) error
Commit(batch) error
}
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.
counting index maintains the logic without any in memory storage. The only dependency countKey
has a copy in kvstore and a copy in the batch we are going to write. If everything is processed in batch, why the readiness
, aka lock
is needed?
db/counting_index.go
Outdated
if inBatch { | ||
return c.addBatch(value) | ||
func (c *countingIndex) AddOne(value []byte) error { | ||
if err := c.TurnOn(); err != 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.
the definition of TurnOn
is the service is ready, which doesn't match the usage here.
db/counting_index.go
Outdated
AddOne([]byte) error | ||
// AddMultiple inserts multiple entries into the index | ||
AddMultiple([][]byte) error | ||
// AddToExternalBatch inserts entries into external batch | ||
AddToExternalBatch(batch.KVStoreBatch, [][]byte) error |
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.
do we really need to distinguish internal and external?
7642dea
to
ab54fc2
Compare
ab54fc2
to
cd0afa7
Compare
Quality Gate passedIssues Measures |
}, nil | ||
} | ||
|
||
// Size returns the total number of keys so far | ||
func (c *countingIndex) Size() uint64 { | ||
return atomic.LoadUint64(&c.size) | ||
c.lock.RLock() |
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.
didn't see the benefits of the changes
} | ||
|
||
func (c *countingIndex) BeginBatch(b batch.KVStoreBatch) { | ||
c.lock.Lock() |
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.
why lock at begin instead of end?
// AddToBatch inserts an entry into external batch | ||
AddToBatch(batch.KVStoreBatch, []byte) | ||
// BeginBatch should be called before writing the batch | ||
BeginBatch(batch.KVStoreBatch) |
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 can put PreCommit
and PostCommit
into batch intead
Description
improve the counting index interface.
Fixes #4489
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: