Created IsMaxMemoryExceeded utility function that is used to check whether the server has exceeded the max memory.

Check whether max memory is exceeded before setting value or creating new key.
Return error from SetValue function when max memory is exceeded. This change has been propagated to the aof and snapshot engines as well.
Snapshot engine now only accepts SetValue option. No longer does it neet to use CreateKeyAndLock & KeyUnlock functions itself.
This commit is contained in:
Kelvin Mwinuka
2024-03-06 15:20:45 +08:00
parent f23bbd481e
commit 118e155144
7 changed files with 65 additions and 25 deletions

View File

@@ -26,7 +26,7 @@ type Engine struct {
startRewrite func()
finishRewrite func()
getState func() map[string]interface{}
setValue func(key string, value interface{})
setValue func(key string, value interface{}) error
handleCommand func(command []byte)
}
@@ -60,7 +60,7 @@ func WithGetStateFunc(f func() map[string]interface{}) func(engine *Engine) {
}
}
func WithSetValueFunc(f func(key string, value interface{})) func(engine *Engine) {
func WithSetValueFunc(f func(key string, value interface{}) error) func(engine *Engine) {
return func(engine *Engine) {
engine.setValue = f
}
@@ -94,7 +94,10 @@ func NewAOFEngine(options ...func(engine *Engine)) *Engine {
startRewrite: func() {},
finishRewrite: func() {},
getState: func() map[string]interface{} { return nil },
setValue: func(key string, value interface{}) {},
setValue: func(key string, value interface{}) error {
// No-Op by default
return nil
},
handleCommand: func(command []byte) {},
}