From b843da73dd6a487e4cec0e458ec662fb2edbde14 Mon Sep 17 00:00:00 2001 From: sangtran Date: Sat, 5 Sep 2026 23:51:10 +0700 Subject: misc: fix return bug in pebble_state and add on close method cleanup --- main.go | 9 ++++++++- state/pebble_backend.go | 6 ++++++ state/pebble_state.go | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 91b96e3..2399ceb 100644 --- a/main.go +++ b/main.go @@ -41,9 +41,16 @@ func (t *TransactionSummary[IN, OUT]) Apply(ctx context.Context, key string, win func main() { // init ctx := context.Background() + // memory backend + // backend := state.NewMemoryStateBackend(1) + // pebble backend + backend, err := state.NewPebbleStateBackend("./data_pebble", 1) - backend := state.NewMemoryStateBackend(1) + if err != nil { + panic(err) + } + defer backend.Close() ctx = core.InjectStateBackend(ctx, backend) txList := []Transaction{ diff --git a/state/pebble_backend.go b/state/pebble_backend.go index fbb8d68..b510f8f 100644 --- a/state/pebble_backend.go +++ b/state/pebble_backend.go @@ -128,3 +128,9 @@ func (p *PebbleStateBackend) deserialize(stateID uint8) []byte { } return b } + +func (p *PebbleStateBackend) Close() error { + return p.db.Close() +} + + diff --git a/state/pebble_state.go b/state/pebble_state.go index 3eeaa05..0b60deb 100644 --- a/state/pebble_state.go +++ b/state/pebble_state.go @@ -44,7 +44,7 @@ func (p *pebbleStateValue) Value(ctx context.Context) (any, error) { res := core.GetBuffer(len(v)) copy(res, v) - return v, nil + return res, nil } func (p *pebbleStateValue) Clear(ctx context.Context) error { -- cgit v1.3.1