在tinykv 2a 接收appendmessage时,发现测试用例TestOldMessages2AB
里的newMemoryStorageWithEnts
在比较的时候没有数据,我自己向raftlog的 entries 里面追加日志导致两个结果不一致,这个意思是我的数据不能够直接向entries 里append吗?
ilog := newLog(
newMemoryStorageWithEnts([]pb.Entry{
{}, {Data: nil, Term: 1, Index: 1},
{Data: nil, Term: 2, Index: 2}, {Data: nil, Term: 3, Index: 3},
{Data: []byte("somedata"), Term: 3, Index: 4},
}))
ilog.committed = 4
base := ltoa(ilog)
for i, p := range tt.peers {
if sm, ok := p.(*Raft); ok {
l := ltoa(sm.RaftLog)
if g := diffu(base, l); g != "" {
t.Errorf("#%d: diff:\
%s", i, g)
}
} else {
t.Logf("#%d: empty log", i)
}
}
这个是比较的结果:
raft_test.go:516: #1: diff:
--- /tmp/base208016859 2022-01-09 20:43:37.193077688 +0800
+++ /tmp/other3085804305 2022-01-09 20:43:37.194077712 +0800
@@ -1,2 +1,6 @@
committed: 4
applied: 0
+#0: {EntryType:EntryNormal Term:1 Index:1 Data:[] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}
+#1: {EntryType:EntryNormal Term:2 Index:2 Data:[] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}
+#2: {EntryType:EntryNormal Term:3 Index:3 Data:[] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}
+#3: {EntryType:EntryNormal Term:3 Index:4 Data:[115 111 109 101 100 97 116 97] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}
raft_test.go:516: #2: diff:
--- /tmp/base1566267759 2022-01-09 20:43:37.196077759 +0800
+++ /tmp/other2235237263 2022-01-09 20:43:37.217078260 +0800
@@ -1,2 +1,6 @@
committed: 4
applied: 0
+#0: {EntryType:EntryNormal Term:1 Index:1 Data:[] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}
+#1: {EntryType:EntryNormal Term:2 Index:2 Data:[] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}
+#2: {EntryType:EntryNormal Term:3 Index:3 Data:[] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}
+#3: {EntryType:EntryNormal Term:3 Index:4 Data:[115 111 109 101 100 97 116 97] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}
raft_test.go:516: #3: diff:
--- /tmp/base765527407 2022-01-09 20:43:37.220078332 +0800
+++ /tmp/other2759677515 2022-01-09 20:43:37.226078475 +0800
@@ -1,2 +1,6 @@
committed: 4
applied: 0
+#0: {EntryType:EntryNormal Term:1 Index:1 Data:[] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}
+#1: {EntryType:EntryNormal Term:2 Index:2 Data:[] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}
+#2: {EntryType:EntryNormal Term:3 Index:3 Data:[] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}
+#3: {EntryType:EntryNormal Term:3 Index:4 Data:[115 111 109 101 100 97 116 97] XXX_NoUnkeyedLiteral:{} XXX_unrecognized:[] XXX_sizecache:0}