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) {},
|
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
|
// Setup Preamble engine
|
||||||
engine.preambleStore = preamble.NewPreambleStore(
|
engine.preambleStore = preamble.NewPreambleStore(
|
||||||
preamble.WithDirectory(engine.directory),
|
preamble.WithDirectory(engine.directory),
|
||||||
@@ -129,10 +135,6 @@ func NewAOFEngine(options ...func(engine *Engine)) *Engine {
|
|||||||
logstore.WithHandleCommandFunc(engine.handleCommand),
|
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.
|
// 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.
|
// LogCommand will get the open file handler from the struct top perform the AOF operation.
|
||||||
go func() {
|
go func() {
|
||||||
|
@@ -69,13 +69,11 @@ func WithHandleCommandFunc(f func(command []byte)) func(store *AppendStore) {
|
|||||||
|
|
||||||
func NewAppendStore(options ...func(store *AppendStore)) *AppendStore {
|
func NewAppendStore(options ...func(store *AppendStore)) *AppendStore {
|
||||||
store := &AppendStore{
|
store := &AppendStore{
|
||||||
directory: "",
|
directory: "",
|
||||||
strategy: "everysec",
|
strategy: "everysec",
|
||||||
rw: nil,
|
rw: nil,
|
||||||
mut: sync.Mutex{},
|
mut: sync.Mutex{},
|
||||||
handleCommand: func(command []byte) {
|
handleCommand: func(command []byte) {},
|
||||||
// No-Op
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
@@ -130,8 +128,11 @@ func (store *AppendStore) Write(command []byte) error {
|
|||||||
|
|
||||||
func (store *AppendStore) Sync() error {
|
func (store *AppendStore) Sync() error {
|
||||||
store.mut.Lock()
|
store.mut.Lock()
|
||||||
store.mut.Unlock()
|
defer store.mut.Unlock()
|
||||||
return store.rw.Sync()
|
if store.rw != nil {
|
||||||
|
return store.rw.Sync()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *AppendStore) Restore() error {
|
func (store *AppendStore) Restore() error {
|
||||||
|
Reference in New Issue
Block a user