Refactor: add and use db.NamespacedKV
This commit is contained in:
@@ -50,9 +50,11 @@ func clock(v int64) int64 {
|
||||
}
|
||||
|
||||
const (
|
||||
keyTypeDevice = iota
|
||||
keyTypeGlobal
|
||||
keyTypeBlock
|
||||
KeyTypeDevice = iota
|
||||
KeyTypeGlobal
|
||||
KeyTypeBlock
|
||||
KeyTypeDeviceStatistic
|
||||
KeyTypeFolderStatistic
|
||||
)
|
||||
|
||||
type fileVersion struct {
|
||||
@@ -112,7 +114,7 @@ const batchFlushSize = 64
|
||||
// name (variable size)
|
||||
func deviceKey(folder, device, file []byte) []byte {
|
||||
k := make([]byte, 1+64+32+len(file))
|
||||
k[0] = keyTypeDevice
|
||||
k[0] = KeyTypeDevice
|
||||
if len(folder) > 64 {
|
||||
panic("folder name too long")
|
||||
}
|
||||
@@ -145,7 +147,7 @@ func deviceKeyDevice(key []byte) []byte {
|
||||
// name (variable size)
|
||||
func globalKey(folder, file []byte) []byte {
|
||||
k := make([]byte, 1+64+len(file))
|
||||
k[0] = keyTypeGlobal
|
||||
k[0] = KeyTypeGlobal
|
||||
if len(folder) > 64 {
|
||||
panic("folder name too long")
|
||||
}
|
||||
@@ -915,7 +917,7 @@ func ldbListFolders(db *leveldb.DB) []string {
|
||||
snap.Release()
|
||||
}()
|
||||
|
||||
dbi := snap.NewIterator(util.BytesPrefix([]byte{keyTypeGlobal}), nil)
|
||||
dbi := snap.NewIterator(util.BytesPrefix([]byte{KeyTypeGlobal}), nil)
|
||||
defer dbi.Release()
|
||||
|
||||
folderExists := make(map[string]bool)
|
||||
@@ -953,7 +955,7 @@ func ldbDropFolder(db *leveldb.DB, folder []byte) {
|
||||
}()
|
||||
|
||||
// Remove all items related to the given folder from the device->file bucket
|
||||
dbi := snap.NewIterator(util.BytesPrefix([]byte{keyTypeDevice}), nil)
|
||||
dbi := snap.NewIterator(util.BytesPrefix([]byte{KeyTypeDevice}), nil)
|
||||
for dbi.Next() {
|
||||
itemFolder := deviceKeyFolder(dbi.Key())
|
||||
if bytes.Compare(folder, itemFolder) == 0 {
|
||||
@@ -963,7 +965,7 @@ func ldbDropFolder(db *leveldb.DB, folder []byte) {
|
||||
dbi.Release()
|
||||
|
||||
// Remove all items related to the given folder from the global bucket
|
||||
dbi = snap.NewIterator(util.BytesPrefix([]byte{keyTypeGlobal}), nil)
|
||||
dbi = snap.NewIterator(util.BytesPrefix([]byte{KeyTypeGlobal}), nil)
|
||||
for dbi.Next() {
|
||||
itemFolder := globalKeyFolder(dbi.Key())
|
||||
if bytes.Compare(folder, itemFolder) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user