mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-05 16:06:57 +08:00
Check for nil rw object in LogStore before attemting a sync
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -113,6 +113,12 @@ func NewAOFEngine(options ...func(engine *Engine)) *Engine {
|
||||
handleCommand: func(command []byte) {},
|
||||
}
|
||||
|
||||
// Setup AOFEngine options first as these options are used
|
||||
// when setting up the PreambleStore and AppendStore
|
||||
for _, option := range options {
|
||||
option(engine)
|
||||
}
|
||||
|
||||
// Setup Preamble engine
|
||||
engine.preambleStore = preamble.NewPreambleStore(
|
||||
preamble.WithDirectory(engine.directory),
|
||||
@@ -129,10 +135,6 @@ func NewAOFEngine(options ...func(engine *Engine)) *Engine {
|
||||
logstore.WithHandleCommandFunc(engine.handleCommand),
|
||||
)
|
||||
|
||||
for _, option := range options {
|
||||
option(engine)
|
||||
}
|
||||
|
||||
// 3. Start the goroutine to pick up queued commands in order to write them to the file.
|
||||
// LogCommand will get the open file handler from the struct top perform the AOF operation.
|
||||
go func() {
|
||||
|
@@ -73,9 +73,7 @@ func NewAppendStore(options ...func(store *AppendStore)) *AppendStore {
|
||||
strategy: "everysec",
|
||||
rw: nil,
|
||||
mut: sync.Mutex{},
|
||||
handleCommand: func(command []byte) {
|
||||
// No-Op
|
||||
},
|
||||
handleCommand: func(command []byte) {},
|
||||
}
|
||||
|
||||
for _, option := range options {
|
||||
@@ -130,8 +128,11 @@ func (store *AppendStore) Write(command []byte) error {
|
||||
|
||||
func (store *AppendStore) Sync() error {
|
||||
store.mut.Lock()
|
||||
store.mut.Unlock()
|
||||
defer store.mut.Unlock()
|
||||
if store.rw != nil {
|
||||
return store.rw.Sync()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (store *AppendStore) Restore() error {
|
||||
|
Reference in New Issue
Block a user