Browse Source

storage: put storage info keys into information bucket

They used to be in key bucket, and make recover failed because they
cannot be parsed as normal key.
Yicheng Qin 10 years ago
parent
commit
7b1a93e1ef
2 changed files with 9 additions and 7 deletions
  1. 8 6
      storage/kvstore.go
  2. 1 1
      storage/kvstore_compaction.go

+ 8 - 6
storage/kvstore.go

@@ -14,9 +14,10 @@ import (
 )
 )
 
 
 var (
 var (
-	batchLimit    = 10000
-	batchInterval = 100 * time.Millisecond
-	keyBucketName = []byte("key")
+	batchLimit     = 10000
+	batchInterval  = 100 * time.Millisecond
+	keyBucketName  = []byte("key")
+	metaBucketName = []byte("meta")
 
 
 	scheduledCompactKeyName = []byte("scheduledCompactRev")
 	scheduledCompactKeyName = []byte("scheduledCompactRev")
 	finishedCompactKeyName  = []byte("finishedCompactRev")
 	finishedCompactKeyName  = []byte("finishedCompactRev")
@@ -50,6 +51,7 @@ func newStore(path string) *store {
 	tx := s.b.BatchTx()
 	tx := s.b.BatchTx()
 	tx.Lock()
 	tx.Lock()
 	tx.UnsafeCreateBucket(keyBucketName)
 	tx.UnsafeCreateBucket(keyBucketName)
+	tx.UnsafeCreateBucket(metaBucketName)
 	tx.Unlock()
 	tx.Unlock()
 	s.b.ForceCommit()
 	s.b.ForceCommit()
 
 
@@ -153,7 +155,7 @@ func (s *store) Compact(rev int64) error {
 
 
 	tx := s.b.BatchTx()
 	tx := s.b.BatchTx()
 	tx.Lock()
 	tx.Lock()
-	tx.UnsafePut(keyBucketName, scheduledCompactKeyName, rbytes)
+	tx.UnsafePut(metaBucketName, scheduledCompactKeyName, rbytes)
 	tx.Unlock()
 	tx.Unlock()
 
 
 	keep := s.kvindex.Compact(rev)
 	keep := s.kvindex.Compact(rev)
@@ -178,7 +180,7 @@ func (s *store) Restore() error {
 	// restore index
 	// restore index
 	tx := s.b.BatchTx()
 	tx := s.b.BatchTx()
 	tx.Lock()
 	tx.Lock()
-	_, finishedCompactBytes := tx.UnsafeRange(keyBucketName, finishedCompactKeyName, nil, 0)
+	_, finishedCompactBytes := tx.UnsafeRange(metaBucketName, finishedCompactKeyName, nil, 0)
 	if len(finishedCompactBytes) != 0 {
 	if len(finishedCompactBytes) != 0 {
 		s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main
 		s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main
 		log.Printf("storage: restore compact to %d", s.compactMainRev)
 		log.Printf("storage: restore compact to %d", s.compactMainRev)
@@ -208,7 +210,7 @@ func (s *store) Restore() error {
 		s.currentRev = rev
 		s.currentRev = rev
 	}
 	}
 
 
-	_, scheduledCompactBytes := tx.UnsafeRange(keyBucketName, scheduledCompactKeyName, nil, 0)
+	_, scheduledCompactBytes := tx.UnsafeRange(metaBucketName, scheduledCompactKeyName, nil, 0)
 	if len(scheduledCompactBytes) != 0 {
 	if len(scheduledCompactBytes) != 0 {
 		scheduledCompact := bytesToRev(finishedCompactBytes[0]).main
 		scheduledCompact := bytesToRev(finishedCompactBytes[0]).main
 		if scheduledCompact > s.compactMainRev {
 		if scheduledCompact > s.compactMainRev {

+ 1 - 1
storage/kvstore_compaction.go

@@ -28,7 +28,7 @@ func (s *store) scheduleCompaction(compactMainRev int64, keep map[reversion]stru
 		if len(keys) == 0 {
 		if len(keys) == 0 {
 			rbytes := make([]byte, 8+1+8)
 			rbytes := make([]byte, 8+1+8)
 			revToBytes(reversion{main: compactMainRev}, rbytes)
 			revToBytes(reversion{main: compactMainRev}, rbytes)
-			tx.UnsafePut(keyBucketName, finishedCompactKeyName, rbytes)
+			tx.UnsafePut(metaBucketName, finishedCompactKeyName, rbytes)
 			tx.Unlock()
 			tx.Unlock()
 			return
 			return
 		}
 		}