channeldb: consolidate top-level bucket create/wipe
This commit is contained in:
parent
d343575104
commit
24cce7a6ec
@ -242,48 +242,31 @@ func (d *DB) Path() string {
|
|||||||
return d.dbPath
|
return d.dbPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var topLevelBuckets = [][]byte{
|
||||||
|
openChannelBucket,
|
||||||
|
closedChannelBucket,
|
||||||
|
forwardingLogBucket,
|
||||||
|
fwdPackagesKey,
|
||||||
|
invoiceBucket,
|
||||||
|
nodeInfoBucket,
|
||||||
|
nodeBucket,
|
||||||
|
edgeBucket,
|
||||||
|
edgeIndexBucket,
|
||||||
|
graphMetaBucket,
|
||||||
|
metaBucket,
|
||||||
|
}
|
||||||
|
|
||||||
// Wipe completely deletes all saved state within all used buckets within the
|
// Wipe completely deletes all saved state within all used buckets within the
|
||||||
// database. The deletion is done in a single transaction, therefore this
|
// database. The deletion is done in a single transaction, therefore this
|
||||||
// operation is fully atomic.
|
// operation is fully atomic.
|
||||||
func (d *DB) Wipe() error {
|
func (d *DB) Wipe() error {
|
||||||
return kvdb.Update(d, func(tx kvdb.RwTx) error {
|
return kvdb.Update(d, func(tx kvdb.RwTx) error {
|
||||||
err := tx.DeleteTopLevelBucket(openChannelBucket)
|
for _, tlb := range topLevelBuckets {
|
||||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
err := tx.DeleteTopLevelBucket(tlb)
|
||||||
return err
|
if err != nil && err != kvdb.ErrBucketNotFound {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tx.DeleteTopLevelBucket(closedChannelBucket)
|
|
||||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = tx.DeleteTopLevelBucket(invoiceBucket)
|
|
||||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = tx.DeleteTopLevelBucket(nodeInfoBucket)
|
|
||||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = tx.DeleteTopLevelBucket(nodeBucket)
|
|
||||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = tx.DeleteTopLevelBucket(edgeBucket)
|
|
||||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = tx.DeleteTopLevelBucket(edgeIndexBucket)
|
|
||||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = tx.DeleteTopLevelBucket(graphMetaBucket)
|
|
||||||
if err != nil && err != kvdb.ErrBucketNotFound {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -301,33 +284,13 @@ func initChannelDB(db kvdb.Backend) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := tx.CreateTopLevelBucket(openChannelBucket); err != nil {
|
for _, tlb := range topLevelBuckets {
|
||||||
return err
|
if _, err := tx.CreateTopLevelBucket(tlb); err != nil {
|
||||||
}
|
return err
|
||||||
if _, err := tx.CreateTopLevelBucket(closedChannelBucket); err != nil {
|
}
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := tx.CreateTopLevelBucket(forwardingLogBucket); err != nil {
|
nodes := tx.ReadWriteBucket(nodeBucket)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := tx.CreateTopLevelBucket(fwdPackagesKey); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := tx.CreateTopLevelBucket(invoiceBucket); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := tx.CreateTopLevelBucket(nodeInfoBucket); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
nodes, err := tx.CreateTopLevelBucket(nodeBucket)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = nodes.CreateBucket(aliasIndexBucket)
|
_, err = nodes.CreateBucket(aliasIndexBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -337,10 +300,7 @@ func initChannelDB(db kvdb.Backend) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
edges, err := tx.CreateTopLevelBucket(edgeBucket)
|
edges := tx.ReadWriteBucket(edgeBucket)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := edges.CreateBucket(edgeIndexBucket); err != nil {
|
if _, err := edges.CreateBucket(edgeIndexBucket); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -354,19 +314,12 @@ func initChannelDB(db kvdb.Backend) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
graphMeta, err := tx.CreateTopLevelBucket(graphMetaBucket)
|
graphMeta := tx.ReadWriteBucket(graphMetaBucket)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = graphMeta.CreateBucket(pruneLogBucket)
|
_, err = graphMeta.CreateBucket(pruneLogBucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := tx.CreateTopLevelBucket(metaBucket); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
meta.DbVersionNumber = getLatestDBVersion(dbVersions)
|
meta.DbVersionNumber = getLatestDBVersion(dbVersions)
|
||||||
return putMeta(meta, tx)
|
return putMeta(meta, tx)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user