Skip to content

Commit

Permalink
Modify to clear db correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Jul 2, 2021
1 parent b4bc163 commit ba239b1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
13 changes: 12 additions & 1 deletion interface/store/arbiters.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,22 @@ func (c *arbiters) Clear() error {
c.Lock()
defer c.Unlock()
it := c.db.NewIterator(dbutil.BytesPrefix(BKTArbiters), nil)
defer it.Release()
for it.Next() {
c.b.Delete(it.Key())
}
it.Release()
c.b.Delete(BKTArbPosition)
c.b.Delete(BKTArbPositions)
it = c.db.NewIterator(dbutil.BytesPrefix(BKTArbitersData), nil)
for it.Next() {
c.b.Delete(it.Key())
}
it.Release()
it = c.db.NewIterator(dbutil.BytesPrefix(BKTTransactionHeight), nil)
for it.Next() {
c.b.Delete(it.Key())
}
it.Release()
return c.db.Write(c.b, nil)
}

Expand Down
13 changes: 10 additions & 3 deletions interface/store/customid.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,22 +556,29 @@ func (c *customID) Clear() error {

batch := new(leveldb.Batch)
it := c.db.NewIterator(util.BytesPrefix(BKTReservedCustomID), nil)
defer it.Release()
for it.Next() {
batch.Delete(it.Key())
}
it.Release()

it = c.db.NewIterator(util.BytesPrefix(BKTReceivedCustomID), nil)
defer it.Release()
for it.Next() {
batch.Delete(it.Key())
}
it.Release()

it = c.db.NewIterator(util.BytesPrefix(BKTChangeCustomIDFee), nil)
defer it.Release()
for it.Next() {
batch.Delete(it.Key())
}
it.Release()

it = c.db.NewIterator(util.BytesPrefix(BKTLastCustomIDFee), nil)
for it.Next() {
batch.Delete(it.Key())
}
it.Release()

return c.db.Write(c.b, nil)
}

Expand Down
22 changes: 19 additions & 3 deletions interface/store/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"bytes"
"errors"
"github.com/elastos/Elastos.ELA/core/types/payload"
dbutil "github.com/syndtr/goleveldb/leveldb/util"
"sync"

"github.com/elastos/Elastos.ELA/common"

"github.com/syndtr/goleveldb/leveldb"
)

// Ensure arbiters implement arbiters interface.
// Ensure upgrade implement Upgrade interface.
var _ Upgrade = (*upgrade)(nil)

type upgrade struct {
Expand All @@ -23,7 +24,22 @@ type upgrade struct {
}

func (u *upgrade) Clear() error {
panic("implement me")
u.Lock()
defer u.Unlock()
it := u.db.NewIterator(dbutil.BytesPrefix(BKTUpgradeControversial), nil)
for it.Next() {
u.b.Delete(it.Key())
}
it.Release()
it = u.db.NewIterator(dbutil.BytesPrefix(BKTUpgradeCode), nil)
for it.Next() {
u.b.Delete(it.Key())
}
it.Release()

u.b.Delete(BKTUpgradePositions)

return u.db.Write(u.b, nil)
}

func (u *upgrade) Close() error {
Expand Down Expand Up @@ -80,7 +96,7 @@ func (u *upgrade) batchPutUpgradeResult(proposalHash common.Uint256, batch *leve
}
newPosCache = append(newPosCache, info.WorkingHeight)
u.posCache = newPosCache
batch.Put(BKTArbPositions, uint32ArrayToBytes(u.posCache))
batch.Put(BKTUpgradePositions, uint32ArrayToBytes(u.posCache))

index := getIndex(info.WorkingHeight)
batch.Put(toKey(BKTUpgradeCode, index...), data)
Expand Down

0 comments on commit ba239b1

Please sign in to comment.