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 f4f15f9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.13

require (
github.com/cevaris/ordered_map v0.0.0-20190319150403-3adeae072e73
github.com/elastos/Elastos.ELA v0.7.0
github.com/elastos/Elastos.ELA v0.6.1-0.20210630074712-c34eacefbc5a
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/stretchr/testify v1.4.0
Expand Down
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 f4f15f9

Please sign in to comment.