Skip to content

Commit

Permalink
mvcc/*_test.go: should not use duplicate revision.Main for one key
Browse files Browse the repository at this point in the history
In commit [[1]], the newTestKeyIndex function creates one key with two
Revision{Main: 14} revisions. However, starting from version [[2]], etcd server
does not allow duplicate keys in a single transaction. This update to
newTestKeyIndex is to avoid confusion and ensure consistency with the
latest etcd server behavior.

REF:

[1]: etcd-io@be80d11
[2]: etcd-io#4376

Signed-off-by: Wei Fu <fuweid89@gmail.com>
  • Loading branch information
fuweid committed Jul 14, 2024
1 parent f0612bb commit 5e178e2
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions server/storage/mvcc/key_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestKeyIndexGet(t *testing.T) {
// modified: 16
// generations:
// {empty}
// {{14, 0}[1], {14, 1}[2], {16, 0}(t)[3]}
// {{14, 0}[1], {15, 1}[2], {16, 0}(t)[3]}
// {{8, 0}[1], {10, 0}[2], {12, 0}(t)[3]}
// {{2, 0}[1], {4, 0}[2], {6, 0}(t)[3]}
ki := newTestKeyIndex(zaptest.NewLogger(t))
Expand All @@ -45,8 +45,8 @@ func TestKeyIndexGet(t *testing.T) {
{16, Revision{}, Revision{}, 0, ErrRevisionNotFound},

// get on generation 3
{15, Revision{Main: 14, Sub: 1}, Revision{Main: 14}, 2, nil},
{14, Revision{Main: 14, Sub: 1}, Revision{Main: 14}, 2, nil},
{15, Revision{Main: 15, Sub: 1}, Revision{Main: 14}, 2, nil},
{14, Revision{Main: 14}, Revision{Main: 14}, 1, nil},

{13, Revision{}, Revision{}, 0, ErrRevisionNotFound},
{12, Revision{}, Revision{}, 0, ErrRevisionNotFound},
Expand Down Expand Up @@ -97,7 +97,8 @@ func TestKeyIndexSince(t *testing.T) {
Revision{Main: 8},
Revision{Main: 10},
Revision{Main: 12},
Revision{Main: 14, Sub: 1},
Revision{Main: 14},
Revision{Main: 15, Sub: 1},
Revision{Main: 16},
}
tests := []struct {
Expand All @@ -106,7 +107,7 @@ func TestKeyIndexSince(t *testing.T) {
wrevs []Revision
}{
{17, nil},
{16, allRevs[6:]},
{16, allRevs[7:]},
{15, allRevs[6:]},
{14, allRevs[5:]},
{13, allRevs[5:]},
Expand Down Expand Up @@ -231,7 +232,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
generations: []generation{
{created: Revision{Main: 2}, ver: 3, revs: []Revision{Revision{Main: 2}, Revision{Main: 4}, Revision{Main: 6}}},
{created: Revision{Main: 8}, ver: 3, revs: []Revision{Revision{Main: 8}, Revision{Main: 10}, Revision{Main: 12}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -245,7 +246,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
generations: []generation{
{created: Revision{Main: 2}, ver: 3, revs: []Revision{Revision{Main: 2}, Revision{Main: 4}, Revision{Main: 6}}},
{created: Revision{Main: 8}, ver: 3, revs: []Revision{Revision{Main: 8}, Revision{Main: 10}, Revision{Main: 12}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -261,7 +262,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
generations: []generation{
{created: Revision{Main: 2}, ver: 3, revs: []Revision{Revision{Main: 2}, Revision{Main: 4}, Revision{Main: 6}}},
{created: Revision{Main: 8}, ver: 3, revs: []Revision{Revision{Main: 8}, Revision{Main: 10}, Revision{Main: 12}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -277,7 +278,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
generations: []generation{
{created: Revision{Main: 2}, ver: 3, revs: []Revision{Revision{Main: 4}, Revision{Main: 6}}},
{created: Revision{Main: 8}, ver: 3, revs: []Revision{Revision{Main: 8}, Revision{Main: 10}, Revision{Main: 12}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -293,7 +294,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
generations: []generation{
{created: Revision{Main: 2}, ver: 3, revs: []Revision{Revision{Main: 4}, Revision{Main: 6}}},
{created: Revision{Main: 8}, ver: 3, revs: []Revision{Revision{Main: 8}, Revision{Main: 10}, Revision{Main: 12}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -308,7 +309,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
modified: Revision{Main: 16},
generations: []generation{
{created: Revision{Main: 8}, ver: 3, revs: []Revision{Revision{Main: 8}, Revision{Main: 10}, Revision{Main: 12}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -321,7 +322,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
modified: Revision{Main: 16},
generations: []generation{
{created: Revision{Main: 8}, ver: 3, revs: []Revision{Revision{Main: 8}, Revision{Main: 10}, Revision{Main: 12}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -334,7 +335,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
modified: Revision{Main: 16},
generations: []generation{
{created: Revision{Main: 8}, ver: 3, revs: []Revision{Revision{Main: 8}, Revision{Main: 10}, Revision{Main: 12}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -349,7 +350,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
modified: Revision{Main: 16},
generations: []generation{
{created: Revision{Main: 8}, ver: 3, revs: []Revision{Revision{Main: 8}, Revision{Main: 10}, Revision{Main: 12}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -364,7 +365,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
modified: Revision{Main: 16},
generations: []generation{
{created: Revision{Main: 8}, ver: 3, revs: []Revision{Revision{Main: 10}, Revision{Main: 12}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -379,7 +380,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
modified: Revision{Main: 16},
generations: []generation{
{created: Revision{Main: 8}, ver: 3, revs: []Revision{Revision{Main: 10}, Revision{Main: 12}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -393,7 +394,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
key: []byte("foo"),
modified: Revision{Main: 16},
generations: []generation{
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -405,7 +406,7 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
key: []byte("foo"),
modified: Revision{Main: 16},
generations: []generation{
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
Expand All @@ -417,12 +418,12 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
key: []byte("foo"),
modified: Revision{Main: 16},
generations: []generation{
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14}, Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
map[Revision]struct{}{
Revision{Main: 14, Sub: 1}: {},
Revision{Main: 14}: {},
},
},
{
Expand All @@ -431,12 +432,12 @@ func TestKeyIndexCompactAndKeep(t *testing.T) {
key: []byte("foo"),
modified: Revision{Main: 16},
generations: []generation{
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 14, Sub: 1}, Revision{Main: 16}}},
{created: Revision{Main: 14}, ver: 3, revs: []Revision{Revision{Main: 15, Sub: 1}, Revision{Main: 16}}},
{},
},
},
map[Revision]struct{}{
Revision{Main: 14, Sub: 1}: {},
Revision{Main: 15, Sub: 1}: {},
},
},
{
Expand Down Expand Up @@ -692,7 +693,7 @@ func newTestKeyIndex(lg *zap.Logger) *keyIndex {
// modified: 16
// generations:
// {empty}
// {{14, 0}[1], {14, 1}[2], {16, 0}(t)[3]}
// {{14, 0}[1], {15, 1}[2], {16, 0}(t)[3]}
// {{8, 0}[1], {10, 0}[2], {12, 0}(t)[3]}
// {{2, 0}[1], {4, 0}[2], {6, 0}(t)[3]}

Expand All @@ -704,7 +705,7 @@ func newTestKeyIndex(lg *zap.Logger) *keyIndex {
ki.put(lg, 10, 0)
ki.tombstone(lg, 12, 0)
ki.put(lg, 14, 0)
ki.put(lg, 14, 1)
ki.put(lg, 15, 1)
ki.tombstone(lg, 16, 0)
return ki
}

0 comments on commit 5e178e2

Please sign in to comment.