mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
fix(hostlimit): uploads go unpaced only while every live lease is a fallback lease; wrapper test
A healthy lease admitted beside an urgent fallback lease kept no pacing (review). The pacing error wrapper now has a test: prefix, cause, no put. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
30dafdbb1e
commit
1a77477892
4 files changed
+65
-4
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package durable
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
// A pacing refusal before a chunk put names the host limiter, keeps its cause
|
||||
// and sends no put (issue 486: it was reported as the chunk remote).
|
||||
func TestChunkUploadPacingErrorNamesTheLimiter(t *testing.T) {
|
||||
inner := storage.NewMemChunkRemote()
|
||||
bound := &closeBoundRemote{ChunkRemote: inner, done: context.Background(),
|
||||
waitUpload: func(context.Context, int) error { return context.DeadlineExceeded }}
|
||||
err := bound.Put(context.Background(), "chunk-1", []byte("x"))
|
||||
if !errors.Is(err, context.DeadlineExceeded) || !strings.HasPrefix(err.Error(), "hostlimit: upload pacing before put chunk-1: ") {
|
||||
t.Fatalf("pacing error: %v", err)
|
||||
}
|
||||
if _, err := inner.Get(context.Background(), "chunk-1"); err == nil {
|
||||
t.Fatal("a chunk was put although pacing refused it")
|
||||
}
|
||||
}
|
||||
@@ -469,9 +469,15 @@ func (l *Limiter) WaitUpload(ctx context.Context, n int) error {
|
||||
l.mu.Unlock()
|
||||
return ErrRevoked
|
||||
}
|
||||
if l.fallback {
|
||||
// Only an urgent cut runs on the fallback, and with the shared
|
||||
// pool unusable there is no host cap to protect: not paced.
|
||||
// Only urgent cuts run on the fallback, and with the shared pool
|
||||
// unusable there is no host cap to protect: while every live lease
|
||||
// is a fallback lease, uploads are not paced. A healthy lease beside
|
||||
// one keeps its pacing.
|
||||
onlyFallback := l.fallback && len(l.live) > 0
|
||||
for _, held := range l.live {
|
||||
onlyFallback = onlyFallback && held.fallback
|
||||
}
|
||||
if onlyFallback {
|
||||
l.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -656,3 +656,33 @@ func TestUrgentFallbackUploadIsNotPaced(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// While an urgent cut is on the fallback, a healthy cut admitted after the
|
||||
// pool came back is still paced: only fallback leases alone go unpaced.
|
||||
func TestFallbackDoesNotUnpaceAHealthyLease(t *testing.T) {
|
||||
c := testConfig(t)
|
||||
c.BytesPerSecond = 16 << 20
|
||||
c.Directory += "-missing"
|
||||
l := newTest(t, c)
|
||||
urgent, err := l.Acquire(context.Background(), Urgent, nil)
|
||||
if err != nil || !l.Snapshot().(Stats).FallbackActive {
|
||||
t.Fatalf("urgent fallback: id=%d err=%v", urgent, err)
|
||||
}
|
||||
defer l.Release(urgent)
|
||||
if err := os.Mkdir(c.Directory, 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
normal, err := l.Admit(context.Background(), 1, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("healthy normal admission after the pool came back: %v", err)
|
||||
}
|
||||
defer l.Release(normal)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
if err := l.WaitUpload(ctx, 16<<20); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := l.WaitUpload(ctx, 16<<20); !errors.Is(err, context.DeadlineExceeded) {
|
||||
t.Fatalf("a healthy lease's second 16 MiB upload was not paced beside a fallback lease: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -839,7 +839,7 @@ Notes:
|
||||
| `INV-HOST-CUT-BUDGET-RESERVE-001` | Each admitted slot, urgent included, carries at most PayloadBytes of cut payload and at most COWBytes of COW side bytes; a reservation beyond COWBytes revokes the slot and aborts its cut. | M7 admitted | `core/hostlimit/limiter.go` `Admit`, `ReserveCOW`; `core/storage/chunk_cut_budget.go` | `TestHostCOWCapAbortsCutAndRetainsPermitUntilJoin` (`core/storage/chunk_host_budget_test.go`); `TestSlotsUrgentAndJoinedRelease` (`core/hostlimit/limiter_test.go`) | `HostBudget` PayloadBound/SpillBound | ACTIVE |
|
||||
| `INV-HOST-CUT-BUDGET-SETTLE-001` | A slot's OS lock is released only after its cut's workers settle and Release is called; cancellation, hold expiry and limiter Close abort the cut but keep the slot until then. | M7 draining → joined → released | `core/hostlimit/limiter.go` `Release`, `releaseLoop`, `revoke`, `Close`; `core/storage/chunk_layer.go` `captureLocked` | `TestCOWAbortHoldsSlotUntilWorkerSettlement`, `TestHoldExpiryAndCloseDoNotSteal`, `TestKilledProcessReleasesButLiveHolderDoesNot` (`core/hostlimit/limiter_test.go`); `TestHostCOWCapAbortsCutAndRetainsPermitUntilJoin` (`core/storage/chunk_host_budget_test.go`) | `HostBudget` HeldUntilJoined | ACTIVE |
|
||||
| `INV-HOST-CUT-BUDGET-CONFIG-001` | A busy configuration lock or a mismatched pool configuration refuses every class, urgent included, with no fallback. | M7 free → admitted (refused) | `core/hostlimit/limiter.go` `pool`, `Admit` | `TestConfigurationLockContentionRefusesAllClasses` (`core/hostlimit/limiter_test.go`) | — | ACTIVE |
|
||||
| `INV-HOST-CUT-BUDGET-FALLBACK-001` | Only urgent admissions (urgent move-final cuts and named seals) proceed while the pool is unavailable, on a per-process fallback that claims no host-wide bound, does not pace their uploads (there is no shared cap to protect), and is reported as fallback while any such lease lives. | M7 free → admitted (pool unavailable) | `core/hostlimit/limiter.go` `Admit`, `releaseLoop`, `WaitUpload` | `TestUnusablePoolClassPolicy`, `TestLastFallbackReleaseClearsActiveStatus`, `TestUrgentFallbackUploadIsNotPaced`, `TestConfigurationLockFailurePreservesPoolPolicy` (`core/hostlimit/limiter_test.go`); `TestChunkControl_NamedSnapshotUsesUrgentFallback` (`core/host/volume/chunk_control_adapter_test.go`) | `HostBudget` (fallback excluded) | ACTIVE |
|
||||
| `INV-HOST-CUT-BUDGET-FALLBACK-001` | Only urgent admissions (urgent move-final cuts and named seals) proceed while the pool is unavailable, on a per-process fallback that claims no host-wide bound, does not pace their uploads while only fallback leases live (there is no shared cap to protect; a healthy lease beside one stays paced), and is reported as fallback while any such lease lives. | M7 free → admitted (pool unavailable) | `core/hostlimit/limiter.go` `Admit`, `releaseLoop`, `WaitUpload` | `TestUnusablePoolClassPolicy`, `TestLastFallbackReleaseClearsActiveStatus`, `TestUrgentFallbackUploadIsNotPaced`, `TestFallbackDoesNotUnpaceAHealthyLease`, `TestConfigurationLockFailurePreservesPoolPolicy` (`core/hostlimit/limiter_test.go`); `TestChunkControl_NamedSnapshotUsesUrgentFallback` (`core/host/volume/chunk_control_adapter_test.go`) | `HostBudget` (fallback excluded) | ACTIVE |
|
||||
| `INV-HOST-CUT-BUDGET-PACING-001` | A process's upload pacing debt carries across its own leases, and a new process starts with no debt. | M7 admitted (upload pacing) | `core/hostlimit/limiter.go` `WaitUpload` | `TestPacingDebtSurvivesOwnLeaseTurnover`, `TestPacingFreshProcessesDoNotShareDebt` (`core/hostlimit/limiter_test.go`) | — | ACTIVE |
|
||||
| `INV-HOST-POOL-CONFIG-001` | A pool configuration is invisible until its complete synced temporary file is atomically renamed under the OS configuration lock. A killed initializer cannot leave a partial visible configuration that strands successors. | M7 configuration preparation/publication | `core/hostlimit` `publishConfig` | `TestKilledInitializerDoesNotPublishPartialConfiguration` | `HostBudget` NoPartialConfig/ConfigBeforeAdmission (filesystem atomicity checked natively) | ACTIVE |
|
||||
| `INV-HOST-URGENT-PENDING-001` | While an urgent cut holds its slot, or a caller holds HoldUrgentPending, every Normal admission on the host is refused with ErrUrgentPending (a held-slot wait); urgent admissions still run. | M7 host cut admission (Normal before a slot) | `core/hostlimit/limiter.go` `pool`, `Admit`; `core/hostlimit/pending.go` `HoldUrgentPending` | `TestNormalWaitsWhileUrgentPendingIsHeld`, `TestUrgentLeaseHoldsThePendingSignal` (`core/hostlimit/pending_test.go`); `TestSlotsUrgentAndJoinedRelease` (`core/hostlimit/limiter_test.go`) | — | ACTIVE |
|
||||
|
||||
Reference in new issue
Block a user