Skip to content

Commit ce95cbe

Browse files
committed
Cleanups / notes
1 parent 625ce37 commit ce95cbe

File tree

7 files changed

+23
-19
lines changed

7 files changed

+23
-19
lines changed

chasm/engine.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ func UpdateWithNewEntity[C Component, I any, O1 any, O2 any](
175175
// - consider remove ComponentRef from the return value and allow components to get
176176
// the ref in the transition function. There are some caveats there, check the
177177
// comment of the NewRef method in MutableContext.
178+
//
179+
// UpdateComponent applies updateFn to the component identified by the supplied component reference.
180+
// It returns the result, along with the new component reference.
178181
func UpdateComponent[C Component, R []byte | ComponentRef, I any, O any](
179182
ctx context.Context,
180183
r R,
@@ -206,6 +209,8 @@ func UpdateComponent[C Component, R []byte | ComponentRef, I any, O any](
206209
return output, newSerializedRef, err
207210
}
208211

212+
// ReadComponent returns the result of evaluating readFn against the current state of the component
213+
// identified by the supplied component reference.
209214
func ReadComponent[C Component, R []byte | ComponentRef, I any, O any](
210215
ctx context.Context,
211216
r R,

chasm/lib/activity/handler.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ func pollActivityExecutionWaitAnyStateChange(
104104
req *activitypb.PollActivityExecutionRequest,
105105
) (*activitypb.PollActivityExecutionResponse, []byte, error) {
106106

107-
// TODO(dan): it is not guaranteed that the response data will differ from that received on a
108-
// previous call. However, this is confusing API behavior: we don't want the server to say
109-
// "there's been a change" while returning data in which the change is not apparent.
107+
// TODO(dan): do we want to guarantee that response data will differ from that received when the
108+
// token was obtained? It's potentially confusing for the server to say "there's been a change"
109+
// while returning data in which the change is not apparent.
110110

111111
refBytesFromToken := req.GetFrontendRequest().
112112
GetWaitPolicy().(*workflowservice.PollActivityExecutionRequest_WaitAnyStateChange).
@@ -161,17 +161,14 @@ func pollActivityExecutionWaitAnyStateChange(
161161
// The runID from the token doesn't match this shard's state. We return immediately,
162162
// on the basis that this constitutes a state change. If the runID from the token is
163163
// ahead of this shard's state then this will be detected by shard ownership or
164-
// staleness checks and the caller will receive an error. Therefore we can assume
165-
// that the runID from the token is behind the shard state and that it's appropriate
166-
// to report a state change to the caller.
164+
// staleness checks and the caller will receive an error.
167165
response, err := a.buildPollActivityExecutionResponse(ctx, req)
168166
if err != nil {
169167
return nil, true, err
170168
}
171169
return response, true, nil
172170
}
173171

174-
// TODO(dan): is this leaking too much detail about VTs?
175172
refComparison, err := chasm.CompareComponentRefs(&lastSeenRef, &currentRef)
176173
if err != nil {
177174
return nil, false, err
@@ -204,7 +201,7 @@ func pollActivityExecutionWaitCompletion(
204201
ctx context.Context,
205202
req *activitypb.PollActivityExecutionRequest,
206203
) (*activitypb.PollActivityExecutionResponse, []byte, error) {
207-
// TODO(dan): untested
204+
// TODO(dan): implement functional test when RecordActivityTaskCompleted is implemented
208205
return chasm.PollComponent(
209206
ctx,
210207
chasm.NewComponentRef[*Activity](chasm.EntityKey{

chasm/ref.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ func ProtoRefToComponentRef(pRef *persistencespb.ChasmComponentRef) ComponentRef
157157
}
158158
}
159159

160+
// TODO(dan): is this leaking too much detail about VTs?
161+
//
160162
// Compare compares the entity versioned transition of two ComponentRefs. Returns -1 if a < b, 0 if
161163
// a == b, 1 if a > b, where a and b are compared according to their versioned transitions using
162-
// transitionhistory.Compare. Note that this plies that a component ref without a versioned
164+
// transitionhistory.Compare. Note that this implies that a component ref without a versioned
163165
// transition compares less than any component ref with a versioned transition.
164-
//
165-
// TODO(dan): is this leaking too much detail about VTs?
166166
func CompareComponentRefs(a, b *ComponentRef) (int, error) {
167167
if a.EntityKey != b.EntityKey {
168168
return 0, serviceerror.NewInvalidArgument("component refs have different entity keys and cannot be compared")

chasm/tree.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2306,7 +2306,6 @@ func (n *Node) IsStateDirty() bool {
23062306
func (n *Node) IsStale(
23072307
ref ComponentRef,
23082308
) error {
2309-
23102309
// The point of this method to access the private entityLastUpdateVT field in componentRef,
23112310
// and avoid exposing it in the public CHASM interface.
23122311
if ref.entityLastUpdateVT == nil {

service/history/api/get_workflow_util.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ func GetOrPollMutableState(
6969
if err != nil {
7070
return nil, err
7171
}
72-
7372
currentVersionHistory, err := versionhistory.GetCurrentVersionHistory(response.GetVersionHistories())
7473
if err != nil {
7574
return nil, err
@@ -312,9 +311,6 @@ func GetMutableStateWithConsistencyCheck(
312311
return transitionhistory.StalenessCheck(transitionHistory, versionedTransition) == nil
313312
}
314313

315-
// TODO(dan): the line above implies that, given transitionhistory.StalenessCheck(), all
316-
// the version history checks below are unnecessary. Is this true?
317-
318314
currentVersionHistory, err := versionhistory.GetCurrentVersionHistory(mutableState.GetExecutionInfo().GetVersionHistories())
319315
if err != nil {
320316
return false

service/history/chasm_engine.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ func (e *ChasmEngine) SetShardController(
100100
e.shardController = shardController
101101
}
102102

103+
// Start starts the ChasmEngine
103104
func (e *ChasmEngine) Start() {
104105
e.notifier.Start()
105106
}
106107

108+
// Stop stops the ChasmEngine
107109
func (e *ChasmEngine) Stop() {
108110
e.notifier.Stop()
109111
}
@@ -292,7 +294,7 @@ func (e *ChasmEngine) PollComponent(
292294
) ([]byte, error) {
293295
// 1. Acquire lock
294296
// 2. Error if shard entity VT < requestRef VT ('stale state')
295-
// 3. Release lock and return if predicate satisfied
297+
// 3. If predicate satisfied, release lock and return
296298
// 4. Subscribe to notifications for this entity
297299
// 5. Release lock
298300
// 6. On notification repeat (1) and (2)
@@ -376,7 +378,7 @@ func (e *ChasmEngine) PollComponent(
376378
return newRef, nil
377379
}
378380
case <-longPollCtx.Done():
379-
// TODO(dan): or return empty response?
381+
// TODO(dan): return empty response?
380382
return nil, serviceerror.NewDeadlineExceeded("long-poll timed out")
381383
}
382384
}

tests/standalone_activity_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (s *standaloneActivityTestSuite) Test_PollActivityExecution_WaitAnyStateCha
146146
})
147147
}()
148148

149-
// TODO(dan): race here: subscription might not be established yet?
149+
// TODO(dan): race here: subscription might not be established yet
150150

151151
// Worker picks up activity task, triggering transition (via RecordActivityTaskStarted)
152152
go func() {
@@ -194,6 +194,11 @@ func (s *standaloneActivityTestSuite) Test_PollActivityExecution_WaitAnyStateCha
194194
require.ErrorContains(t, err, "cached mutable state could potentially be stale")
195195
}
196196

197+
func (s *standaloneActivityTestSuite) Test_PollActivityExecution_WaitCompletion() {
198+
t := s.T()
199+
t.Skip("TODO(dan): implement test when RecordActivityTaskCompleted is implemented")
200+
}
201+
197202
func (s *standaloneActivityTestSuite) startActivity(ctx context.Context, activityID string, taskQueue string) (*workflowservice.StartActivityExecutionResponse, error) {
198203
return s.FrontendClient().StartActivityExecution(ctx, &workflowservice.StartActivityExecutionRequest{
199204
Namespace: s.Namespace().String(),

0 commit comments

Comments
 (0)