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.

68 lines
1.5 KiB

  1. package storage
  2. import (
  3. "fmt"
  4. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  5. "github.com/chrislusf/seaweedfs/weed/storage/super_block"
  6. "io/ioutil"
  7. "os"
  8. "testing"
  9. "time"
  10. )
  11. func TestSearchVolumesWithDeletedNeedles(t *testing.T) {
  12. dir, err := ioutil.TempDir("", "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 := 10
  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<5;i++{
  30. n := newEmptyNeedle(uint64(i))
  31. _, err := v.doDeleteRequest(n)
  32. if err != nil {
  33. t.Fatalf("delete needle %d: %v", i, err)
  34. }
  35. }
  36. ts1 := time.Now().UnixNano()
  37. var ts2 uint64
  38. for i:=5;i<count;i++{
  39. n := newEmptyNeedle(uint64(i))
  40. _, err := v.doDeleteRequest(n)
  41. if err != nil {
  42. t.Fatalf("delete needle %d: %v", i, err)
  43. }
  44. ts2 = n.AppendAtNs
  45. }
  46. offset, isLast, err := v.BinarySearchByAppendAtNs(uint64(ts1))
  47. if err != nil {
  48. t.Fatalf("lookup by ts: %v", err)
  49. }
  50. fmt.Printf("offset: %v, isLast: %v\n", offset.ToActualOffset(), isLast)
  51. offset, isLast, err = v.BinarySearchByAppendAtNs(uint64(ts2))
  52. if err != nil {
  53. t.Fatalf("lookup by ts: %v", err)
  54. }
  55. fmt.Printf("offset: %v, isLast: %v\n", offset.ToActualOffset(), isLast)
  56. }