aboutsummaryrefslogtreecommitdiff
path: root/state/memory_backend.go
diff options
context:
space:
mode:
authorsangtran <tranquangsang12.7@gmail.com>2026-08-29 01:08:28 +0700
committersangtran <tranquangsang12.7@gmail.com>2026-08-29 01:08:28 +0700
commit96c07bab1086510a55a004e9a1b90c30bc723a5c (patch)
tree7abbc615c51667e111fdef7b2ef69a9fc663f2ca /state/memory_backend.go
signatureVerified sangtran <tranquangsang12.7@gmail.com> Key: 8DD79823D235E1BB ultimate trust
downloadflux-96c07bab1086510a55a004e9a1b90c30bc723a5c.tar.gz
flux-96c07bab1086510a55a004e9a1b90c30bc723a5c.zip
Verified feat: init base draft support window
Diffstat (limited to 'state/memory_backend.go')
-rw-r--r--state/memory_backend.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/state/memory_backend.go b/state/memory_backend.go
new file mode 100644
index 0000000..6594657
--- /dev/null
+++ b/state/memory_backend.go
@@ -0,0 +1,57 @@
1package state
2
3import (
4 "context"
5 "flux/core"
6)
7
8// TODO: currently using Golang Map for go through the DAG pipline
9// This should be use index map index map[uint64]uint32 Hash(KeyGroup + StateName + Key) -> Offset
10// with 1GB of []byte allocation
11// This should be optimize with ZERO GC Scanning, Memory Alignment
12
13type MemoryStateBackend struct {
14 maxParallelism int
15 currentKey string
16 currentGroupKey int
17 currentNamespace any
18 // 4D structure StateName -> KeyGroup -> Key -> Namespace -> Value
19 states map[string]map[int]map[string]map[any]any
20}
21
22func NewMemoryStateBackend(maxParallelism int) *MemoryStateBackend {
23 return &MemoryStateBackend{
24 maxParallelism: maxParallelism,
25 states: make(map[string]map[int]map[string]map[any]any),
26 }
27}
28
29func (ms *MemoryStateBackend) GetCurrentKey() string {
30 return ms.currentKey
31}
32
33func (ms *MemoryStateBackend) SetCurrentKey(key string) error {
34 ms.currentKey = key
35 ms.currentGroupKey = core.AssignToKeyGroup(key, ms.maxParallelism)
36 return nil
37}
38
39func (ms *MemoryStateBackend) GetValueState(ctx context.Context, key string) (core.ValueState[any], error) {
40 // Assign if state not existed
41
42 if _, ok := ms.states[key]; !ok {
43 ms.states[key] = make(map[int]map[string]map[any]any)
44 }
45
46 return &memoryStateValue{backend: ms, stateName: key}, nil
47}
48
49func (ms *MemoryStateBackend) GetCurrentNamespace() any{
50
51 return ms.currentNamespace
52}
53
54func (ms *MemoryStateBackend) SetCurrentNamespace(namespace any) error {
55 ms.currentNamespace = namespace
56 return nil
57}