volume: find a non-empty offset when binary searching by timestamp

This commit is contained in:
Chris Lu
2021-10-11 22:00:41 -07:00
parent b530f12327
commit 3afa451cdc
2 changed files with 60 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/chrislusf/seaweedfs/weed/storage/needle"
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
"github.com/chrislusf/seaweedfs/weed/storage/types"
"io/ioutil"
"os"
"testing"
@@ -22,7 +23,7 @@ func TestSearchVolumesWithDeletedNeedles(t *testing.T) {
t.Fatalf("volume creation: %v", err)
}
count := 10
count := 20
for i:=1;i<count;i++{
n := newRandomNeedle(uint64(i))
@@ -32,9 +33,9 @@ func TestSearchVolumesWithDeletedNeedles(t *testing.T) {
}
}
for i:=1;i<5;i++{
for i:=1;i<15;i++{
n := newEmptyNeedle(uint64(i))
_, err := v.doDeleteRequest(n)
err := v.nm.Put(n.Id, types.Offset{}, types.TombstoneFileSize)
if err != nil {
t.Fatalf("delete needle %d: %v", i, err)
}
@@ -42,15 +43,12 @@ func TestSearchVolumesWithDeletedNeedles(t *testing.T) {
ts1 := time.Now().UnixNano()
var ts2 uint64
for i:=5;i<count;i++{
for i:=15;i<count;i++{
n := newEmptyNeedle(uint64(i))
_, err := v.doDeleteRequest(n)
if err != nil {
t.Fatalf("delete needle %d: %v", i, err)
}
ts2 = n.AppendAtNs
}
offset, isLast, err := v.BinarySearchByAppendAtNs(uint64(ts1))
@@ -59,11 +57,4 @@ func TestSearchVolumesWithDeletedNeedles(t *testing.T) {
}
fmt.Printf("offset: %v, isLast: %v\n", offset.ToActualOffset(), isLast)
offset, isLast, err = v.BinarySearchByAppendAtNs(uint64(ts2))
if err != nil {
t.Fatalf("lookup by ts: %v", err)
}
fmt.Printf("offset: %v, isLast: %v\n", offset.ToActualOffset(), isLast)
}