38
38
// upon observing a history event indicating that the command has been recorded. Note that this
39
39
// does not imply that the command has been _executed_, only that it _will be_ executed at some
40
40
// point in the future.
41
- CommandIssued --( CommandRecorded ( CmdRecDat ) , shared on_command_recorded) --> Done ;
41
+ CommandIssued --( CommandRecorded , on_command_recorded) --> Done ;
42
42
}
43
43
44
44
/// Instantiates an UpsertSearchAttributesMachine and packs it together with an initial command
@@ -62,37 +62,21 @@ pub(super) fn upsert_search_attrs(
62
62
) ;
63
63
// We must still create the command to preserve compatability with anyone previously doing
64
64
// this.
65
- create_new ( Default :: default ( ) , true , internal_flags )
65
+ create_new ( Default :: default ( ) )
66
66
} else {
67
- create_new ( attribs. search_attributes . into ( ) , false , internal_flags )
67
+ create_new ( attribs. search_attributes . into ( ) )
68
68
}
69
69
}
70
70
71
71
/// May be used by other state machines / internal needs which desire upserting search attributes.
72
72
pub ( super ) fn upsert_search_attrs_internal (
73
73
attribs : UpsertWorkflowSearchAttributesCommandAttributes ,
74
- internal_flags : InternalFlagsRef ,
75
74
) -> NewMachineWithCommand {
76
- create_new (
77
- attribs. search_attributes . unwrap_or_default ( ) ,
78
- true ,
79
- internal_flags,
80
- )
75
+ create_new ( attribs. search_attributes . unwrap_or_default ( ) )
81
76
}
82
77
83
- fn create_new (
84
- sa_map : SearchAttributes ,
85
- should_skip_determinism : bool ,
86
- internal_flags : InternalFlagsRef ,
87
- ) -> NewMachineWithCommand {
88
- let sm = UpsertSearchAttributesMachine :: from_parts (
89
- Created { } . into ( ) ,
90
- SharedState {
91
- sa_map : sa_map. clone ( ) ,
92
- should_skip_determinism,
93
- internal_flags,
94
- } ,
95
- ) ;
78
+ fn create_new ( sa_map : SearchAttributes ) -> NewMachineWithCommand {
79
+ let sm = UpsertSearchAttributesMachine :: from_parts ( Created { } . into ( ) , SharedState { } ) ;
96
80
let cmd = Command {
97
81
command_type : CommandType :: UpsertWorkflowSearchAttributes as i32 ,
98
82
attributes : Some (
@@ -110,11 +94,7 @@ fn create_new(
110
94
}
111
95
112
96
#[ derive( Clone ) ]
113
- pub ( super ) struct SharedState {
114
- should_skip_determinism : bool ,
115
- sa_map : SearchAttributes ,
116
- internal_flags : InternalFlagsRef ,
117
- }
97
+ pub ( super ) struct SharedState { }
118
98
119
99
/// The state-machine-specific set of commands that are the results of state transition in the
120
100
/// UpsertSearchAttributesMachine. There are none of these because this state machine emits the
@@ -131,30 +111,9 @@ pub(super) struct Created {}
131
111
/// higher-level machinery, it transitions into this state.
132
112
#[ derive( Debug , Default , Clone , derive_more:: Display ) ]
133
113
pub ( super ) struct CommandIssued { }
134
- pub ( super ) struct CmdRecDat {
135
- sa_map : Option < SearchAttributes > ,
136
- replaying : bool ,
137
- }
138
114
139
115
impl CommandIssued {
140
- pub ( super ) fn on_command_recorded (
141
- self ,
142
- shared : & mut SharedState ,
143
- dat : CmdRecDat ,
144
- ) -> UpsertSearchAttributesMachineTransition < Done > {
145
- if shared. internal_flags . borrow_mut ( ) . try_use (
146
- CoreInternalFlags :: UpsertSearchAttributeOnPatch ,
147
- !dat. replaying ,
148
- ) {
149
- let sa = dat. sa_map . unwrap_or_default ( ) ;
150
- if !shared. should_skip_determinism && shared. sa_map != sa {
151
- return TransitionResult :: Err ( WFMachinesError :: Nondeterminism ( format ! (
152
- "Search attribute upsert calls must remain deterministic, but {:?} does not \
153
- match the attributes from history: {:?}",
154
- shared. sa_map, sa
155
- ) ) ) ;
156
- }
157
- }
116
+ pub ( super ) fn on_command_recorded ( self ) -> UpsertSearchAttributesMachineTransition < Done > {
158
117
TransitionResult :: default ( )
159
118
}
160
119
}
@@ -198,14 +157,9 @@ impl TryFrom<HistEventData> for UpsertSearchAttributesMachineEvents {
198
157
199
158
fn try_from ( e : HistEventData ) -> Result < Self , Self :: Error > {
200
159
match e. event . attributes {
201
- Some ( history_event:: Attributes :: UpsertWorkflowSearchAttributesEventAttributes (
202
- attrs,
203
- ) ) => Ok ( UpsertSearchAttributesMachineEvents :: CommandRecorded (
204
- CmdRecDat {
205
- sa_map : attrs. search_attributes ,
206
- replaying : e. replaying ,
207
- } ,
208
- ) ) ,
160
+ Some ( history_event:: Attributes :: UpsertWorkflowSearchAttributesEventAttributes ( _) ) => {
161
+ Ok ( UpsertSearchAttributesMachineEvents :: CommandRecorded )
162
+ }
209
163
_ => Err ( Self :: Error :: Nondeterminism ( format ! (
210
164
"UpsertWorkflowSearchAttributesMachine does not handle {e}"
211
165
) ) ) ,
@@ -241,16 +195,15 @@ impl From<Created> for CommandIssued {
241
195
mod tests {
242
196
use super :: { super :: OnEventWrapper , * } ;
243
197
use crate :: {
244
- internal_flags:: InternalFlags ,
245
198
replay:: TestHistoryBuilder ,
246
199
test_help:: { build_mock_pollers, mock_worker, MockPollCfg , ResponseType } ,
247
200
worker:: {
248
201
client:: mocks:: mock_workflow_client,
249
202
workflow:: { machines:: patch_state_machine:: VERSION_SEARCH_ATTR_KEY , ManagedWFFunc } ,
250
203
} ,
251
204
} ;
252
- use rustfsm:: { MachineError , StateMachine } ;
253
- use std:: { cell :: RefCell , collections:: HashMap , rc :: Rc } ;
205
+ use rustfsm:: StateMachine ;
206
+ use std:: collections:: HashMap ;
254
207
use temporal_sdk:: { WfContext , WorkflowFunction } ;
255
208
use temporal_sdk_core_api:: Worker ;
256
209
use temporal_sdk_core_protos:: {
@@ -317,25 +270,14 @@ mod tests {
317
270
}
318
271
319
272
#[ rstest:: rstest]
320
- fn upsert_search_attrs_sm ( #[ values( true , false ) ] nondetermistic : bool ) {
321
- let mut sm = UpsertSearchAttributesMachine :: from_parts (
322
- Created { } . into ( ) ,
323
- SharedState {
324
- sa_map : Default :: default ( ) ,
325
- should_skip_determinism : false ,
326
- internal_flags : Rc :: new ( RefCell :: new ( InternalFlags :: all_core_enabled ( ) ) ) ,
327
- } ,
328
- ) ;
329
-
330
- let sa_attribs = if nondetermistic {
331
- UpsertWorkflowSearchAttributesEventAttributes {
332
- workflow_task_completed_event_id : 0 ,
333
- search_attributes : Some ( SearchAttributes {
334
- indexed_fields : HashMap :: from ( [ ( "Yo" . to_string ( ) , Payload :: default ( ) ) ] ) ,
335
- } ) ,
336
- }
337
- } else {
338
- Default :: default ( )
273
+ fn upsert_search_attrs_sm ( ) {
274
+ let mut sm = UpsertSearchAttributesMachine :: from_parts ( Created { } . into ( ) , SharedState { } ) ;
275
+
276
+ let sa_attribs = UpsertWorkflowSearchAttributesEventAttributes {
277
+ workflow_task_completed_event_id : 0 ,
278
+ search_attributes : Some ( SearchAttributes {
279
+ indexed_fields : HashMap :: from ( [ ( "Yo" . to_string ( ) , Payload :: default ( ) ) ] ) ,
280
+ } ) ,
339
281
} ;
340
282
let recorded_history_event = HistoryEvent {
341
283
event_type : EventType :: UpsertWorkflowSearchAttributes as i32 ,
@@ -365,15 +307,8 @@ mod tests {
365
307
assert_eq ! ( CommandIssued { } . to_string( ) , sm. state( ) . to_string( ) ) ;
366
308
367
309
let recorded_res = OnEventWrapper :: on_event_mut ( & mut sm, cmd_recorded_sm_event) ;
368
- if nondetermistic {
369
- assert_matches ! (
370
- recorded_res. unwrap_err( ) ,
371
- MachineError :: Underlying ( WFMachinesError :: Nondeterminism ( _) )
372
- ) ;
373
- } else {
374
- recorded_res. expect ( "CommandRecorded should transition CommandIssued -> Done" ) ;
375
- assert_eq ! ( Done { } . to_string( ) , sm. state( ) . to_string( ) ) ;
376
- }
310
+ recorded_res. expect ( "CommandRecorded should transition CommandIssued -> Done" ) ;
311
+ assert_eq ! ( Done { } . to_string( ) , sm. state( ) . to_string( ) ) ;
377
312
}
378
313
379
314
#[ rstest:: rstest]
0 commit comments