mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
* volume: refuse a write the local volume already rejects before the replica fan-out ReplicatedWrite runs the local needle write and the replica fan-out concurrently. When the local volume is read-only (noWriteOrDelete or noWriteCanDelete), unavailable, or on a disk below -minFreeSpace, the local leg fails, but the replicas have already stored the needle. The client writes to a new file id, so the replica copy is referenced by nothing, and the copies of the volume differ in file count and size until volume.fsck purges it. Ask the volume whether it accepts writes (Volume.CheckWritable, the same check Store.WriteVolumeNeedle applies first) before the fan-out starts, and fail the request without contacting the replicas. The error, its metrics and the ErrorWriteRefused rule are those of a failed local write. A type=replicate request, and a write with no local copy, are unchanged. A volume that turns read-only after the check, during the write, still leaves a replica copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume: observe a write refused before the fan-out in the local write histogram The local write that the up-front refusal replaces observed the refusal in the WriteToLocalDisk request histogram next to the error counter. Observe it there too, so a refused write is counted as before. The replication metrics do not record it, since it no longer reaches the replicas. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * volume(rs): refuse a write the local volume already rejects before forwarding it to the replicas Mirror the Go up-front check: when the local volume refuses writes, the replicated upload fails with the local refusal and never spawns the replica fan-out, so no replica keeps a needle nothing references. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package storage
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/super_block"
|
|
)
|
|
|
|
// CheckWritable is the refusal WriteVolumeNeedle applies, so each way a volume
|
|
// stops taking writes must show up in it and in the write itself.
|
|
func TestVolumeCheckWritableMatchesWrite(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
refuse func(v *Volume)
|
|
readOnly bool
|
|
}{
|
|
{name: "writable", refuse: func(v *Volume) {}},
|
|
{name: "no write or delete", readOnly: true, refuse: func(v *Volume) {
|
|
v.noWriteLock.Lock()
|
|
v.noWriteOrDelete = true
|
|
v.noWriteLock.Unlock()
|
|
}},
|
|
{name: "no write, can delete", readOnly: true, refuse: func(v *Volume) {
|
|
v.noWriteLock.Lock()
|
|
v.noWriteCanDelete = true
|
|
v.noWriteLock.Unlock()
|
|
}},
|
|
{name: "disk space low", readOnly: true, refuse: func(v *Volume) {
|
|
v.location = &DiskLocation{}
|
|
v.location.isDiskSpaceLow.Store(true)
|
|
}},
|
|
{name: "io unavailable", readOnly: true, refuse: func(v *Volume) {
|
|
v.noWriteLock.Lock()
|
|
v.ioUnavailable = true
|
|
v.noWriteLock.Unlock()
|
|
}},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
v, err := NewVolume(dir, dir, "", 41, NeedleMapInMemory, &super_block.ReplicaPlacement{}, &needle.TTL{}, 0, needle.GetCurrentVersion(), 0, 0)
|
|
if err != nil {
|
|
t.Fatalf("volume creation: %v", err)
|
|
}
|
|
defer v.Close()
|
|
tc.refuse(v)
|
|
|
|
checkErr := v.CheckWritable()
|
|
s := &Store{Locations: []*DiskLocation{{volumes: map[needle.VolumeId]*Volume{v.Id: v}}}}
|
|
_, writeErr := s.WriteVolumeNeedle(v.Id, newRandomNeedle(1), true, false)
|
|
|
|
if !tc.readOnly {
|
|
if checkErr != nil || writeErr != nil {
|
|
t.Fatalf("writable volume: CheckWritable = %v, WriteVolumeNeedle = %v", checkErr, writeErr)
|
|
}
|
|
return
|
|
}
|
|
if !errors.Is(checkErr, ErrorReadOnly) {
|
|
t.Fatalf("CheckWritable = %v, want an error wrapping ErrorReadOnly", checkErr)
|
|
}
|
|
if !errors.Is(writeErr, ErrorReadOnly) || writeErr.Error() != checkErr.Error() {
|
|
t.Fatalf("WriteVolumeNeedle = %v, want the CheckWritable error %v", writeErr, checkErr)
|
|
}
|
|
})
|
|
}
|
|
}
|