
We should use WithCompactPhysical to wait for compaction to finish, because 50ms sleep can't guarantee compaction is done. Based on the log, the defragment is finished before compaction, which is not expected. This patch is to make sure compaction should be finished before assertation. ``` =========================== defragment ============== logger.go:146: 2025-02-27T07:57:18.652Z INFO m0 finished defragment {"member": "m0"} ===================================================== logger.go:146: 2025-02-27T07:57:18.652Z INFO m0 grpc service status changed {"member": "m0", "service": "", "status": "SERVING"} logger.go:146: 2025-02-27T07:57:18.653Z INFO grpc [[core] [Channel #1457]Channel Connectivity change to SHUTDOWN] logger.go:146: 2025-02-27T07:57:18.653Z INFO grpc [[core] [Channel #1457]Closing the name resolver] logger.go:146: 2025-02-27T07:57:18.653Z INFO grpc [[core] [Channel #1457]ccBalancerWrapper: closing] logger.go:146: 2025-02-27T07:57:18.653Z INFO grpc [[core] [Channel #1457 SubChannel #1458]Subchannel Connectivity change to SHUTDOWN] logger.go:146: 2025-02-27T07:57:18.653Z INFO grpc [[core] [Channel #1457 SubChannel #1458]Subchannel deleted] logger.go:146: 2025-02-27T07:57:18.654Z INFO grpc [[transport] [client-transport 0xc00237bd48] Closing: rpc error: code = Canceled desc = grpc: the client connection is closing] logger.go:146: 2025-02-27T07:57:18.654Z INFO grpc [[transport] [client-transport 0xc00237bd48] loopyWriter exiting with error: rpc error: code = Canceled desc = grpc: the client connection is closing] logger.go:146: 2025-02-27T07:57:18.654Z INFO grpc [[transport] [server-transport 0xc0006bb520] Closing: EOF] logger.go:146: 2025-02-27T07:57:18.654Z INFO grpc [[core] [Channel #1457]Channel deleted] logger.go:146: 2025-02-27T07:57:18.654Z INFO grpc [[transport] [server-transport 0xc0006bb520] loopyWriter exiting with error: transport closed by client] hash.go:82: Error Trace: /home/prow/go/src/github.com/etcd-io/etcd/server/storage/mvcc/testutil/hash.go:82 /home/prow/go/src/github.com/etcd-io/etcd/server/storage/mvcc/testutil/hash.go:44 Error: Not equal: expected: testutil.KeyValueHash{Hash:0x94694091, CompactRevision:1278, Revision:2507} actual : testutil.KeyValueHash{Hash:0x58af47dc, CompactRevision:2488, Revision:2507} Diff: --- Expected +++ Actual @@ -1,4 +1,4 @@ (testutil.KeyValueHash) { - Hash: (uint32) 2489925777, - CompactRevision: (int64) 1278, + Hash: (uint32) 1487882204, + CompactRevision: (int64) 2488, Revision: (int64) 2507 Test: TestCompactionHash Messages: hashes do not match on rev 2488 cluster.go:1423: ========= Cluster termination started ===================== logger.go:146: 2025-02-27T07:57:18.655Z INFO grpc [[core] [Channel #1377]Channel Connectivity change to SHUTDOWN] logger.go:146: 2025-02-27T07:57:18.655Z INFO grpc [[core] [Channel #1377]Closing the name resolver] logger.go:146: 2025-02-27T07:57:18.655Z INFO grpc [[core] [Channel #1377]ccBalancerWrapper: closing] logger.go:146: 2025-02-27T07:57:18.656Z INFO grpc [[core] [Channel #1377 SubChannel #1378]Subchannel Connectivity change to SHUTDOWN] logger.go:146: 2025-02-27T07:57:18.656Z INFO grpc [[core] [Channel #1377 SubChannel #1378]Subchannel deleted] logger.go:146: 2025-02-27T07:57:18.656Z INFO grpc [[transport] [client-transport 0xc0025f2248] Closing: rpc error: code = Canceled desc = grpc: the client connection is closing] logger.go:146: 2025-02-27T07:57:18.656Z INFO grpc [[transport] [client-transport 0xc0025f2248] loopyWriter exiting with error: rpc error: code = Canceled desc = grpc: the client connection is closing] logger.go:146: 2025-02-27T07:57:18.656Z INFO grpc [[transport] [server-transport 0xc000b56ea0] Closing: EOF] =========================== compaction ============== logger.go:146: 2025-02-27T07:57:18.656Z INFO m0 finished scheduled compaction {"member": "m0", "compact-revision": 2488, "took": "129.590742ms", "hash": 2489925777, "current-db-size-bytes": 40960, "current-db-size": "41 kB", "current-db-size-in-use-bytes": 40960, "current-db-size-in-use": "41 kB"} ===================================================== ``` Fixes: #19497 Signed-off-by: Wei Fu <fuweid89@gmail.com>
83 lines
2.5 KiB
Go
83 lines
2.5 KiB
Go
// Copyright 2022 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 integration
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
clientv3 "go.etcd.io/etcd/client/v3"
|
|
"go.etcd.io/etcd/server/v3/etcdserver"
|
|
"go.etcd.io/etcd/server/v3/storage/mvcc/testutil"
|
|
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
|
|
)
|
|
|
|
// TestCompactionHash tests the compaction hash
|
|
// TODO: Change this to fuzz test
|
|
func TestCompactionHash(t *testing.T) {
|
|
integration2.BeforeTest(t)
|
|
|
|
clus := integration2.NewCluster(t, &integration2.ClusterConfig{Size: 1})
|
|
defer clus.Terminate(t)
|
|
|
|
cc, err := clus.ClusterClient(t)
|
|
require.NoError(t, err)
|
|
client := &http.Client{
|
|
Transport: &http.Transport{
|
|
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
|
|
return net.Dial("unix", clus.Members[0].PeerURLs[0].Host)
|
|
},
|
|
},
|
|
}
|
|
|
|
testutil.TestCompactionHash(context.Background(), t, hashTestCase{cc, clus.Members[0].GRPCURL, client, clus.Members[0].Server}, 1000)
|
|
}
|
|
|
|
type hashTestCase struct {
|
|
*clientv3.Client
|
|
url string
|
|
http *http.Client
|
|
server *etcdserver.EtcdServer
|
|
}
|
|
|
|
func (tc hashTestCase) Put(ctx context.Context, key, value string) error {
|
|
_, err := tc.Client.Put(ctx, key, value)
|
|
return err
|
|
}
|
|
|
|
func (tc hashTestCase) Delete(ctx context.Context, key string) error {
|
|
_, err := tc.Client.Delete(ctx, key)
|
|
return err
|
|
}
|
|
|
|
func (tc hashTestCase) HashByRev(ctx context.Context, rev int64) (testutil.KeyValueHash, error) {
|
|
resp, err := etcdserver.HashByRev(ctx, tc.server.Cluster().ID(), tc.http, "http://unix", rev)
|
|
return testutil.KeyValueHash{Hash: resp.Hash, CompactRevision: resp.CompactRevision, Revision: resp.Header.Revision}, err
|
|
}
|
|
|
|
func (tc hashTestCase) Defrag(ctx context.Context) error {
|
|
_, err := tc.Client.Defragment(ctx, tc.url)
|
|
return err
|
|
}
|
|
|
|
func (tc hashTestCase) Compact(ctx context.Context, rev int64) error {
|
|
_, err := tc.Client.Compact(ctx, rev, clientv3.WithCompactPhysical())
|
|
return err
|
|
}
|