mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
storage: keep a full store's answer through retries and a batch; record the guarantees
SeaweedFS names a full store only to the assign that tries to grow a volume, so one object's retries and a cut's upload batch keep that answer over plainer failures. A real-weed integration test fills a tiny store and checks every round of concurrent uploads answers remote_full. The ledger gains the remote_full and LastCutFailure rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
36bc8f5683
commit
96a3d30003
7 files changed
+189
-7
No files matched your search
@@ -0,0 +1,94 @@
|
||||
//go:build chunkstore_integration
|
||||
|
||||
package chunkstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/storage"
|
||||
)
|
||||
|
||||
// A real SeaweedFS that has run out of volumes answers a full store, not an
|
||||
// outage: once a tiny store (-max 2 volumes of 1 MB) is filled, every round
|
||||
// of concurrent uploads (one cut's batch) fails, and at least one upload of
|
||||
// each round answers storage.ErrChunkRemoteFull, which the cut's batch
|
||||
// reports over its other failures. A change of SeaweedFS's wording turns this
|
||||
// red. Each upload is retried as a cut's is, keeping the full answer.
|
||||
func TestIntegration_FullStoreAnswersRemoteFull(t *testing.T) {
|
||||
c := startWeedSized(t, "", 1, 2)
|
||||
cl := c.client(t, "/swblock/vols/full")
|
||||
obj := make([]byte, 256<<10)
|
||||
|
||||
// Fill the store until it says it is full.
|
||||
deadline := time.Now().Add(2 * time.Minute)
|
||||
var filled error
|
||||
for i := 0; filled == nil; i++ {
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("the store never answered full after %d objects", i)
|
||||
}
|
||||
obj[0], obj[1] = byte(i), byte(i>>8)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
_, err := cl.Put(ctx, obj)
|
||||
cancel()
|
||||
if errors.Is(err, storage.ErrChunkRemoteFull) {
|
||||
filled = err
|
||||
}
|
||||
}
|
||||
t.Logf("full: %v", filled)
|
||||
|
||||
const rounds, uploads = 4, 8
|
||||
for r := 0; r < rounds; r++ {
|
||||
var (
|
||||
mu sync.Mutex
|
||||
full, done int
|
||||
others []string
|
||||
)
|
||||
var wg sync.WaitGroup
|
||||
for u := 0; u < uploads; u++ {
|
||||
wg.Add(1)
|
||||
go func(u int) {
|
||||
defer wg.Done()
|
||||
data := make([]byte, 64<<10)
|
||||
copy(data, fmt.Sprintf("round %d upload %d", r, u))
|
||||
// Retried as a cut's upload is, keeping a full answer (only the
|
||||
// assign that tries to grow a volume says so).
|
||||
var err error
|
||||
for attempt := 0; attempt < 3; attempt++ {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
_, e := cl.Put(ctx, data)
|
||||
cancel()
|
||||
if e == nil || errors.Is(e, storage.ErrChunkRemoteFull) || err == nil {
|
||||
err = e
|
||||
}
|
||||
if e == nil {
|
||||
break
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
switch {
|
||||
case err == nil:
|
||||
done++
|
||||
case errors.Is(err, storage.ErrChunkRemoteFull):
|
||||
full++
|
||||
default:
|
||||
others = append(others, err.Error())
|
||||
}
|
||||
}(u)
|
||||
}
|
||||
wg.Wait()
|
||||
if done > 0 {
|
||||
t.Fatalf("round %d: %d uploads succeeded on a full store", r, done)
|
||||
}
|
||||
if full == 0 {
|
||||
t.Fatalf("round %d: no upload answered a full store; the others: %q", r, others)
|
||||
}
|
||||
t.Logf("round %d: %d of %d uploads answered full", r, full, uploads)
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,14 @@ func startWeed(t *testing.T) *weedCluster {
|
||||
// startWeedWith starts the cluster with security (the contents of a
|
||||
// security.toml in its working directory; "" for none).
|
||||
func startWeedWith(t *testing.T, security string) *weedCluster {
|
||||
t.Helper()
|
||||
return startWeedSized(t, security, 256, 32)
|
||||
}
|
||||
|
||||
// startWeedSized starts the cluster with the master's volume size limit
|
||||
// (MB) and the volume server's volume count (-max): the store holds at most
|
||||
// max x sizeMB.
|
||||
func startWeedSized(t *testing.T, security string, sizeMB, max int) *weedCluster {
|
||||
t.Helper()
|
||||
weed := os.Getenv("CHUNKSTORE_WEED")
|
||||
if weed == "" {
|
||||
@@ -119,9 +127,9 @@ func startWeedWith(t *testing.T, security string) *weedCluster {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
run("master", "master", "-ip=127.0.0.1", fmt.Sprintf("-port=%d", mp), "-mdir="+filepath.Join(dir, "m"), "-volumeSizeLimitMB=256", "-defaultReplication=000")
|
||||
run("master", "master", "-ip=127.0.0.1", fmt.Sprintf("-port=%d", mp), "-mdir="+filepath.Join(dir, "m"), fmt.Sprintf("-volumeSizeLimitMB=%d", sizeMB), "-defaultReplication=000")
|
||||
waitTCP(t, c.master, 20*time.Second)
|
||||
run("volume", "volume", "-ip=127.0.0.1", fmt.Sprintf("-port=%d", vp), "-dir="+filepath.Join(dir, "v"), "-master="+c.master, "-max=32")
|
||||
run("volume", "volume", "-ip=127.0.0.1", fmt.Sprintf("-port=%d", vp), "-dir="+filepath.Join(dir, "v"), "-master="+c.master, fmt.Sprintf("-max=%d", max))
|
||||
run("filer", "filer", "-ip=127.0.0.1", fmt.Sprintf("-port=%d", fp), "-master="+c.master, "-defaultStoreDir="+filepath.Join(dir, "f"))
|
||||
waitTCP(t, c.filerGRPC, 30*time.Second)
|
||||
|
||||
|
||||
@@ -238,6 +238,9 @@ func TestStatusServer_ChunkErrorBodyIsTyped(t *testing.T) {
|
||||
{fmt.Errorf("x: %w", storage.ErrChunkRemoteFull), "remote_full", 503, true},
|
||||
{errors.Join(storage.ErrChunkRemoteUnavailable, errors.New("storage: cut upload failed"), fmt.Errorf("%w: chunkstore: assign", storage.ErrChunkRemoteFull)), "remote_full", 503, true},
|
||||
{errors.Join(storage.ErrCutCOWAborted, storage.ErrChunkRemoteFull), "cut_aborted", 503, true},
|
||||
{errors.Join(storage.ErrChunkCASOutcomeUnknown, storage.ErrChunkRemoteFull), "outcome_unknown", 503, true},
|
||||
{errors.Join(storage.ErrChunkLayerFenced, storage.ErrChunkRemoteFull), "fenced", 409, false},
|
||||
{errors.Join(storage.ErrChunkLayerClosed, storage.ErrChunkRemoteFull), "closing", 503, false},
|
||||
{fmt.Errorf("x: %w", storage.ErrChunkLayerClosed), "closing", 503, false},
|
||||
{errors.Join(storage.ErrCutCOWAborted, storage.ErrChunkLayerClosed, storage.ErrChunkRemoteUnavailable, context.Canceled), "closing", 503, false},
|
||||
{errors.Join(storage.ErrCutCOWAborted, storage.ErrChunkLayerDetached, storage.ErrChunkRemoteUnavailable, context.Canceled), "closing", 409, false},
|
||||
|
||||
@@ -3,6 +3,7 @@ package storage
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
@@ -103,3 +104,51 @@ func TestChunkCutFailureStatusNamesAFullStore(t *testing.T) {
|
||||
t.Fatalf("a successful cut left the failure %+v in status", *st.LastCutFailure)
|
||||
}
|
||||
}
|
||||
|
||||
// SeaweedFS names a full store only to the assign that tries to grow a
|
||||
// volume; a retry or a concurrent upload gets a plainer answer. The full
|
||||
// answer is kept through later attempts of one object and decides a
|
||||
// batch's answer whatever failed first.
|
||||
func TestChunkUploadKeepsTheFullStoreAnswer(t *testing.T) {
|
||||
s, _ := newChunkTestStore(t)
|
||||
cfg := ctConfig(1)
|
||||
cfg.UploadConcurrency = 2 // the batch case needs both uploads in flight
|
||||
layer := mustAttach(t, s, newFakeChunkRemote(), cfg).(*chunkLayerImpl)
|
||||
full := fmt.Errorf("%w: chunkstore: assign: No writable volumes and no free volumes left", ErrChunkRemoteFull)
|
||||
plain := errors.New("chunkstore: assign: No writable volumes")
|
||||
|
||||
// One object: full on the first attempt, plain on every retry.
|
||||
calls := 0
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 400*time.Millisecond)
|
||||
defer cancel()
|
||||
err := layer.putCapturedWith(ctx, "k1", []byte("x"), func(context.Context) error {
|
||||
calls++
|
||||
if calls == 1 {
|
||||
return full
|
||||
}
|
||||
return plain
|
||||
})
|
||||
if calls < 2 {
|
||||
t.Fatalf("%d attempts, want a retry after the first", calls)
|
||||
}
|
||||
if !errors.Is(err, ErrChunkRemoteFull) {
|
||||
t.Fatalf("an object whose first attempt found the store full answered %v", err)
|
||||
}
|
||||
|
||||
// A batch: one upload fails plainly first, another finds the store full.
|
||||
// Both are in flight before either answers.
|
||||
started, plainDone := make(chan struct{}), make(chan struct{})
|
||||
err = layer.uploadBatch(context.Background(), 2, func(ctx context.Context, i int) error {
|
||||
if i == 0 {
|
||||
<-started
|
||||
defer close(plainDone)
|
||||
return plain
|
||||
}
|
||||
close(started)
|
||||
<-plainDone
|
||||
return full
|
||||
})
|
||||
if !errors.Is(err, ErrChunkRemoteFull) {
|
||||
t.Fatalf("a batch with a full-store failure answered %v", err)
|
||||
}
|
||||
}
|
||||
@@ -25,16 +25,22 @@ func (l *chunkLayerImpl) putCapturedWith(ctx context.Context, key string, data [
|
||||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
backoff := 100 * time.Millisecond
|
||||
var lastErr error
|
||||
// full keeps a full store's answer through later attempts: SeaweedFS
|
||||
// says so only to the assign that tries to grow a volume, and a retry
|
||||
// may get a plainer answer.
|
||||
var lastErr, full error
|
||||
for {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return errors.Join(lastErr, err)
|
||||
return errors.Join(keepFull(full, lastErr), err)
|
||||
}
|
||||
err := put(ctx)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
lastErr = err
|
||||
if errors.Is(err, errChunkRemoteFull) {
|
||||
full = err
|
||||
}
|
||||
// Resolve a possibly committed binding before replaying the Put.
|
||||
got, readErr := l.remote.Get(ctx, key)
|
||||
if readErr == nil {
|
||||
@@ -50,13 +56,22 @@ func (l *chunkLayerImpl) putCapturedWith(ctx context.Context, key string, data [
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
timer.Stop()
|
||||
return errors.Join(lastErr, ctx.Err())
|
||||
return errors.Join(keepFull(full, lastErr), ctx.Err())
|
||||
case <-timer.C:
|
||||
}
|
||||
backoff = min(2*time.Second, 2*backoff)
|
||||
}
|
||||
}
|
||||
|
||||
// keepFull is err, joined with full when err itself does not say the store
|
||||
// is full.
|
||||
func keepFull(full, err error) error {
|
||||
if full == nil || errors.Is(err, errChunkRemoteFull) {
|
||||
return err
|
||||
}
|
||||
return errors.Join(full, err)
|
||||
}
|
||||
|
||||
// uploadBatch owns and joins all Put calls before its caller settles intents.
|
||||
// No storage/publication lock is acquired by workers. Cancellation stops new
|
||||
// admission; a remote ignoring cancellation remains joined, never declared done.
|
||||
@@ -90,9 +105,14 @@ func (l *chunkLayerImpl) uploadBatch(ctx context.Context, n int, put func(contex
|
||||
mu.Unlock()
|
||||
if err := put(ctx, i); err != nil {
|
||||
mu.Lock()
|
||||
if first == nil {
|
||||
switch {
|
||||
case first == nil:
|
||||
first = err
|
||||
cancel()
|
||||
case !errors.Is(first, errChunkRemoteFull) && errors.Is(err, errChunkRemoteFull):
|
||||
// A full store decides the batch's answer whatever
|
||||
// failed first (see keepFull).
|
||||
first = err
|
||||
}
|
||||
mu.Unlock()
|
||||
return
|
||||
|
||||
@@ -970,6 +970,11 @@ Notes:
|
||||
| `INV-CUT-PAYLOAD-SPILL-SOURCE-001` | Only a COW save made before a store mutation (`WriteContext`, `WriteBatchContext` or `applyEntryV3`) consumes side-file bytes; copy and upload workers never write the side file. | M5 Copy (COW save) | `core/storage/chunk_cut_cow.go` `beforeCOWMutation`, `copyCOWEntry`; `core/storage/walstore.go` `WriteContext`, `WriteBatchContext`; `core/storage/base_install_v3.go` `applyEntryV3` | `TestCutCOWV3_SpillWithinCapIsAccounted` (`core/storage/chunk_cut_cow_spillcap_test.go`) | — | ACTIVE |
|
||||
| `INV-CUT-PAYLOAD-JOIN-001` | Every upload worker of a cut or staging round has returned before that round's intents are cleaned up or its outcome is settled, also after an upload failure or cancellation. | M5 Upload → Closed, Aborted | `core/storage/chunk_upload.go` `uploadBatch`; `core/storage/chunk_layer.go` `captureLocked` | `TestChunkUploads_FailureJoinsBeforeIntentCleanup` (`core/storage/chunk_upload_parallel_test.go`) | — | ACTIVE |
|
||||
| `INV-CUT-ERROR-PRECEDENCE-001` | A chunk-control error body reports `cut_aborted` for a local cut abort even when the abort cancelled a remote upload, but an unknown CAS outcome, a fence or a closed or detached layer joined to it keeps its own code (`outcome_unknown`, `fenced`, `closing`). | M5 Copy, Upload → Aborted (HTTP error body) | `core/host/volume/chunk_control.go` `chunkErrorCode` | `TestStatusServer_ChunkErrorBodyIsTyped` (`core/host/volume/chunk_control_test.go`) | — | ACTIVE |
|
||||
| `INV-CUT-REMOTE-FULL-001` | An assign answer that names no free volumes (`no free volumes left`) is `storage.ErrChunkRemoteFull` on both assign paths; any other assign failure stays a plain remote failure (`remote_unavailable`). | M5 Upload → Aborted | `core/frontend/chunkstore/swfs.go` `assignErr` (`Put`, `reserve`) | `TestSWFS_AssignOnAFullStoreIsRemoteFull` (`core/frontend/chunkstore/swfs_test.go`), `TestIntegration_FullStoreAnswersRemoteFull` (`core/frontend/chunkstore/full_store_integration_test.go`, real weed) | — | ACTIVE |
|
||||
| `INV-CUT-REMOTE-FULL-002` | One object's retries and a cut's upload batch keep a full-store failure over plainer ones, since SeaweedFS names a full store only to the assign that tries to grow a volume. | M5 Upload → Aborted | `core/storage/chunk_upload.go` `putCapturedWith`, `uploadBatch`, `keepFull` | `TestChunkUploadKeepsTheFullStoreAnswer` (`core/storage/chunk_cut_failure_status_test.go`) | — | ACTIVE |
|
||||
| `INV-CUT-REMOTE-FULL-003` | The HTTP error body answers a full store as 503 `remote_full`, retryable, checked before `remote_unavailable`; a local cut abort, an unknown outcome, a fence or a closed layer joined to it keeps its own code. | M5 Upload → Aborted (HTTP error body) | `core/host/volume/chunk_control.go` `chunkErrorCode` | `TestStatusServer_ChunkErrorBodyIsTyped` (`core/host/volume/chunk_control_test.go`) | — | ACTIVE |
|
||||
| `INV-CUT-LAST-FAILURE-001` | Every failed cut, whatever requested it, sets `Chunk.Stats.LastCutFailure` (code, cause of at most 1024 bytes, time, repeats with that code); a successful cut clears it and a refusal leaves it. | M5 Upload → Aborted; Commit → Published | `core/storage/chunk_layer.go` `recordCut`, `noteCutFailureLocked`, `cutFailureCode` | `TestChunkCutFailureStatusNamesAFullStore` (`core/storage/chunk_cut_failure_status_test.go`) | — | ACTIVE |
|
||||
| `INV-CUT-LAST-FAILURE-002` | The holder logs one `cuts failing` WARN per change of the failure's code, not one per retry. | M5 Upload → Aborted | `core/storage/chunk_layer.go` `noteCutFailureLocked` | `TestChunkCutFailureStatusNamesAFullStore` (`core/storage/chunk_cut_failure_status_test.go`) | — | ACTIVE |
|
||||
| `INV-CATALOG-HEAD-CONFLICT-001` | A catalog transition that lost its conditional HEAD write (`layout.ErrPrecondition`, such as a snapshot delete raced by a cleaning's begin) reports `head_conflict` (409, retryable), never `internal`; it decides last, so any other cause joined to it keeps its own code. | M6 snapshot delete (HTTP error body) | `core/host/volume/chunk_control.go` `chunkErrorCode` | `TestSnapshotDeleteRacedByACleanBeginIsAHeadConflict`, `TestSnapshotDeleteUnderAPersistentConflictIsNeverInternal` (`core/host/volume/chunk_delete_head_conflict_test.go`); `TestStatusServer_ChunkErrorBodyIsTyped` (`core/host/volume/chunk_control_test.go`) | — | ACTIVE |
|
||||
| `INV-HOST-CUT-BUDGET-001` | A cooperating cut process holds a host OS slot from its admission, before staging or the capture barrier: see M7 free → admitted. | M7 free → admitted | `core/hostlimit/limiter.go` `Admit`; `core/storage/chunk_cut_budget.go`; blockvolume host-limit flags | `TestSlotsUrgentAndJoinedRelease` (`core/hostlimit/limiter_test.go`); `TestHostCutLimitDoesNotGateGuestIO` (`core/frontend/durable/host_limit_test.go`) | `HostBudget` HeldUntilJoined/PayloadBound/SpillBound (bounded OS-lock abstraction; fallback excluded) | ACTIVE |
|
||||
| `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 |
|
||||
@@ -1013,6 +1018,7 @@ Notes:
|
||||
- `INV-CUT-GUEST-BOUNDED-WAIT-001`: the capture a write waits for is its own or that of the chunk's current copier or saver. Lazily absent blocks are left to the copier, which fills them from the base HEAD after it releases the entry.
|
||||
- `INV-CUT-PAYLOAD-BOUNDED-001`: upload-worker buffers are not counted at run time; the budget reserves four chunk buffers per uploader and two per saver before any cached save is admitted (`cutPayloadWorkers`, `installCOWWindow`). Host-wide policy is a separate limiter module (`INV-HOST-CUT-BUDGET-001`). A host Budget admits a cut for this payload ceiling before staging or the barrier: see M5 Admit (test `TestCutBudgetRefusesBeforeBarrier`). Physical local I/O stays joined (`INV-CUT-COW-DRAIN-001`), and native at-H reads protect unsent candidates with COW (`INV-CUT-COW-OWNER-001`, `INV-CUT-HOOK-BEFORE-APPEND`).
|
||||
- `INV-CUT-PAYLOAD-SPILL-SOURCE-001`: `applyEntryV3` (base install and replicated applies) runs the same COW hook, so it would charge the side file if a cut window were open. That is believed unreachable, since cut admission needs a healthy primary and no base install, but nothing prevents it (enforced by reading: none).
|
||||
- `INV-CUT-REMOTE-FULL-001`: only the master that tries to grow a volume names a full store. A follower master, or one with volume growth disabled, answers without that text, so its full store still reads `remote_unavailable`. A volume server whose disk fills while it accepts a needle (the upload after the assign) is not classified here.
|
||||
- `INV-CUT-ERROR-PRECEDENCE-001`: class ORDER, a wire contract: the order of the cases in `chunkErrorCode` decides which code a caller sees when one error carries several causes.
|
||||
- `INV-CUT-INTENT-FIRST-001`: Begin opens or replays the holder session before its first upload; a failed Begin uploads nothing. Commit verifies the objects before installing their root (`INV-SNAPK-COMMIT-REACH-001`).
|
||||
- `INV-CUT-INTENT-CLOSE-001`: the session is retained while reusable uploads or an unresolved commit need it. Settled or abandoned work ends through commit or abort (`INV-SNAPK-ABORT-001`); no elapsed intent TTL or later-epoch GC fence decides this lifetime.
|
||||
|
||||
@@ -133,7 +133,9 @@ local-engine volume: `not applicable: no chunk store`.
|
||||
**Fix:** the holder's `Chunk.Stats.LastCutFailure` names the last failed cut, whatever requested it, with its `Code`
|
||||
and `Cause`; the holder logs one `cuts failing` WARN each time the code changes. `remote_full`: SeaweedFS has no
|
||||
writable volume and no free volume slot; add capacity (see [size a host](operator-guide.md#size-a-host)), and cuts
|
||||
resume on their next retry. A retryable `remote_unavailable` clears when SeaweedFS answers again. `remote_unavailable` also follows a request that ran out of its own 5-minute bound while SeaweedFS was
|
||||
resume on their next retry. A full store behind a follower master, or a master with volume growth disabled, still
|
||||
answers `remote_unavailable`: check SeaweedFS's free volume count too. A retryable `remote_unavailable` clears when
|
||||
SeaweedFS answers again. `remote_unavailable` also follows a request that ran out of its own 5-minute bound while SeaweedFS was
|
||||
still answering (a long first cut); rerun it: the work already done is kept. See [recovery point and sync policy](operator-guide.md#recovery-point-and-sync-policy).
|
||||
|
||||
## volume.cleaning
|
||||
|
||||
Reference in new issue
Block a user