|
|
|
@ -2,10 +2,13 @@ package store
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/rqlite/rqlite/command"
|
|
|
|
|
"github.com/rqlite/rqlite/command/chunking"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func test_OpenStoreCloseStartup(t *testing.T, s *Store) {
|
|
|
|
@ -276,3 +279,59 @@ func Test_StoreSnapshotStressSingleNode(t *testing.T) {
|
|
|
|
|
defer ln.Close()
|
|
|
|
|
test_SnapshotStress(t, s)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_StoreLoadChunk_Restart(t *testing.T) {
|
|
|
|
|
s, ln := mustNewStore(t)
|
|
|
|
|
defer ln.Close()
|
|
|
|
|
|
|
|
|
|
if err := s.Open(); err != nil {
|
|
|
|
|
t.Fatalf("failed to open single-node store: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
if err := s.Bootstrap(NewServer(s.ID(), s.Addr(), true)); err != nil {
|
|
|
|
|
t.Fatalf("failed to bootstrap single-node store: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
defer s.Close(true)
|
|
|
|
|
if _, err := s.WaitForLeader(10 * time.Second); err != nil {
|
|
|
|
|
t.Fatalf("Error waiting for leader: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Open the SQLite file for loading.
|
|
|
|
|
f, err := os.Open(filepath.Join("testdata", "load.sqlite"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to open SQLite file: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
|
|
numSnapshots := s.numSnapshots
|
|
|
|
|
chunker := chunking.NewChunker(f, 2048)
|
|
|
|
|
for {
|
|
|
|
|
chunk, err := chunker.Next()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to read next chunk: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
err = s.LoadChunk(chunk)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to load chunk: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
if chunk.IsLast {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Chunked loading should trigger a snapshot, so check that the snapshot
|
|
|
|
|
// exists. Check that numSnapshots is 1
|
|
|
|
|
testPoll(t, func() bool {
|
|
|
|
|
s.numSnapshotsMu.Lock()
|
|
|
|
|
defer s.numSnapshotsMu.Unlock()
|
|
|
|
|
return s.numSnapshots == numSnapshots+1
|
|
|
|
|
}, 100*time.Millisecond, 3*time.Second)
|
|
|
|
|
|
|
|
|
|
// Check store can be re-opened.
|
|
|
|
|
if err := s.Close(true); err != nil {
|
|
|
|
|
t.Fatalf("failed to close single-node store: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := s.Open(); err != nil {
|
|
|
|
|
t.Fatalf("failed to open single-node store: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|