2021-10-09 11:54:14 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2021-10-14 04:27:58 +00:00
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
2021-10-09 11:54:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSearchVolumesWithDeletedNeedles(t *testing.T) {
|
2021-10-14 04:27:58 +00:00
|
|
|
dir, err := os.MkdirTemp("", "example")
|
2021-10-09 11:54:14 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("temp dir creation: %v", err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(dir) // clean up
|
|
|
|
|
|
|
|
v, err := NewVolume(dir, dir, "", 1, NeedleMapInMemory, &super_block.ReplicaPlacement{}, &needle.TTL{}, 0, 0)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("volume creation: %v", err)
|
|
|
|
}
|
|
|
|
|
2021-10-12 05:00:41 +00:00
|
|
|
count := 20
|
2021-10-09 11:54:14 +00:00
|
|
|
|
2021-10-12 06:23:46 +00:00
|
|
|
for i := 1; i < count; i++ {
|
2021-10-09 11:54:14 +00:00
|
|
|
n := newRandomNeedle(uint64(i))
|
|
|
|
_, _, _, err := v.writeNeedle2(n, true, false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("write needle %d: %v", i, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-12 06:23:46 +00:00
|
|
|
for i := 1; i < 15; i++ {
|
2021-10-09 11:54:14 +00:00
|
|
|
n := newEmptyNeedle(uint64(i))
|
2021-10-12 05:00:41 +00:00
|
|
|
err := v.nm.Put(n.Id, types.Offset{}, types.TombstoneFileSize)
|
2021-10-09 11:54:14 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("delete needle %d: %v", i, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ts1 := time.Now().UnixNano()
|
|
|
|
|
2021-10-12 06:23:46 +00:00
|
|
|
for i := 15; i < count; i++ {
|
2021-10-09 11:54:14 +00:00
|
|
|
n := newEmptyNeedle(uint64(i))
|
|
|
|
_, err := v.doDeleteRequest(n)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("delete needle %d: %v", i, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
offset, isLast, err := v.BinarySearchByAppendAtNs(uint64(ts1))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("lookup by ts: %v", err)
|
|
|
|
}
|
|
|
|
fmt.Printf("offset: %v, isLast: %v\n", offset.ToActualOffset(), isLast)
|
|
|
|
|
2021-10-12 06:23:46 +00:00
|
|
|
}
|