|
| 1 | +// Copyright (c) 2026 Feng Ruohang |
| 2 | +// |
| 3 | +// This file is part of Silo Object Storage stack |
| 4 | +// |
| 5 | +// This program is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU Affero General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// This program is distributed in the hope that it will be useful |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU Affero General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU Affero General Public License |
| 16 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +package cmd |
| 19 | + |
| 20 | +import ( |
| 21 | + "fmt" |
| 22 | + "testing" |
| 23 | + "time" |
| 24 | +) |
| 25 | + |
| 26 | +// Both walkers must preserve markers even when all older versions reside in |
| 27 | +// another pool. Local version counts cannot prove that a marker is redundant. |
| 28 | +func TestPoolsMigrationDeleteMarkers(t *testing.T) { |
| 29 | + for _, kind := range []string{"rebalance", "decommission"} { |
| 30 | + for _, pools := range []int{2, 3} { |
| 31 | + for _, null := range []bool{false, true} { |
| 32 | + for _, history := range []string{"none", "source", "destination"} { |
| 33 | + t.Run(fmt.Sprintf("%s/pools=%d/null=%t/history=%s", kind, pools, null, history), func(t *testing.T) { |
| 34 | + var z *erasureServerPools |
| 35 | + var bucket string |
| 36 | + if pools == 2 { |
| 37 | + z, bucket = migrationTestPools(t) |
| 38 | + } else { |
| 39 | + z, bucket = migrationTestThreePools(t) |
| 40 | + } |
| 41 | + const object = "deleted" |
| 42 | + old, stamp := UTCNow().Add(-time.Hour), UTCNow().Add(-time.Minute) |
| 43 | + var prior ObjectInfo |
| 44 | + if history != "none" { |
| 45 | + pool := 0 |
| 46 | + if history == "destination" { |
| 47 | + pool = 1 |
| 48 | + } |
| 49 | + prior = putConsistencyObject(t, z, bucket, object, pool, "history", ObjectOptions{Versioned: true, MTime: old}) |
| 50 | + } |
| 51 | + // A stale null copy is a normal consequence of cross-pool overwrites. |
| 52 | + putConsistencyObject(t, z, bucket, object, 1, "stale", ObjectOptions{MTime: old}) |
| 53 | + vid := mustGetUUID() |
| 54 | + if null { |
| 55 | + vid = nullVersionID |
| 56 | + } |
| 57 | + opts := ObjectOptions{Versioned: true, VersionID: vid, DeleteMarker: true, MTime: stamp} |
| 58 | + marker, err := z.serverPools[0].DeleteObject(t.Context(), bucket, object, opts) |
| 59 | + mustIAM(t, err) |
| 60 | + if !marker.DeleteMarker { |
| 61 | + t.Fatal("fixture did not create marker") |
| 62 | + } |
| 63 | + if oi, err := z.GetObjectInfo(t.Context(), bucket, object, ObjectOptions{}); !isErrObjectNotFound(err) || !oi.DeleteMarker { |
| 64 | + t.Fatalf("fixture visible: %+v %v", oi, err) |
| 65 | + } |
| 66 | + if failed := migrationTestWalk(t, z, bucket, 0, kind); failed != 0 { |
| 67 | + t.Fatalf("failed moves: %d", failed) |
| 68 | + } |
| 69 | + for attempt := 0; attempt < 2; attempt++ { |
| 70 | + if oi, err := z.GetObjectInfo(t.Context(), bucket, object, ObjectOptions{}); !isErrObjectNotFound(err) || !oi.DeleteMarker || !oi.ModTime.Equal(stamp) { |
| 71 | + t.Fatalf("marker lost: %+v %v", oi, err) |
| 72 | + } |
| 73 | + if _, err := z.serverPools[0].GetObjectInfo(t.Context(), bucket, object, ObjectOptions{VersionID: migrationTestVersion(marker)}); !isErrObjectNotFound(err) && !isErrVersionNotFound(err) { |
| 74 | + t.Fatalf("source marker retained: %v", err) |
| 75 | + } |
| 76 | + if prior.VersionID != "" && migrationTestBody(t, z.GetObjectNInfo, bucket, object, prior.VersionID) != "history" { |
| 77 | + t.Fatal("lost historical version") |
| 78 | + } |
| 79 | + // Repeating a completed walk must preserve the same state. |
| 80 | + migrationTestWalk(t, z, bucket, 0, kind) |
| 81 | + } |
| 82 | + }) |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +// A reader opened before a public purge must not recreate the purged version. |
| 90 | +func TestPoolsMigrationDoesNotResurrectPurgedSource(t *testing.T) { |
| 91 | + for _, kind := range []string{"rebalance", "decommission"} { |
| 92 | + for _, multipart := range []bool{false, true} { |
| 93 | + t.Run(fmt.Sprintf("%s/multipart=%t", kind, multipart), func(t *testing.T) { |
| 94 | + z, bucket := migrationTestPools(t) |
| 95 | + move := migrationTestMover(t, z, 0, kind) |
| 96 | + oi := migrationTestObject(t, z, bucket, "purged", 0, multipart, []string{"payload"}, ObjectOptions{Versioned: true}) |
| 97 | + gr := migrationTestReader(t, z, 0, oi) |
| 98 | + _, err := z.DeleteObject(t.Context(), bucket, oi.Name, ObjectOptions{VersionID: oi.VersionID, Versioned: true}) |
| 99 | + mustIAM(t, err) |
| 100 | + err = move(t.Context(), 0, bucket, gr) |
| 101 | + if err == nil { |
| 102 | + t.Error("move accepted a purged source") |
| 103 | + } |
| 104 | + if oi, err := z.GetObjectInfo(t.Context(), bucket, oi.Name, ObjectOptions{}); !isErrObjectNotFound(err) { |
| 105 | + t.Fatalf("purged version resurrected: %+v %v", oi, err) |
| 106 | + } |
| 107 | + }) |
| 108 | + } |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +// Cleanup must not erase a marker created after the data was copied. It must |
| 113 | +// also fail closed if the destination becomes unreadable before source removal. |
| 114 | +func TestPoolsMigrationCleanupRechecksSource(t *testing.T) { |
| 115 | + for _, change := range []string{"delete-null", "delete-uuid", "unreadable-destination", "missing-destination"} { |
| 116 | + t.Run(change, func(t *testing.T) { |
| 117 | + z, bucket := migrationTestPools(t) |
| 118 | + move := migrationTestMover(t, z, 0, "decommission") |
| 119 | + oi := migrationTestObject(t, z, bucket, "cleanup", 0, false, []string{"payload"}, ObjectOptions{}) |
| 120 | + snapshot := []FileInfo{{VersionID: oi.VersionID, ModTime: oi.ModTime}} |
| 121 | + mustIAM(t, move(t.Context(), 0, bucket, migrationTestReader(t, z, 0, oi))) |
| 122 | + switch change { |
| 123 | + case "delete-null", "delete-uuid": |
| 124 | + _, err := z.DeleteObject(t.Context(), bucket, oi.Name, ObjectOptions{VersionSuspended: change == "delete-null", Versioned: change == "delete-uuid"}) |
| 125 | + mustIAM(t, err) |
| 126 | + case "unreadable-destination": |
| 127 | + restore := conditionalPutSwapDisks(z.serverPools[1], oi.Name, func(d StorageAPI) StorageAPI { |
| 128 | + return consistencyReadFaultDisk{StorageAPI: d, bucket: bucket, object: oi.Name} |
| 129 | + }) |
| 130 | + defer restore() |
| 131 | + case "missing-destination": |
| 132 | + _, err := z.serverPools[1].DeleteObject(t.Context(), bucket, oi.Name, ObjectOptions{VersionID: nullVersionID}) |
| 133 | + mustIAM(t, err) |
| 134 | + } |
| 135 | + err := z.removeMovedVersions(t.Context(), bucket, oi.Name, 0, snapshot) |
| 136 | + if change != "delete-uuid" && err == nil { |
| 137 | + t.Fatal("cleanup accepted changed or uncertain state") |
| 138 | + } |
| 139 | + if change == "delete-null" || change == "delete-uuid" { |
| 140 | + if got, err := z.GetObjectInfo(t.Context(), bucket, oi.Name, ObjectOptions{}); !isErrObjectNotFound(err) || !got.DeleteMarker { |
| 141 | + t.Fatalf("cleanup resurrected data: %v", err) |
| 142 | + } |
| 143 | + } else if _, err := z.serverPools[0].GetObjectInfo(t.Context(), bucket, oi.Name, ObjectOptions{}); err != nil { |
| 144 | + t.Fatalf("cleanup lost source: %v", err) |
| 145 | + } |
| 146 | + }) |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | +func TestPoolsMigrationConflictingTimestampTie(t *testing.T) { |
| 151 | + for _, kind := range []string{"rebalance", "decommission"} { |
| 152 | + for source := range 2 { |
| 153 | + t.Run(fmt.Sprintf("%s/source=%d", kind, source), func(t *testing.T) { |
| 154 | + z, bucket := migrationTestPools(t) |
| 155 | + stamp := UTCNow().Add(-time.Minute) |
| 156 | + for i := range 2 { |
| 157 | + putConsistencyObject(t, z, bucket, "tie", i, fmt.Sprintf("pool-%d", i), ObjectOptions{MTime: stamp}) |
| 158 | + } |
| 159 | + if got := migrationTestBody(t, z.GetObjectNInfo, bucket, "tie", ""); got != "pool-0" { |
| 160 | + t.Fatalf("fixture winner: %s", got) |
| 161 | + } |
| 162 | + migrationTestWalk(t, z, bucket, source, kind) |
| 163 | + if got := migrationTestBody(t, z.GetObjectNInfo, bucket, "tie", ""); got != "pool-0" { |
| 164 | + t.Fatalf("changed tie winner: %s", got) |
| 165 | + } |
| 166 | + }) |
| 167 | + } |
| 168 | + } |
| 169 | +} |
0 commit comments