inmem_store.go 538 字节
Newer Older
H
Helin Wang 已提交
1 2 3 4 5 6
package master

import "sync"

// InMemStore is an in memory implementation of Store interface.
//
7
// It does not tolerate the fault that causes the program to crash.
H
Helin Wang 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
type InMemStore struct {
	mu  sync.Mutex
	buf []byte
}

// Save saves the state into the in-memory store.
func (m *InMemStore) Save(state []byte) error {
	m.mu.Lock()
	defer m.mu.Unlock()

	m.buf = state
	return nil
}

// Load loads the state from the in-memory store.
func (m *InMemStore) Load() ([]byte, error) {
	m.mu.Lock()
	defer m.mu.Unlock()

	return m.buf, nil
}