1
0
Fork 0

Sync queries and restores

master
Philip O'Toole 4 years ago
parent 0f1352fb01
commit ef1f0f1d57

@ -124,7 +124,8 @@ type Store struct {
raftStable raft.StableStore // Persistent k-v store. raftStable raft.StableStore // Persistent k-v store.
boltStore *raftboltdb.BoltStore // Physical store. boltStore *raftboltdb.BoltStore // Physical store.
txMu sync.RWMutex // Sync between snapshots and query transactions. txMu sync.RWMutex // Sync between snapshots and query-level transactions.
queryMu sync.RWMutex // Sync queries generally with other operations.
metaMu sync.RWMutex metaMu sync.RWMutex
meta map[string]map[string]string meta map[string]map[string]string
@ -565,6 +566,9 @@ func (s *Store) Backup(leader bool, fmt BackupFormat, dst io.Writer) error {
// Query executes queries that return rows, and do not modify the database. // Query executes queries that return rows, and do not modify the database.
func (s *Store) Query(qr *command.QueryRequest) ([]*sql.Rows, error) { func (s *Store) Query(qr *command.QueryRequest) ([]*sql.Rows, error) {
s.queryMu.RLock()
defer s.queryMu.RUnlock()
if qr.Level == command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG { if qr.Level == command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG {
b, compressed, err := s.reqMarshaller.Marshal(qr) b, compressed, err := s.reqMarshaller.Marshal(qr)
if err != nil { if err != nil {
@ -974,10 +978,11 @@ func (s *Store) Snapshot() (raft.FSMSnapshot, error) {
// Restore restores the node to a previous state. The Hashicorp docs state this // Restore restores the node to a previous state. The Hashicorp docs state this
// will not be called concurrently with Apply(), so synchronization with Execute() // will not be called concurrently with Apply(), so synchronization with Execute()
// is not necessary. To be safe, this function does block query transactions. // is not necessary.To prevent problems during queries, which may not go through
// the log, it blocks all query requests.
func (s *Store) Restore(rc io.ReadCloser) error { func (s *Store) Restore(rc io.ReadCloser) error {
s.txMu.Lock() s.queryMu.Lock()
defer s.txMu.Unlock() defer s.queryMu.Unlock()
var uint64Size uint64 var uint64Size uint64
inc := int64(unsafe.Sizeof(uint64Size)) inc := int64(unsafe.Sizeof(uint64Size))

Loading…
Cancel
Save