Browse Source

migrate: convert 0.4 terms to start at 1

Barak Michener 11 years ago
parent
commit
7f91a35313
3 changed files with 4 additions and 2 deletions
  1. 2 0
      migrate/etcd4.go
  2. 1 1
      migrate/log.go
  3. 1 1
      migrate/snapshot.go

+ 2 - 0
migrate/etcd4.go

@@ -29,6 +29,8 @@ import (
 	"github.com/coreos/etcd/wal/walpb"
 )
 
+const termOffset4to2 = 1
+
 func snapDir4(dataDir string) string {
 	return path.Join(dataDir, "snapshot")
 }

+ 1 - 1
migrate/log.go

@@ -498,7 +498,7 @@ func toEntry2(ent4 *etcd4pb.LogEntry, raftMap map[string]uint64) (*raftpb.Entry,
 	}
 
 	ent2 := raftpb.Entry{
-		Term:  ent4.GetTerm(),
+		Term:  ent4.GetTerm() + termOffset4to2,
 		Index: ent4.GetIndex(),
 		Type:  cmd4.Type2(),
 		Data:  data,

+ 1 - 1
migrate/snapshot.go

@@ -195,7 +195,7 @@ func (s *Snapshot4) Snapshot2() *raftpb.Snapshot {
 		Data: newState,
 		Metadata: raftpb.SnapshotMetadata{
 			Index: s.LastIndex,
-			Term:  s.LastTerm,
+			Term:  s.LastTerm + termOffset4to2,
 			ConfState: raftpb.ConfState{
 				Nodes: nodeList,
 			},