volume_write_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package storage
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  7. "github.com/chrislusf/seaweedfs/weed/storage/super_block"
  8. "github.com/chrislusf/seaweedfs/weed/storage/types"
  9. )
  10. func TestSearchVolumesWithDeletedNeedles(t *testing.T) {
  11. dir := t.TempDir()
  12. v, err := NewVolume(dir, dir, "", 1, NeedleMapInMemory, &super_block.ReplicaPlacement{}, &needle.TTL{}, 0, 0)
  13. if err != nil {
  14. t.Fatalf("volume creation: %v", err)
  15. }
  16. count := 20
  17. for i := 1; i < count; i++ {
  18. n := newRandomNeedle(uint64(i))
  19. _, _, _, err := v.writeNeedle2(n, true, false)
  20. if err != nil {
  21. t.Fatalf("write needle %d: %v", i, err)
  22. }
  23. }
  24. for i := 1; i < 15; i++ {
  25. n := newEmptyNeedle(uint64(i))
  26. err := v.nm.Put(n.Id, types.Offset{}, types.TombstoneFileSize)
  27. if err != nil {
  28. t.Fatalf("delete needle %d: %v", i, err)
  29. }
  30. }
  31. ts1 := time.Now().UnixNano()
  32. for i := 15; i < count; i++ {
  33. n := newEmptyNeedle(uint64(i))
  34. _, err := v.doDeleteRequest(n)
  35. if err != nil {
  36. t.Fatalf("delete needle %d: %v", i, err)
  37. }
  38. }
  39. offset, isLast, err := v.BinarySearchByAppendAtNs(uint64(ts1))
  40. if err != nil {
  41. t.Fatalf("lookup by ts: %v", err)
  42. }
  43. fmt.Printf("offset: %v, isLast: %v\n", offset.ToActualOffset(), isLast)
  44. }