-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.5] fix revision loss issue caused by compaction - 17780 #17865
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6b03446
server/mvcc: introduce compactBeforeSetFinishedCompact failpoint
fuweid 7beff57
tests/e2e: reproduce #17780
fuweid c06b17b
server/storage: update currentRev if scheduledCompact > currentRev
fuweid 0af22ab
server/mvcc: should update currentRev in revMu
fuweid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright 2024 The etcd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package e2e | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
clientv3 "go.etcd.io/etcd/client/v3" | ||
"go.etcd.io/etcd/pkg/v3/stringutil" | ||
"go.etcd.io/etcd/tests/v3/framework/e2e" | ||
) | ||
|
||
// TestReproduce17780 reproduces the issue: https://github.com/etcd-io/etcd/issues/17780. | ||
func TestReproduce17780(t *testing.T) { | ||
e2e.BeforeTest(t) | ||
|
||
compactionBatchLimit := 10 | ||
|
||
ctx := context.TODO() | ||
clus, cerr := e2e.NewEtcdProcessCluster(t, | ||
&e2e.EtcdProcessClusterConfig{ | ||
ClusterSize: 3, | ||
GoFailEnabled: true, | ||
SnapshotCount: 1000, | ||
CompactionBatchLimit: compactionBatchLimit, | ||
WatchProcessNotifyInterval: 100 * time.Millisecond, | ||
}, | ||
) | ||
require.NoError(t, cerr) | ||
|
||
t.Cleanup(func() { require.NoError(t, clus.Stop()) }) | ||
|
||
leaderIdx := clus.WaitLeader(t) | ||
targetIdx := (leaderIdx + 1) % clus.Cfg.ClusterSize | ||
|
||
cli := newClient(t, clus.Procs[targetIdx].EndpointsGRPC(), e2e.ClientNonTLS, false) | ||
|
||
// Revision: 2 -> 8 for new keys | ||
n := compactionBatchLimit - 2 | ||
valueSize := 16 | ||
for i := 2; i <= n; i++ { | ||
_, err := cli.Put(ctx, fmt.Sprintf("%d", i), stringutil.RandString(uint(valueSize))) | ||
require.NoError(t, err) | ||
} | ||
|
||
// Revision: 9 -> 11 for delete keys with compared revision | ||
// | ||
// We need last compaction batch is no-op and all the tombstones should | ||
// be deleted in previous compaction batch. So that we just lost the | ||
// finishedCompactRev after panic. | ||
for i := 9; i <= compactionBatchLimit+1; i++ { | ||
rev := i - 5 | ||
key := fmt.Sprintf("%d", rev) | ||
|
||
_, err := cli.Delete(ctx, key) | ||
require.NoError(t, err) | ||
} | ||
|
||
require.NoError(t, clus.Procs[targetIdx].Failpoints().SetupHTTP(ctx, "compactBeforeSetFinishedCompact", `panic`)) | ||
|
||
_, err := cli.Compact(ctx, 11, clientv3.WithCompactPhysical()) | ||
require.Error(t, err) | ||
|
||
require.Error(t, clus.Procs[targetIdx].Stop()) | ||
// NOTE: The proc panics and exit code is 2. It's impossible to restart | ||
// that etcd proc because last exit code is 2 and Restart() refuses to | ||
// start new one. Using IsRunning() function is to cleanup status. | ||
require.False(t, clus.Procs[targetIdx].IsRunning()) | ||
require.NoError(t, clus.Procs[targetIdx].Restart()) | ||
|
||
// NOTE: We should not decrease the revision if there is no record | ||
// about finished compact operation. | ||
resp, err := cli.Get(ctx, fmt.Sprintf("%d", n)) | ||
require.NoError(t, err) | ||
assert.GreaterOrEqual(t, resp.Header.Revision, int64(11)) | ||
|
||
// Revision 4 should be deleted by compaction. | ||
resp, err = cli.Get(ctx, fmt.Sprintf("%d", 4)) | ||
require.NoError(t, err) | ||
require.True(t, resp.Count == 0) | ||
|
||
next := 20 | ||
for i := 12; i <= next; i++ { | ||
_, err := cli.Put(ctx, fmt.Sprintf("%d", i), stringutil.RandString(uint(valueSize))) | ||
require.NoError(t, err) | ||
} | ||
|
||
expectedRevision := next | ||
for procIdx, proc := range clus.Procs { | ||
cli = newClient(t, proc.EndpointsGRPC(), e2e.ClientNonTLS, false) | ||
resp, err := cli.Get(ctx, fmt.Sprintf("%d", next)) | ||
require.NoError(t, err) | ||
|
||
assert.GreaterOrEqual(t, resp.Header.Revision, int64(expectedRevision), | ||
fmt.Sprintf("LeaderIdx: %d, Current: %d", leaderIdx, procIdx)) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might be missing some improvements to
expect
on release-3.5 branch. As a testing library change, we could consider backporting them avoid need for branch specific test code code causing branches to diverge.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to make the test as consistent as possible. @fuweid can you please raise a followup to track it? thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #17869