Add ReadDBStateCopy

graph-rework-2
noah metz 2023-06-26 23:03:11 -06:00
parent b145148471
commit 94ef8ca3d0
1 changed files with 23 additions and 0 deletions

@ -266,6 +266,29 @@ func (node * BaseNode) StateLock() * sync.RWMutex {
return &node.state_lock return &node.state_lock
} }
func ReadDBStateCopy(ctx * GraphContext, id NodeID) ([]byte, error) {
ctx.Log.Logf("db", "DB_READ: %s", id)
var val []byte = nil
err := ctx.DB.View(func(txn *badger.Txn) error {
item, err := txn.Get([]byte(id))
if err != nil {
return err
}
val, err = item.ValueCopy(nil)
if err != nil {
return err
}
return nil
})
if err != nil {
return nil, err
}
return val, nil
}
func WriteDBState(ctx * GraphContext, id NodeID, state NodeState) error { func WriteDBState(ctx * GraphContext, id NodeID, state NodeState) error {
ctx.Log.Logf("db", "DB_WRITE: %s - %+v", id, state) ctx.Log.Logf("db", "DB_WRITE: %s - %+v", id, state)