(t *testing.T)
| 382 | } |
| 383 | |
| 384 | func TestReindex(t *testing.T) { |
| 385 | if testing.Short() { |
| 386 | t.Skip("skipping in short mode") |
| 387 | } |
| 388 | |
| 389 | type file struct { |
| 390 | size int64 |
| 391 | name string |
| 392 | contents []byte |
| 393 | } |
| 394 | files := []file{ |
| 395 | {17 << 20, "foo.dat", randBytesSrc(17<<20, 42)}, |
| 396 | {10 << 20, "bar.dat", randBytesSrc(10<<20, 43)}, |
| 397 | {5 << 20, "baz.dat", randBytesSrc(5<<20, 44)}, |
| 398 | } |
| 399 | |
| 400 | pt := testPack(t, |
| 401 | func(sto blobserver.Storage) error { |
| 402 | for _, f := range files { |
| 403 | if _, err := schema.WriteFileFromReader(ctxbg, sto, f.name, bytes.NewReader(f.contents)); err != nil { |
| 404 | return err |
| 405 | } |
| 406 | } |
| 407 | return nil |
| 408 | }, |
| 409 | wantNumLargeBlobs(4), |
| 410 | wantNumSmallBlobs(0), |
| 411 | ) |
| 412 | |
| 413 | // backup the meta that is supposed to be lost/erased. |
| 414 | // pt.sto.reindex allocates a new pt.sto.meta, so meta != pt.sto.meta after it is called. |
| 415 | meta := pt.sto.meta |
| 416 | |
| 417 | // and build new meta index |
| 418 | if err := pt.sto.reindex(context.TODO(), func() (sorted.KeyValue, error) { |
| 419 | return sorted.NewMemoryKeyValue(), nil |
| 420 | }); err != nil { |
| 421 | t.Fatal(err) |
| 422 | } |
| 423 | |
| 424 | validBlobKey := func(key, value string) error { |
| 425 | if !strings.HasPrefix(key, "b:") { |
| 426 | return errors.New("not a blob meta key") |
| 427 | } |
| 428 | wantRef, ok := blob.Parse(key[2:]) |
| 429 | if !ok { |
| 430 | return errors.New("bogus blobref in key") |
| 431 | } |
| 432 | m, err := parseMetaRow([]byte(value)) |
| 433 | if err != nil { |
| 434 | return err |
| 435 | } |
| 436 | rc, err := pt.large.SubFetch(ctxbg, m.largeRef, int64(m.largeOff), int64(m.size)) |
| 437 | if err != nil { |
| 438 | return err |
| 439 | } |
| 440 | defer rc.Close() |
| 441 | h := wantRef.Hash() |
nothing calls this directly
no test coverage detected