From c19beea84de74ce95eb7d13ba9c17c9aa5e417ff Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Thu, 4 Jul 2024 17:52:36 +0800 Subject: [PATCH] tests/e2e: add cases for watcher on compacted revision when it's mix version Signed-off-by: Wei Fu --- tests/e2e/watch_test.go | 89 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/tests/e2e/watch_test.go b/tests/e2e/watch_test.go index 17d34fdfd41e..10af556532a8 100644 --- a/tests/e2e/watch_test.go +++ b/tests/e2e/watch_test.go @@ -32,6 +32,7 @@ import ( "go.etcd.io/etcd/api/v3/etcdserverpb" "go.etcd.io/etcd/api/v3/mvccpb" v3rpc "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" + "go.etcd.io/etcd/client/pkg/v3/fileutil" clientv3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/tests/v3/framework/config" "go.etcd.io/etcd/tests/v3/framework/e2e" @@ -390,6 +391,94 @@ func TestVerifyHashKVAfterCompact(t *testing.T) { } } +func TestVerifyHashKVAfterCompactMixVersion(t *testing.T) { + if !fileutil.Exist(e2e.BinPath.EtcdLastRelease) { + t.Skipf("%q does not exist", e2e.BinPath.EtcdLastRelease) + } + + tests := []struct { + compactedOnTombstoneRev bool + hashKVOnCompactedRev bool + consistentHash bool + }{ + // The test performs compaction on tombstone revision. + // The tombstone revision is always larger than last compacted revision. + // So, both versions take the same hash value in compaction. + { + compactedOnTombstoneRev: true, + hashKVOnCompactedRev: true, + consistentHash: true, + }, + // The test performs compaction on tombstone revision. + // For v3.5 version, the tombstone revision has been deleted so that that revision won't be included in new hash value. + // For main branch, even if the tombstone revision still exists, + // the tombstone revision is smaller that last compacted revision and the index.Keep(hashOnRev) won't keep it. + // So, main branch won't include the tombstone revision in new hash value as well. + // Both versions take the same hash value from HashKV. + { + compactedOnTombstoneRev: true, + hashKVOnCompactedRev: false, + consistentHash: true, + }, + // FIXME(fuweid): + // + // The test performs HashKV on tombstone revision. + // For v3.5 version, the index.Keep(tombstoneRev) returns empty. + // So, the last compacted revision will be included in new hash value again. + // + // However, for the main branch, the index.Keep(tombstoneRev) returns one revision. + // So, the last compacted revision won't be included in new hash value. + // It caused inconsistent hash value. + { + compactedOnTombstoneRev: false, + hashKVOnCompactedRev: true, + consistentHash: false, + }, + // The test performs HashKV on non-tombstone revision. + // The index.Keep(non-tombstone-revision) always returns non-empty result. + // Both versions won't include last compacted revision in new revision. + { + compactedOnTombstoneRev: false, + hashKVOnCompactedRev: false, + consistentHash: true, + }, + } + + for idx, tt := range tests { + t.Run(fmt.Sprintf("#%d", idx), func(t *testing.T) { + verifyHashKVAfterCompactFn(t, e2e.QuorumLastVersion, func(t *testing.T, cli *e2e.EtcdctlV3, lastRevision int64, tombstoneRevisions []int64) { + ctx := context.Background() + + hashKVOnCompactedRev := lastRevision + if tt.hashKVOnCompactedRev { + hashKVOnCompactedRev = tombstoneRevisions[len(tombstoneRevisions)-1] + } + + compactedOnRev := tombstoneRevisions[len(tombstoneRevisions)-1] + if !tt.compactedOnTombstoneRev { + compactedOnRev = hashKVOnCompactedRev - 8 + } + + t.Logf("COMPACT rev=%d", compactedOnRev) + _, err := cli.Compact(ctx, compactedOnRev, config.CompactOption{Physical: true}) + require.NoError(t, err) + + t.Logf("HashKV on rev=%d", hashKVOnCompactedRev) + resp, err := cli.HashKV(ctx, hashKVOnCompactedRev) + require.NoError(t, err) + + require.Len(t, resp, 3) + require.True(t, resp[0].Hash != 0) + t.Logf("One Hash value is %d", resp[0].Hash) + + require.Equal(t, tt.consistentHash, resp[0].Hash == resp[1].Hash && resp[1].Hash == resp[2].Hash, + "Expected consistentHash = %v, but got %d - %d - %d", + tt.consistentHash, resp[0].Hash, resp[1].Hash, resp[2].Hash) + }) + }) + } +} + // verifyHashKVAfterCompactFn will generate 3 tombstones on key foo. func verifyHashKVAfterCompactFn( t *testing.T,