358
}
359
}
360
>
def, ok := n.registry.Machine(key.Type)
tree.go
361
>
if !ok {
362
return nil, fmt.Errorf("%w: state machine for type: %v", ErrNotRegistered, key.Type)
363
}
364
>
serialized, err := def.Serialize(data)
tree.go
365
>
if err != nil {
366
return nil, err
367
}
368
369
>
nextVersionedTransition := &persistencespb.VersionedTransition{
tree.go
370
>
NamespaceFailoverVersion: n.backend.GetCurrentVersion(),
371
>
// The transition count for the backend is only incremented when closing the current transaction,
372
>
// but any change to state machine node is a state transtion,
373
>
// so we can safely using next transition count here is safe.
374
>
TransitionCount: n.backend.NextTransitionCount(),
375
>
}
376
>
node := &Node{
377
>
Key: key,
378
>
Parent: n,
379
>
definition: def,
380
>
registry: n.registry,
381
>
persistence: &persistencespb.StateMachineNode{
382
>
Children: make(map[string]*persistencespb.StateMachineMap),
383
>
Data: serialized,
384
>
InitialVersionedTransition: nextVersionedTransition,
385
>
LastUpdateVersionedTransition: nextVersionedTransition,
386
>
TransitionCount: 0,
387
>
},
388
>
cache: &cachedMachine{
389
>
dataLoaded: true,
390
>
data: data,
391
>
dirty: true,
392
>
children: make(map[Key]*Node),
393
>
},
394
>
backend: n.backend,
395
>
}
396
>
n.cache.children[key] = node
397
>
children, ok := n.persistence.Children[key.Type]
398
>
if !ok {
399
children = &persistencespb.StateMachineMap{MachinesById: make(map[string]*persistencespb.StateMachineNode)}
400
// Children may be nil if the map was empty and the proto message we serialized and deserialized.