|
|
|
@ -56,7 +56,7 @@ func TestFreezerBasics(t *testing.T) { |
|
|
|
|
// set cutoff at 50 bytes
|
|
|
|
|
f, err := newCustomTable(os.TempDir(), |
|
|
|
|
fmt.Sprintf("unittest-%d", rand.Uint64()), |
|
|
|
|
metrics.NewMeter(), metrics.NewMeter(), metrics.NewCounter(), 50, true) |
|
|
|
|
metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge(), 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -99,11 +99,11 @@ func TestFreezerBasicsClosing(t *testing.T) { |
|
|
|
|
// set cutoff at 50 bytes
|
|
|
|
|
var ( |
|
|
|
|
fname = fmt.Sprintf("basics-close-%d", rand.Uint64()) |
|
|
|
|
rm, wm, sc = metrics.NewMeter(), metrics.NewMeter(), metrics.NewCounter() |
|
|
|
|
rm, wm, sg = metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge() |
|
|
|
|
f *freezerTable |
|
|
|
|
err error |
|
|
|
|
) |
|
|
|
|
f, err = newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err = newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -112,7 +112,7 @@ func TestFreezerBasicsClosing(t *testing.T) { |
|
|
|
|
data := getChunk(15, x) |
|
|
|
|
f.Append(uint64(x), data) |
|
|
|
|
f.Close() |
|
|
|
|
f, err = newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err = newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -129,7 +129,7 @@ func TestFreezerBasicsClosing(t *testing.T) { |
|
|
|
|
t.Fatalf("test %d, got \n%x != \n%x", y, got, exp) |
|
|
|
|
} |
|
|
|
|
f.Close() |
|
|
|
|
f, err = newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err = newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -139,11 +139,11 @@ func TestFreezerBasicsClosing(t *testing.T) { |
|
|
|
|
// TestFreezerRepairDanglingHead tests that we can recover if index entries are removed
|
|
|
|
|
func TestFreezerRepairDanglingHead(t *testing.T) { |
|
|
|
|
t.Parallel() |
|
|
|
|
rm, wm, sc := metrics.NewMeter(), metrics.NewMeter(), metrics.NewCounter() |
|
|
|
|
rm, wm, sg := metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge() |
|
|
|
|
fname := fmt.Sprintf("dangling_headtest-%d", rand.Uint64()) |
|
|
|
|
|
|
|
|
|
{ // Fill table
|
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -172,7 +172,7 @@ func TestFreezerRepairDanglingHead(t *testing.T) { |
|
|
|
|
idxFile.Close() |
|
|
|
|
// Now open it again
|
|
|
|
|
{ |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -190,11 +190,11 @@ func TestFreezerRepairDanglingHead(t *testing.T) { |
|
|
|
|
// TestFreezerRepairDanglingHeadLarge tests that we can recover if very many index entries are removed
|
|
|
|
|
func TestFreezerRepairDanglingHeadLarge(t *testing.T) { |
|
|
|
|
t.Parallel() |
|
|
|
|
rm, wm, sc := metrics.NewMeter(), metrics.NewMeter(), metrics.NewCounter() |
|
|
|
|
rm, wm, sg := metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge() |
|
|
|
|
fname := fmt.Sprintf("dangling_headtest-%d", rand.Uint64()) |
|
|
|
|
|
|
|
|
|
{ // Fill a table and close it
|
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -222,7 +222,7 @@ func TestFreezerRepairDanglingHeadLarge(t *testing.T) { |
|
|
|
|
idxFile.Close() |
|
|
|
|
// Now open it again
|
|
|
|
|
{ |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -243,7 +243,7 @@ func TestFreezerRepairDanglingHeadLarge(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
// And if we open it, we should now be able to read all of them (new values)
|
|
|
|
|
{ |
|
|
|
|
f, _ := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, _ := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
for y := 1; y < 255; y++ { |
|
|
|
|
exp := getChunk(15, ^y) |
|
|
|
|
got, err := f.Retrieve(uint64(y)) |
|
|
|
@ -260,11 +260,11 @@ func TestFreezerRepairDanglingHeadLarge(t *testing.T) { |
|
|
|
|
// TestSnappyDetection tests that we fail to open a snappy database and vice versa
|
|
|
|
|
func TestSnappyDetection(t *testing.T) { |
|
|
|
|
t.Parallel() |
|
|
|
|
rm, wm, sc := metrics.NewMeter(), metrics.NewMeter(), metrics.NewCounter() |
|
|
|
|
rm, wm, sg := metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge() |
|
|
|
|
fname := fmt.Sprintf("snappytest-%d", rand.Uint64()) |
|
|
|
|
// Open with snappy
|
|
|
|
|
{ |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -277,7 +277,7 @@ func TestSnappyDetection(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
// Open without snappy
|
|
|
|
|
{ |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, false) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, false) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -289,7 +289,7 @@ func TestSnappyDetection(t *testing.T) { |
|
|
|
|
|
|
|
|
|
// Open with snappy
|
|
|
|
|
{ |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -317,11 +317,11 @@ func assertFileSize(f string, size int64) error { |
|
|
|
|
// the index is repaired
|
|
|
|
|
func TestFreezerRepairDanglingIndex(t *testing.T) { |
|
|
|
|
t.Parallel() |
|
|
|
|
rm, wm, sc := metrics.NewMeter(), metrics.NewMeter(), metrics.NewCounter() |
|
|
|
|
rm, wm, sg := metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge() |
|
|
|
|
fname := fmt.Sprintf("dangling_indextest-%d", rand.Uint64()) |
|
|
|
|
|
|
|
|
|
{ // Fill a table and close it
|
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -357,7 +357,7 @@ func TestFreezerRepairDanglingIndex(t *testing.T) { |
|
|
|
|
// 45, 45, 15
|
|
|
|
|
// with 3+3+1 items
|
|
|
|
|
{ |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -374,11 +374,11 @@ func TestFreezerRepairDanglingIndex(t *testing.T) { |
|
|
|
|
func TestFreezerTruncate(t *testing.T) { |
|
|
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
|
rm, wm, sc := metrics.NewMeter(), metrics.NewMeter(), metrics.NewCounter() |
|
|
|
|
rm, wm, sg := metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge() |
|
|
|
|
fname := fmt.Sprintf("truncation-%d", rand.Uint64()) |
|
|
|
|
|
|
|
|
|
{ // Fill table
|
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -395,7 +395,7 @@ func TestFreezerTruncate(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
// Reopen, truncate
|
|
|
|
|
{ |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -417,10 +417,10 @@ func TestFreezerTruncate(t *testing.T) { |
|
|
|
|
// That will rewind the index, and _should_ truncate the head file
|
|
|
|
|
func TestFreezerRepairFirstFile(t *testing.T) { |
|
|
|
|
t.Parallel() |
|
|
|
|
rm, wm, sc := metrics.NewMeter(), metrics.NewMeter(), metrics.NewCounter() |
|
|
|
|
rm, wm, sg := metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge() |
|
|
|
|
fname := fmt.Sprintf("truncationfirst-%d", rand.Uint64()) |
|
|
|
|
{ // Fill table
|
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -448,7 +448,7 @@ func TestFreezerRepairFirstFile(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
// Reopen
|
|
|
|
|
{ |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -473,10 +473,10 @@ func TestFreezerRepairFirstFile(t *testing.T) { |
|
|
|
|
// - check that we did not keep the rdonly file descriptors
|
|
|
|
|
func TestFreezerReadAndTruncate(t *testing.T) { |
|
|
|
|
t.Parallel() |
|
|
|
|
rm, wm, sc := metrics.NewMeter(), metrics.NewMeter(), metrics.NewCounter() |
|
|
|
|
rm, wm, sg := metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge() |
|
|
|
|
fname := fmt.Sprintf("read_truncate-%d", rand.Uint64()) |
|
|
|
|
{ // Fill table
|
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -493,7 +493,7 @@ func TestFreezerReadAndTruncate(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
// Reopen and read all files
|
|
|
|
|
{ |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 50, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 50, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -519,10 +519,10 @@ func TestFreezerReadAndTruncate(t *testing.T) { |
|
|
|
|
|
|
|
|
|
func TestOffset(t *testing.T) { |
|
|
|
|
t.Parallel() |
|
|
|
|
rm, wm, sc := metrics.NewMeter(), metrics.NewMeter(), metrics.NewCounter() |
|
|
|
|
rm, wm, sg := metrics.NewMeter(), metrics.NewMeter(), metrics.NewGauge() |
|
|
|
|
fname := fmt.Sprintf("offset-%d", rand.Uint64()) |
|
|
|
|
{ // Fill table
|
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 40, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 40, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
@ -578,7 +578,7 @@ func TestOffset(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
// Now open again
|
|
|
|
|
{ |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sc, 40, true) |
|
|
|
|
f, err := newCustomTable(os.TempDir(), fname, rm, wm, sg, 40, true) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal(err) |
|
|
|
|
} |
|
|
|
|