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.4 KiB

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