mirror of
				https://github.com/EchoVault/SugarDB.git
				synced 2025-10-31 19:32:59 +08:00 
			
		
		
		
	Take expiry into account when creating snashot and AOF preamble. If the key is already expired when snapshot is taken, it will not be persisted. If the key is expired when loading a snapshot/preamble, it will not be restored.
This commit is contained in:
		| @@ -4,8 +4,10 @@ import ( | ||||
| 	"fmt" | ||||
| 	logstore "github.com/echovault/echovault/src/aof/log" | ||||
| 	"github.com/echovault/echovault/src/aof/preamble" | ||||
| 	"github.com/echovault/echovault/src/utils" | ||||
| 	"log" | ||||
| 	"sync" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| // This package handles AOF logging in standalone mode only. | ||||
| @@ -25,8 +27,9 @@ type Engine struct { | ||||
|  | ||||
| 	startRewrite  func() | ||||
| 	finishRewrite func() | ||||
| 	getState      func() map[string]interface{} | ||||
| 	getState      func() map[string]utils.KeyData | ||||
| 	setValue      func(key string, value interface{}) error | ||||
| 	setExpiry     func(key string, expireAt time.Time) error | ||||
| 	handleCommand func(command []byte) | ||||
| } | ||||
|  | ||||
| @@ -54,7 +57,7 @@ func WithFinishRewriteFunc(f func()) func(engine *Engine) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func WithGetStateFunc(f func() map[string]interface{}) func(engine *Engine) { | ||||
| func WithGetStateFunc(f func() map[string]utils.KeyData) func(engine *Engine) { | ||||
| 	return func(engine *Engine) { | ||||
| 		engine.getState = f | ||||
| 	} | ||||
| @@ -66,6 +69,12 @@ func WithSetValueFunc(f func(key string, value interface{}) error) func(engine * | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func WithSetExpiryFunc(f func(key string, expireAt time.Time) error) func(engine *Engine) { | ||||
| 	return func(engine *Engine) { | ||||
| 		engine.setExpiry = f | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func WithHandleCommandFunc(f func(command []byte)) func(engine *Engine) { | ||||
| 	return func(engine *Engine) { | ||||
| 		engine.handleCommand = f | ||||
| @@ -93,11 +102,12 @@ func NewAOFEngine(options ...func(engine *Engine)) *Engine { | ||||
| 		logCount:      0, | ||||
| 		startRewrite:  func() {}, | ||||
| 		finishRewrite: func() {}, | ||||
| 		getState:      func() map[string]interface{} { return nil }, | ||||
| 		getState:      func() map[string]utils.KeyData { return nil }, | ||||
| 		setValue: func(key string, value interface{}) error { | ||||
| 			// No-Op by default | ||||
| 			return nil | ||||
| 		}, | ||||
| 		setExpiry:     func(key string, expireAt time.Time) error { return nil }, | ||||
| 		handleCommand: func(command []byte) {}, | ||||
| 	} | ||||
|  | ||||
| @@ -111,6 +121,7 @@ func NewAOFEngine(options ...func(engine *Engine)) *Engine { | ||||
| 		preamble.WithReadWriter(engine.preambleRW), | ||||
| 		preamble.WithGetStateFunc(engine.getState), | ||||
| 		preamble.WithSetValueFunc(engine.setValue), | ||||
| 		preamble.WithSetExpiryFunc(engine.setExpiry), | ||||
| 	) | ||||
|  | ||||
| 	// Setup AOF log store engine | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kelvin Mwinuka
					Kelvin Mwinuka