Skip to content

Commit

Permalink
add TestReproducePerfRegressionOnCompact
Browse files Browse the repository at this point in the history
Signed-off-by: Chao Chen <[email protected]>
  • Loading branch information
chaochn47 committed Feb 7, 2025
1 parent 068f1cd commit 3b8677e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server/mvcc/kvstore_compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
"time"

humanize "github.com/dustin/go-humanize"
"go.etcd.io/etcd/server/v3/mvcc/buckets"
"go.uber.org/zap"

"go.etcd.io/etcd/server/v3/mvcc/buckets"
)

func (s *store) scheduleCompaction(compactMainRev, prevCompactRev int64) (KeyValueHash, error) {
Expand Down Expand Up @@ -85,6 +86,7 @@ func (s *store) scheduleCompaction(compactMainRev, prevCompactRev int64) (KeyVal
// update last
revToBytes(revision{main: rev.main, sub: rev.sub + 1}, last)
tx.Unlock()
// gofail: var compactBeforeForceCommit struct{}
// Immediately commit the compaction deletes instead of letting them accumulate in the write buffer
s.b.ForceCommit()
dbCompactionPauseMs.Observe(float64(time.Since(start) / time.Millisecond))
Expand Down
49 changes: 49 additions & 0 deletions tests/e2e/reproduce_17780_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,61 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"

clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/pkg/v3/stringutil"
"go.etcd.io/etcd/tests/v3/framework/e2e"
)

func TestReproducePerfRegressionOnCompact(t *testing.T) {
e2e.BeforeTest(t)
ctx := context.TODO()
cc := e2e.EtcdProcessClusterConfig{
ClusterSize: 1,
GoFailEnabled: true,
CompactionBatchLimit: 1,
WatchProcessNotifyInterval: 100 * time.Millisecond,
}
clus, cerr := e2e.NewEtcdProcessCluster(t, &cc)
require.NoError(t, cerr)
t.Cleanup(func() { require.NoError(t, clus.Stop()) })

client := newClient(t, clus.EndpointsGRPC(), e2e.ClientNonTLS, false)

var compactRev int64
for i := 0; i < 1000; i++ {
presp, err := client.Put(context.Background(), "foo", "bar")
require.NoError(t, err)
compactRev = presp.Header.Revision
}

require.NoError(t, clus.Procs[0].Failpoints().SetupHTTP(ctx, "compactBeforeForceCommit", `sleep(15)`))
_, err := client.Compact(context.Background(), compactRev)
require.NoError(t, err)

g := new(errgroup.Group)
putN := 100
for i := 0; i < 10; i++ {
g.Go(func() error {
for j := 0; j < putN; j++ {
start := time.Now()
_, err := client.Put(context.Background(), "foo", "bar")
if err != nil {
return err
}
if time.Since(start) > time.Second {
return fmt.Errorf("put latency is unexpectedly high")
}
}
return nil
})
}
if err := g.Wait(); err != nil {
t.Fatal(err)
}
}

// TestReproduce17780 reproduces the issue: https://github.com/etcd-io/etcd/issues/17780.
func TestReproduce17780(t *testing.T) {
e2e.BeforeTest(t)
Expand Down

0 comments on commit 3b8677e

Please sign in to comment.