Expose Reset (#558)

* exposed Reset()

* exposed Reset()

* unimplemented commit

* complete reset

* complete reset

* complete reset

* better reset

* finished Reset

* fixed memory mutation

Co-authored-by: giuliorebuffo <giuliorebuffo@system76-pc.localdomain>
This commit is contained in:
Giulio rebuffo 2022-07-28 22:42:23 +02:00 committed by GitHub
parent fadc9b21d1
commit 5d7fb4ddb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

@ -264,6 +264,7 @@ type RwTx interface {
// CollectMetrics - does collect all DB-related and Tx-related metrics
// this method exists only in RwTx to avoid concurrency
CollectMetrics()
Reset() error
}
// BucketMigrator used for buckets migration, don't use it in usual app code

View File

@ -1046,6 +1046,28 @@ func (tx *MdbxTx) DBSize() (uint64, error) {
return info.Geo.Current, err
}
func (tx *MdbxTx) Reset() (err error) {
tx.Rollback()
//tx.printDebugInfo()
if tx.db.closed.Load() {
return fmt.Errorf("db closed")
}
runtime.LockOSThread()
defer func() {
if err == nil {
tx.db.wg.Add(1)
}
}()
tx.tx, err = tx.db.env.BeginTxn(nil, 0)
if err != nil {
runtime.UnlockOSThread() // unlock only in case of error. normal flow is "defer .Rollback()"
return fmt.Errorf("%w, lable: %s, trace: %s", err, tx.db.opts.label.String(), stack2.Trace().String())
}
tx.tx.RawRead = true
return nil
}
func (tx *MdbxTx) RwCursor(bucket string) (kv.RwCursor, error) {
b := tx.db.buckets[bucket]
if b.AutoDupSortKeysConversion {

View File

@ -374,7 +374,10 @@ func (m *MemoryMutation) Cursor(bucket string) (kv.Cursor, error) {
return m.makeCursor(bucket)
}
// ViewID creates a new cursor (the real fun begins here)
func (m *MemoryMutation) ViewID() uint64 {
panic("ViewID Not implemented")
}
func (m *MemoryMutation) Reset() error {
return nil
}