Files
upstream-seaweedfs/weed/topology/race_condition_stress_test.go
upstream-mirror 89f5be005d
Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
snapshot of https://github.com/seaweedfs/seaweedfs.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 03:23:42 +05:00

351 lines
11 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package topology
import (
"fmt"
"sync"
"sync/atomic"
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/sequence"
"github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
"github.com/seaweedfs/seaweedfs/weed/storage/super_block"
"github.com/seaweedfs/seaweedfs/weed/storage/types"
)
// TestRaceConditionStress simulates the original issue scenario:
// High concurrent writes causing capacity misjudgment
func TestRaceConditionStress(t *testing.T) {
// Create a cluster similar to the issue description:
// 3 volume servers, 200GB each, 5GB volume limit = 40 volumes max per server
const (
numServers = 3
volumeLimitMB = 5000 // 5GB in MB
storagePerServerGB = 200 // 200GB per server
maxVolumesPerServer = storagePerServerGB * 1024 / volumeLimitMB // 200*1024/5000 = 40
concurrentRequests = 50 // High concurrency like the issue
)
// Create test topology
topo := NewTopology("weedfs", sequence.NewMemorySequencer(), uint64(volumeLimitMB)*1024*1024, 5, false)
dc := NewDataCenter("dc1")
topo.LinkChildNode(dc)
rack := NewRack("rack1")
dc.LinkChildNode(rack)
// Create 3 volume servers with realistic capacity
servers := make([]*DataNode, numServers)
for i := 0; i < numServers; i++ {
dn := NewDataNode(fmt.Sprintf("server%d", i+1))
rack.LinkChildNode(dn)
// Set up disk with capacity for 40 volumes
disk := NewDisk(types.HardDriveType.String())
disk.diskUsages.getOrCreateDisk(types.HardDriveType).maxVolumeCount = maxVolumesPerServer
dn.LinkChildNode(disk)
servers[i] = dn
}
vg := NewDefaultVolumeGrowth()
rp, _ := super_block.NewReplicaPlacementFromString("000") // Single replica like the issue
option := &VolumeGrowOption{
Collection: "test-bucket-large", // Same collection name as issue
ReplicaPlacement: rp,
DiskType: types.HardDriveType,
}
// Track results
var successfulAllocations int64
var failedAllocations int64
var totalVolumesCreated int64
var wg sync.WaitGroup
// Launch concurrent volume creation requests
startTime := time.Now()
for i := 0; i < concurrentRequests; i++ {
wg.Add(1)
go func(requestId int) {
defer wg.Done()
// This is the critical test: multiple threads trying to allocate simultaneously
servers, reservation, err := vg.findEmptySlotsForOneVolume(topo, option, true)
if err != nil {
atomic.AddInt64(&failedAllocations, 1)
t.Logf("Request %d failed: %v", requestId, err)
return
}
// Simulate volume creation delay (like in real scenario)
time.Sleep(time.Millisecond * 50)
// Simulate successful volume creation
for _, server := range servers {
disk := server.children[NodeId(types.HardDriveType.String())].(*Disk)
deltaDiskUsage := &DiskUsageCounts{
volumeCount: 1,
}
disk.UpAdjustDiskUsageDelta(types.HardDriveType, deltaDiskUsage)
atomic.AddInt64(&totalVolumesCreated, 1)
}
// Release reservations (simulates successful registration)
reservation.releaseAllReservations()
atomic.AddInt64(&successfulAllocations, 1)
}(i)
}
wg.Wait()
duration := time.Since(startTime)
// Verify results
t.Logf("Test completed in %v", duration)
t.Logf("Successful allocations: %d", successfulAllocations)
t.Logf("Failed allocations: %d", failedAllocations)
t.Logf("Total volumes created: %d", totalVolumesCreated)
// Check capacity limits are respected
totalCapacityUsed := int64(0)
for i, server := range servers {
disk := server.children[NodeId(types.HardDriveType.String())].(*Disk)
volumeCount := disk.diskUsages.getOrCreateDisk(types.HardDriveType).volumeCount
totalCapacityUsed += volumeCount
t.Logf("Server %d: %d volumes (max: %d)", i+1, volumeCount, maxVolumesPerServer)
// Critical test: No server should exceed its capacity
if volumeCount > maxVolumesPerServer {
t.Errorf("RACE CONDITION DETECTED: Server %d exceeded capacity: %d > %d",
i+1, volumeCount, maxVolumesPerServer)
}
}
// Verify totals make sense
if totalVolumesCreated != totalCapacityUsed {
t.Errorf("Volume count mismatch: created=%d, actual=%d", totalVolumesCreated, totalCapacityUsed)
}
// The total should never exceed the cluster capacity (120 volumes for 3 servers × 40 each)
maxClusterCapacity := int64(numServers * maxVolumesPerServer)
if totalCapacityUsed > maxClusterCapacity {
t.Errorf("RACE CONDITION DETECTED: Cluster capacity exceeded: %d > %d",
totalCapacityUsed, maxClusterCapacity)
}
// With reservations, we should have controlled allocation
// Total requests = successful + failed should equal concurrentRequests
if successfulAllocations+failedAllocations != concurrentRequests {
t.Errorf("Request count mismatch: success=%d + failed=%d != total=%d",
successfulAllocations, failedAllocations, concurrentRequests)
}
t.Logf("Race condition test passed: Capacity limits respected with %d concurrent requests",
concurrentRequests)
}
// TestCapacityJudgmentAccuracy verifies that the capacity calculation is accurate
// under various load conditions
func TestCapacityJudgmentAccuracy(t *testing.T) {
// Create a single server with known capacity
topo := NewTopology("weedfs", sequence.NewMemorySequencer(), 5*1024*1024*1024, 5, false)
dc := NewDataCenter("dc1")
topo.LinkChildNode(dc)
rack := NewRack("rack1")
dc.LinkChildNode(rack)
dn := NewDataNode("server1")
rack.LinkChildNode(dn)
// Server with capacity for exactly 10 volumes
disk := NewDisk(types.HardDriveType.String())
diskUsage := disk.diskUsages.getOrCreateDisk(types.HardDriveType)
diskUsage.maxVolumeCount = 10
dn.LinkChildNode(disk)
// Also set max volume count on the DataNode level (gets propagated up)
dn.diskUsages.getOrCreateDisk(types.HardDriveType).maxVolumeCount = 10
vg := NewDefaultVolumeGrowth()
rp, _ := super_block.NewReplicaPlacementFromString("000")
option := &VolumeGrowOption{
Collection: "test",
ReplicaPlacement: rp,
DiskType: types.HardDriveType,
}
// Test accurate capacity reporting at each step
for i := 0; i < 10; i++ {
// Check available space before reservation
availableBefore := dn.AvailableSpaceFor(option)
availableForReservation := dn.AvailableSpaceForReservation(option)
expectedAvailable := int64(10 - i)
if availableBefore != expectedAvailable {
t.Errorf("Step %d: Expected %d available, got %d", i, expectedAvailable, availableBefore)
}
if availableForReservation != expectedAvailable {
t.Errorf("Step %d: Expected %d available for reservation, got %d", i, expectedAvailable, availableForReservation)
}
// Try to reserve and allocate
_, reservation, err := vg.findEmptySlotsForOneVolume(topo, option, true)
if err != nil {
t.Fatalf("Step %d: Unexpected reservation failure: %v", i, err)
}
// Check that available space for reservation decreased
availableAfterReservation := dn.AvailableSpaceForReservation(option)
if availableAfterReservation != expectedAvailable-1 {
t.Errorf("Step %d: Expected %d available after reservation, got %d",
i, expectedAvailable-1, availableAfterReservation)
}
// Simulate successful volume creation by properly updating disk usage hierarchy
disk := dn.children[NodeId(types.HardDriveType.String())].(*Disk)
// Create a volume usage delta to simulate volume creation
deltaDiskUsage := &DiskUsageCounts{
volumeCount: 1,
}
// Properly propagate the usage up the hierarchy
disk.UpAdjustDiskUsageDelta(types.HardDriveType, deltaDiskUsage)
// Debug: Check the volume count after update
diskUsageOnNode := dn.diskUsages.getOrCreateDisk(types.HardDriveType)
currentVolumeCount := atomic.LoadInt64(&diskUsageOnNode.volumeCount)
t.Logf("Step %d: Volume count after update: %d", i, currentVolumeCount)
// Release reservation
reservation.releaseAllReservations()
// Verify final state
availableAfter := dn.AvailableSpaceFor(option)
expectedAfter := int64(10 - i - 1)
if availableAfter != expectedAfter {
t.Errorf("Step %d: Expected %d available after creation, got %d",
i, expectedAfter, availableAfter)
// More debugging
diskUsageOnNode := dn.diskUsages.getOrCreateDisk(types.HardDriveType)
maxVolumes := atomic.LoadInt64(&diskUsageOnNode.maxVolumeCount)
remoteVolumes := atomic.LoadInt64(&diskUsageOnNode.remoteVolumeCount)
actualVolumeCount := atomic.LoadInt64(&diskUsageOnNode.volumeCount)
t.Logf("Debug Step %d: max=%d, volume=%d, remote=%d", i, maxVolumes, actualVolumeCount, remoteVolumes)
}
}
// At this point, no more reservations should succeed
_, _, err := vg.findEmptySlotsForOneVolume(topo, option, true)
if err == nil {
t.Error("Expected reservation to fail when at capacity")
}
t.Logf("Capacity judgment accuracy test passed")
}
// TestReservationSystemPerformance measures the performance impact of reservations
func TestReservationSystemPerformance(t *testing.T) {
// Create topology
topo := NewTopology("weedfs", sequence.NewMemorySequencer(), 32*1024, 5, false)
dc := NewDataCenter("dc1")
topo.LinkChildNode(dc)
rack := NewRack("rack1")
dc.LinkChildNode(rack)
dn := NewDataNode("server1")
rack.LinkChildNode(dn)
disk := NewDisk(types.HardDriveType.String())
disk.diskUsages.getOrCreateDisk(types.HardDriveType).maxVolumeCount = 1000
dn.LinkChildNode(disk)
vg := NewDefaultVolumeGrowth()
rp, _ := super_block.NewReplicaPlacementFromString("000")
option := &VolumeGrowOption{
Collection: "test",
ReplicaPlacement: rp,
DiskType: types.HardDriveType,
}
// Benchmark reservation operations
const iterations = 1000
startTime := time.Now()
for i := 0; i < iterations; i++ {
_, reservation, err := vg.findEmptySlotsForOneVolume(topo, option, true)
if err != nil {
t.Fatalf("Iteration %d failed: %v", i, err)
}
reservation.releaseAllReservations()
// Simulate volume creation
diskUsage := dn.diskUsages.getOrCreateDisk(types.HardDriveType)
atomic.AddInt64(&diskUsage.volumeCount, 1)
}
duration := time.Since(startTime)
avgDuration := duration / iterations
t.Logf("Performance: %d reservations in %v (avg: %v per reservation)",
iterations, duration, avgDuration)
// Performance should be reasonable (less than 1ms per reservation on average)
if avgDuration > time.Millisecond {
t.Errorf("Reservation system performance concern: %v per reservation", avgDuration)
} else {
t.Logf("Performance test passed: %v per reservation", avgDuration)
}
}
func TestDisk_GetEcShards_Race(t *testing.T) {
d := NewDisk("hdd")
// Pre-populate with one shard
initialShard := &erasure_coding.EcVolumeInfo{
VolumeId: needle.VolumeId(1),
ShardsInfo: erasure_coding.NewShardsInfo(),
}
initialShard.ShardsInfo.Set(erasure_coding.ShardInfo{Id: 0, Size: 100})
d.AddOrUpdateEcShard(initialShard)
var wg sync.WaitGroup
wg.Add(10)
// Goroutine 1-5: Continuously read shards
for j := 0; j < 5; j++ {
go func() {
defer wg.Done()
for i := 0; i < 10000; i++ {
d.GetEcShards()
}
}()
}
// Goroutine 6-10: Continuously update shards
for j := 0; j < 5; j++ {
go func() {
defer wg.Done()
for i := 0; i < 10000; i++ {
shard := &erasure_coding.EcVolumeInfo{
VolumeId: needle.VolumeId(i % 100),
ShardsInfo: erasure_coding.NewShardsInfo(),
}
shard.ShardsInfo.Set(erasure_coding.ShardInfo{Id: erasure_coding.ShardId(i % 14), Size: 100})
d.AddOrUpdateEcShard(shard)
}
}()
}
wg.Wait()
}