mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
test, replication: reproduce concurrent heal and store attestation exchanges
This commit is contained in:
1 parent
69711830af
commit
51f5c6806d
1 file changed
+61
@@ -0,0 +1,61 @@
|
||||
package volume
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/replication"
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
"github.com/seaweedfs/seaweed-block/core/transport"
|
||||
)
|
||||
|
||||
type reconcileAttestationStore struct{ *storage.BlockStore }
|
||||
|
||||
func (*reconcileAttestationStore) StoreID() storage.StoreID { return storage.StoreID{2} }
|
||||
|
||||
// TestPublishHealthyDoesNotRaceStoreAttestation exercises the production heal
|
||||
// entry point while UpdateReplicaSet's asynchronous store learner is admitted.
|
||||
// Both exchanges use a real replica connection. Repetition exposes logical
|
||||
// frame ownership races that the Go memory race detector cannot detect.
|
||||
func TestPublishHealthyDoesNotRaceStoreAttestation(t *testing.T) {
|
||||
for attempt := 0; attempt < 500; attempt++ {
|
||||
func() {
|
||||
replica := &reconcileAttestationStore{storage.NewBlockStore(64, 4096)}
|
||||
listener, err := transport.NewReplicaListener("127.0.0.1:0", replica)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
listener.Serve()
|
||||
defer listener.Stop()
|
||||
|
||||
v := replication.NewReplicationVolume("v", storage.NewBlockStore(64, 4096))
|
||||
defer v.Close()
|
||||
epochs, err := transport.LoadEpochTable("", "v")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
v.SetEpochTable(epochs)
|
||||
v.RequireAttestedStores()
|
||||
var peer *replication.ReplicaPeer
|
||||
if err := v.ConfigurePeerLifecycleHook(func(p *replication.ReplicaPeer) { peer = p }, func(string) {}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
target := replication.ReplicaTarget{
|
||||
ReplicaID: "r2", DataAddr: listener.Addr(), ControlAddr: listener.Addr(),
|
||||
Epoch: 1, EndpointVersion: 1, StoreID: replica.StoreID(),
|
||||
}
|
||||
if err := v.UpdateReplicaSet(1, []replication.ReplicaTarget{target}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if peer == nil {
|
||||
t.Fatal("membership update did not install the replica")
|
||||
}
|
||||
exec := NewPeerCommandExecutor(peer)
|
||||
for exchange := 0; exchange < 2; exchange++ {
|
||||
exec.PublishHealthy("r2")
|
||||
if got := peer.State(); got != replication.ReplicaHealthy {
|
||||
t.Fatalf("attempt %d exchange %d: caught-up replica degraded during store attestation: %s", attempt, exchange, got)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user