Files
seaweedfs/weed/shell/command_volume_tier_upload_test.go
T
5a8e774e36 shell: harden volume.tier.upload for unattended batch runs (#13254)
* shell: harden volume.tier.upload for unattended batch runs

- validate -dest against the master's storage backends before any volume
  is marked read-only, instead of failing per volume after the freeze
- mark replicas read-only with canDelete so TTL expiry keeps draining the
  volume during the upload, and restore writable marks when the upload or
  metadata replication fails partway
- keep going after a per-volume failure in batch mode and report all
  errors at the end
- treat an unset -disk as "any disk"; flag.String never returns nil and
  ToDiskType("") is the hdd type, so the batch silently skipped ssd and
  tagged volumes

Refs #13223

* shell: keep deletes refused while volume.tier.upload copies a volume

A delete accepted during the copy appends a tombstone to the source .dat,
so the attach refuses the upload, and one accepted after a replica's .idx
snapshot is dropped when that replica installs the copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shell: leave replicas that were read-only alone when a tier upload fails

VolumeMarkWritable persists ReadOnly=false, so the rollback cleared an
operator's read-only mark on any replica that was frozen before the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shell: roll back the replica whose read-only mark failed in volume.tier.upload

VolumeMarkReadonly freezes the volume locally before its second master
notification, so an error there leaves the replica read-only although it
never joined the marked list. Also name that replica in the error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shell: let the tiered source accept deletes once every replica has its index

The copies load as tiered volumes that accept deletes, but the source kept
the no-delete mark until its next reload, so a delete applied on a copy
then failed on the source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shell: bound each rollback mark in volume.tier.upload

A stalled VolumeMarkWritable held up the upload error and, in a batch run,
every later volume.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shell: keep replicas frozen when the tier upload attached before failing

A stream that breaks after the volume server attached the remote copy
returns an error, and reopening the other replicas then let them take
writes the remote copy lacks. Ask the source first; a rerun finishes the
upload from its remote copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* shell: bound the final delete mark in volume.tier.upload

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 03:38:02 -08:00

118 lines
4.0 KiB
Go

package shell
import (
"io"
"testing"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
"github.com/seaweedfs/seaweedfs/weed/storage/types"
)
func tierUploadTopo(nodes map[string]*master_pb.VolumeInformationMessage) *master_pb.TopologyInfo {
var dns []*master_pb.DataNodeInfo
for _, id := range []string{"n1", "n2", "n3"} {
vi, found := nodes[id]
if !found {
continue
}
dns = append(dns, &master_pb.DataNodeInfo{
Id: id,
DiskInfos: map[string]*master_pb.DiskInfo{"": {VolumeInfos: []*master_pb.VolumeInformationMessage{vi}}},
})
}
return &master_pb.TopologyInfo{
DataCenterInfos: []*master_pb.DataCenterInfo{{
RackInfos: []*master_pb.RackInfo{{DataNodeInfos: dns}},
}},
}
}
// A replica that is already tiered must become the upload source, so a rerun
// after a partial failure reuses its remote object instead of uploading a
// second copy under a new key.
func TestCollectVolumeTierUploadLocationsPrefersTieredReplica(t *testing.T) {
topo := tierUploadTopo(map[string]*master_pb.VolumeInformationMessage{
"n1": {Id: 1, Collection: "c"},
"n2": {Id: 1, Collection: "c", RemoteStorageName: "s3.default", RemoteStorageKey: "some-key"},
"n3": {Id: 1, Collection: "c"},
})
locations, _ := collectVolumeTierUploadLocations(topo, needle.VolumeId(1), "c", io.Discard)
if len(locations) != 3 {
t.Fatalf("want 3 locations, got %d", len(locations))
}
if locations[0].Url != "n2" {
t.Fatalf("want tiered replica n2 first, got %s", locations[0].Url)
}
}
func TestCollectVolumeTierUploadLocationsFiltersCollection(t *testing.T) {
topo := tierUploadTopo(map[string]*master_pb.VolumeInformationMessage{
"n1": {Id: 1, Collection: "c"},
"n2": {Id: 1, Collection: "other"},
})
if locations, _ := collectVolumeTierUploadLocations(topo, needle.VolumeId(1), "c", io.Discard); len(locations) != 1 || locations[0].Url != "n1" {
t.Fatalf("want only n1, got %+v", locations)
}
}
// A failed upload must not reopen a replica that was read-only before it.
func TestCollectVolumeTierUploadLocationsReportsReadOnly(t *testing.T) {
topo := tierUploadTopo(map[string]*master_pb.VolumeInformationMessage{
"n1": {Id: 1, Collection: "c"},
"n2": {Id: 1, Collection: "c", ReadOnly: true},
})
locations, readOnly := collectVolumeTierUploadLocations(topo, needle.VolumeId(1), "c", io.Discard)
if len(locations) != 2 {
t.Fatalf("want 2 locations, got %d", len(locations))
}
if readOnly["n1"] || !readOnly["n2"] {
t.Fatalf("want only n2 read-only, got %v", readOnly)
}
}
// An unset -disk must not become an hdd-only filter: flag.String always
// returns a non-nil pointer and ToDiskType("") is the hdd type.
func TestTierUploadDiskTypeEmptyMeansAnyDisk(t *testing.T) {
if got := tierUploadDiskType(""); got != nil {
t.Fatalf("want nil disk filter for empty -disk, got %v", *got)
}
}
func TestTierUploadDiskType(t *testing.T) {
for disk, want := range map[string]types.DiskType{
"hdd": types.HardDriveType,
"ssd": types.SsdType,
"nvme": types.NvmeType,
"archive": types.DiskType("archive"),
} {
got := tierUploadDiskType(disk)
if got == nil || *got != want {
t.Fatalf("tierUploadDiskType(%q) = %v, want %q", disk, got, want)
}
}
}
// The destination check must accept exactly the names the volume server can
// resolve: every "type.id" pair plus the bare type alias for id "default".
func TestTierUploadBackendNames(t *testing.T) {
backends := []*master_pb.StorageBackend{
{Type: "s3", Id: "default"},
{Type: "s3", Id: "telegram"},
{Type: "azure", Id: "archive"},
nil,
{Type: "", Id: "broken"},
}
names := tierUploadBackendNames(backends)
for _, want := range []string{"s3.default", "s3", "s3.telegram", "azure.archive"} {
if !names[want] {
t.Fatalf("want backend name %q accepted, got %v", want, names)
}
}
for _, unwanted := range []string{"azure", "s3.", "telegram", "broken.x"} {
if names[unwanted] {
t.Fatalf("backend name %q must not be accepted, got %v", unwanted, names)
}
}
}