channeldb: move .SyncVersions() into .Open(), minor migration cleanups
This commit unexports the SyncVerions PR, in favor of making it private and moving it into the .Open() method. With this change, callers no longer need worry about ensuring the database version is up to sync before usage, as it will happen automatically once the database is opened. This commit also unexports some additional variables within the package that don’t need be consumed by the public, and exports the DbVersionNumber attribute on the meta struct. Finally some minor formatting fixes have neen carried out to ensure the new code more closely matches the style of the rest of the codebase.
This commit is contained in:
4 files changed
+71
-65
No files matched your search
+6
-5
@@ -9,14 +9,15 @@ var (
|
||||
// the database.
|
||||
metaBucket = []byte("metadata")
|
||||
|
||||
// dbVersionKey is a boltdb key and it's used for storing/retrieveing
|
||||
// dbVersionKey is a boltdb key and it's used for storing/retrieving
|
||||
// current database version.
|
||||
dbVersionKey = []byte("dbp")
|
||||
)
|
||||
|
||||
// Meta structure holds the database meta information.
|
||||
type Meta struct {
|
||||
dbVersionNumber uint32
|
||||
// DbVersionNumber is the current schema version of the database.
|
||||
DbVersionNumber uint32
|
||||
}
|
||||
|
||||
// FetchMeta fetches the meta data from boltdb and returns filled meta
|
||||
@@ -74,7 +75,7 @@ func (d *DB) PutMeta(meta *Meta, tx *bolt.Tx) error {
|
||||
|
||||
func putDbVersion(metaBucket *bolt.Bucket, meta *Meta) error {
|
||||
scratch := make([]byte, 4)
|
||||
byteOrder.PutUint32(scratch, meta.dbVersionNumber)
|
||||
byteOrder.PutUint32(scratch, meta.DbVersionNumber)
|
||||
if err := metaBucket.Put(dbVersionKey, scratch); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -83,8 +84,8 @@ func putDbVersion(metaBucket *bolt.Bucket, meta *Meta) error {
|
||||
|
||||
func fetchDbVersion(metaBucket *bolt.Bucket, meta *Meta) {
|
||||
if data := metaBucket.Get(dbVersionKey); data != nil {
|
||||
meta.dbVersionNumber = byteOrder.Uint32(data)
|
||||
meta.DbVersionNumber = byteOrder.Uint32(data)
|
||||
} else {
|
||||
meta.dbVersionNumber = getLatestDBVersion(DBVersions)
|
||||
meta.DbVersionNumber = getLatestDBVersion(dbVersions)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user