aboutsummaryrefslogtreecommitdiff
path: root/state
diff options
context:
space:
mode:
authorSangTran-127 <tranquangsang12.7@gmail.com>2026-08-09 01:11:31 +0700
committerSangTran-127 <tranquangsang12.7@gmail.com>2026-08-09 01:11:31 +0700
commit4d62f01af159fddd56585b3dce19b8a0f47369c1 (patch)
treeb7396fad1528edb048ef500d1894f78312df8233 /state
parent0958e46c3651f2c8b6d76bcffbd8820063647d59 (diff)
downloadgoflink-4d62f01af159fddd56585b3dce19b8a0f47369c1.tar.gz
goflink-4d62f01af159fddd56585b3dce19b8a0f47369c1.zip
feat: implement memory state backend with key group assignment and value state interface
Diffstat (limited to 'state')
-rw-r--r--state/memory_backend.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/state/memory_backend.go b/state/memory_backend.go
new file mode 100644
index 0000000..58e86e0
--- /dev/null
+++ b/state/memory_backend.go
@@ -0,0 +1,41 @@
+package state
+
+import (
+ "context"
+ "goflink/core"
+)
+
+// TODO: currently using Golang Map for go through the DAG pipline
+// This should be use index map index map[uint64]uint32 Hash(KeyGroup + StateName + Key) -> Offset
+// with 1GB of []byte allocation
+// This should be optimize with ZERO GC Scanning, Memory Alignment
+
+type MemoryStateBackend struct {
+ maxParallelism int
+ currentKey string
+ currentGroupKey int
+ // 3D structure StateName -> KeyGroup -> Key -> Value
+ states map[string]map[int]map[string]any
+}
+
+func NewMemoryStateBackend(maxParallelism int) *MemoryStateBackend {
+ return &MemoryStateBackend{
+ maxParallelism: maxParallelism,
+ states: make(map[string]map[int]map[string]any),
+ }
+}
+
+func (ms *MemoryStateBackend) GetCurrentKey() string {
+ return ms.currentKey
+}
+
+func (ms *MemoryStateBackend) SetCurrentKey(key string) error {
+ ms.currentKey = key
+ ms.currentGroupKey = core.AssignToKeyGroup(key, ms.maxParallelism)
+ return nil
+}
+
+func (ms *MemoryStateBackend) GetValueState(ctx context.Context, key string) (core.ValueState[any], error) {
+ //TODO implement me
+ panic("implement me")
+}