blob: 58e86e0940f0c6307f70bacad82dfc194c294b7d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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")
}
|