Check for nil rw object in LogStore before attemting a sync

This commit is contained in:
Kelvin Mwinuka
2024-03-25 11:48:58 +08:00
parent aea3e0675c
commit ea0092e7cc
3 changed files with 706 additions and 703 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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() {

View File

@@ -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,9 +128,12 @@ 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 {
store.mut.Lock()