You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.3 KiB

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