put in hack to allow boltdb reader isolation test to pass
in boltdb, long readers *MAY* block a writer. in particular if the write requires additional allocation, it must acquire a lock already held by the reader. in general this is not a problem for bleve (though it can affect performance in some cases), but it is a problem for the reader isolation test. this commit adds a hack to try and avoid the need for additional allocation closes #208
This commit is contained in:
parent
5b8c9f2d73
commit
a52d3b5c07
|
@ -10,6 +10,7 @@
|
||||||
package boltdb
|
package boltdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -150,6 +151,31 @@ func CommonTestReaderIsolation(t *testing.T, s store.KVStore) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// **************************************************
|
||||||
|
// this is a hack to try to pre-emptively overflow
|
||||||
|
// boltdb writes *MAY* block a long reader
|
||||||
|
// in particular, if the write requires additional
|
||||||
|
// allocation, it must acquire the same lock as
|
||||||
|
// the reader, thus cannot continue until that
|
||||||
|
// reader is closed.
|
||||||
|
// in general this is not a problem for bleve
|
||||||
|
// (though it may affect performance in some cases)
|
||||||
|
// but it is a problem for this test which attemps
|
||||||
|
// to easily verify that readers are isolated
|
||||||
|
// this hack writes enough initial data such that
|
||||||
|
// the subsequent writes do not require additional
|
||||||
|
// space
|
||||||
|
hackSize := 1000
|
||||||
|
for i := 0; i < hackSize; i++ {
|
||||||
|
k := fmt.Sprintf("x%d", i)
|
||||||
|
err = writer.Set([]byte(k), []byte("filler"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// **************************************************
|
||||||
|
|
||||||
err = writer.Close()
|
err = writer.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -189,7 +215,7 @@ func CommonTestReaderIsolation(t *testing.T, s store.KVStore) {
|
||||||
it.Next()
|
it.Next()
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
if count != 1 {
|
if count != hackSize+1 {
|
||||||
t.Errorf("expected iterator to see 1, saw %d", count)
|
t.Errorf("expected iterator to see 1, saw %d", count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +265,7 @@ func CommonTestReaderIsolation(t *testing.T, s store.KVStore) {
|
||||||
it2.Next()
|
it2.Next()
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
if count != 2 {
|
if count != hackSize+2 {
|
||||||
t.Errorf("expected iterator to see 2, saw %d", count)
|
t.Errorf("expected iterator to see 2, saw %d", count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +291,7 @@ func CommonTestReaderIsolation(t *testing.T, s store.KVStore) {
|
||||||
it3.Next()
|
it3.Next()
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
if count != 1 {
|
if count != hackSize+1 {
|
||||||
t.Errorf("expected iterator to see 1, saw %d", count)
|
t.Errorf("expected iterator to see 1, saw %d", count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user