|
1 | 1 | package meta
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "bytes" |
4 | 5 | "context"
|
5 | 6 | "fmt"
|
6 | 7 | "math/big"
|
@@ -41,6 +42,7 @@ func TestObjectExpiration(t *testing.T) {
|
41 | 42 | var oo []object.Object
|
42 | 43 | for i := range objNum {
|
43 | 44 | o := objecttest.Object()
|
| 45 | + o.ResetRelations() |
44 | 46 | o.SetContainerID(cID)
|
45 | 47 | setExpiration(&o, uint64(i))
|
46 | 48 |
|
@@ -99,9 +101,11 @@ func TestObjectExpiration(t *testing.T) {
|
99 | 101 |
|
100 | 102 | o := objecttest.Object()
|
101 | 103 | oID := o.GetID()
|
| 104 | + o.ResetRelations() |
102 | 105 | o.SetContainerID(cID)
|
103 | 106 | setExpiration(&o, objExp)
|
104 | 107 | lock := objecttest.Object()
|
| 108 | + lock.ResetRelations() |
105 | 109 | lock.SetContainerID(cID)
|
106 | 110 | setExpiration(&lock, lockExp)
|
107 | 111 |
|
@@ -153,3 +157,141 @@ func TestObjectExpiration(t *testing.T) {
|
153 | 157 | })
|
154 | 158 | })
|
155 | 159 | }
|
| 160 | + |
| 161 | +func objectChain(cID cid.ID, length int) (object.Object, []object.Object) { |
| 162 | + reset := func(o *object.Object) { |
| 163 | + o.SetContainerID(cID) |
| 164 | + o.ResetRelations() |
| 165 | + o.SetType(object.TypeRegular) |
| 166 | + } |
| 167 | + |
| 168 | + root := objecttest.Object() |
| 169 | + reset(&root) |
| 170 | + first := objecttest.Object() |
| 171 | + reset(&first) |
| 172 | + |
| 173 | + children := make([]object.Object, length-1) |
| 174 | + children[0] = first |
| 175 | + for i := range children { |
| 176 | + if i != 0 { |
| 177 | + children[i] = objecttest.Object() |
| 178 | + reset(&children[i]) |
| 179 | + children[i].SetFirstID(first.GetID()) |
| 180 | + children[i].SetPreviousID(children[i-1].GetID()) |
| 181 | + } |
| 182 | + if i == len(children)-1 { |
| 183 | + children[i].SetParentID(root.GetID()) |
| 184 | + children[i].SetParent(&root) |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + link := objecttest.Object() |
| 189 | + reset(&link) |
| 190 | + link.SetFirstID(first.GetID()) |
| 191 | + link.SetParentID(root.GetID()) |
| 192 | + link.SetParent(&root) |
| 193 | + link.SetType(object.TypeLink) |
| 194 | + |
| 195 | + return root, append(children, link) |
| 196 | +} |
| 197 | + |
| 198 | +type bigObj struct { |
| 199 | + root object.Object |
| 200 | + children []object.Object |
| 201 | +} |
| 202 | + |
| 203 | +func TestBigObjects(t *testing.T) { |
| 204 | + cID := cidtest.ID() |
| 205 | + l := zaptest.NewLogger(t) |
| 206 | + ctx := context.Background() |
| 207 | + |
| 208 | + var bigObjs []bigObj |
| 209 | + for range 10 { |
| 210 | + root, children := objectChain(cID, 10) |
| 211 | + bigObjs = append(bigObjs, bigObj{root, children}) |
| 212 | + } |
| 213 | + |
| 214 | + var rawObjSlice []object.Object |
| 215 | + for _, obj := range bigObjs { |
| 216 | + rawObjSlice = append(rawObjSlice, obj.children...) |
| 217 | + } |
| 218 | + |
| 219 | + net := testNetwork{} |
| 220 | + net.setContainers([]cid.ID{cID}) |
| 221 | + net.setObjects(objsToAddrMap(rawObjSlice)) |
| 222 | + ee := make([]objEvent, 0, len(rawObjSlice)) |
| 223 | + for _, o := range rawObjSlice { |
| 224 | + ev := objEvent{ |
| 225 | + cID: cID, |
| 226 | + oID: o.GetID(), |
| 227 | + size: big.NewInt(testObjectSize), |
| 228 | + network: big.NewInt(testNetworkMagic), |
| 229 | + } |
| 230 | + ev.typ = o.Type() |
| 231 | + if id := o.GetPreviousID(); !id.IsZero() { |
| 232 | + ev.prevObject = id[:] |
| 233 | + } |
| 234 | + if id := o.GetFirstID(); !id.IsZero() { |
| 235 | + ev.firstObject = id[:] |
| 236 | + } |
| 237 | + |
| 238 | + ee = append(ee, ev) |
| 239 | + } |
| 240 | + |
| 241 | + st, err := storageForContainer(t.TempDir(), cID) |
| 242 | + require.NoError(t, err) |
| 243 | + t.Cleanup(func() { |
| 244 | + _ = st.drop() |
| 245 | + }) |
| 246 | + |
| 247 | + st.putObjects(ctx, l, 0, ee, &net) |
| 248 | + |
| 249 | + tsObj := objecttest.Object() |
| 250 | + tsObj.ResetRelations() |
| 251 | + tsObj.SetContainerID(cID) |
| 252 | + tsObj.SetType(object.TypeTombstone) |
| 253 | + tsEv := objEvent{ |
| 254 | + cID: cID, |
| 255 | + oID: tsObj.GetID(), |
| 256 | + size: big.NewInt(testObjectSize), |
| 257 | + network: big.NewInt(testNetworkMagic), |
| 258 | + } |
| 259 | + net.setObjects(objsToAddrMap([]object.Object{tsObj})) |
| 260 | + |
| 261 | + for _, bigO := range bigObjs { |
| 262 | + rID := bigO.root.GetID() |
| 263 | + tsEv.deletedObjects = rID[:] |
| 264 | + |
| 265 | + st.putObjects(ctx, l, 0, []objEvent{tsEv}, &net) |
| 266 | + |
| 267 | + k := make([]byte, 1+oid.Size) |
| 268 | + k[0] = oidIndex |
| 269 | + |
| 270 | + for _, child := range bigO.children { |
| 271 | + chID := child.GetID() |
| 272 | + copy(k[1:], chID[:]) |
| 273 | + |
| 274 | + _, err = st.db.Get(k) |
| 275 | + require.ErrorIs(t, err, storage.ErrKeyNotFound) |
| 276 | + } |
| 277 | + } |
| 278 | + |
| 279 | + // only last operation from TS should be kept |
| 280 | + tsID := tsObj.GetID() |
| 281 | + st.db.Seek(storage.SeekRange{}, func(k, _ []byte) bool { |
| 282 | + switch k[0] { |
| 283 | + case oidIndex, oidToAttrIndex, deletedIndex: |
| 284 | + if bytes.Equal(k[1:1+oid.Size], tsID[:]) { |
| 285 | + return true |
| 286 | + } |
| 287 | + case attrIntToOIDIndex, attrPlainToOIDIndex: |
| 288 | + if bytes.Equal(k[len(k)-oid.Size:], tsID[:]) { |
| 289 | + return true |
| 290 | + } |
| 291 | + default: |
| 292 | + } |
| 293 | + |
| 294 | + t.Fatalf("empty db is expected after full clean, found key: %d", k[0]) |
| 295 | + return true |
| 296 | + }) |
| 297 | +} |
0 commit comments