|
119 | 119 | handler_data :: term(), |
120 | 120 |
|
121 | 121 | %% connected socket owned by this process: |
122 | | - socket :: gen_tcp:socket(), |
| 122 | + socket :: undefined | gen_tcp:socket(), |
123 | 123 |
|
124 | 124 | %% input buffer; responses are small and we need no output buffer: |
125 | | - buf = [] :: list(binary()), |
| 125 | + buf = [] :: [binary()], |
126 | 126 |
|
127 | 127 | %% worker state returned from handler module init: |
128 | | - worker_state :: term(), |
| 128 | + worker_state :: undefined | term(), |
129 | 129 |
|
130 | 130 | %% if true, the MLD made a processRecords call with the V2 format (supplied |
131 | 131 | %% millisBehindLatest), so we will checkpoint using the V2 checkpoint format: |
132 | 132 | is_v2 = false :: boolean(), |
133 | 133 |
|
134 | 134 | %% most recent action name from the peer: |
135 | | - last_request :: binary(), |
| 135 | + last_request :: undefined | binary(), |
136 | 136 |
|
137 | 137 | %% last attempted checkpoint: |
138 | | - last_checkpoint :: checkpoint() |
| 138 | + last_checkpoint :: undefined | checkpoint() |
139 | 139 | }). |
140 | 140 |
|
141 | 141 | -define(INTERNAL, internal). |
@@ -410,22 +410,26 @@ handle_event(?INTERNAL, #{<<"action">> := <<"checkpoint">>, |
410 | 410 |
|
411 | 411 | handle_event(?INTERNAL, #{<<"action">> := <<"checkpoint">>} = R, |
412 | 412 | {?DISPATCH, CheckpointState}, |
413 | | - #data{worker_state = {ok, WorkerState}, |
| 413 | + #data{handler_module = Mod, |
| 414 | + worker_state = {ok, WorkerState}, |
414 | 415 | last_checkpoint = Checkpoint, |
415 | 416 | last_request = LastAction} = Data) |
416 | 417 | when CheckpointState == ?CHECKPOINT; |
417 | 418 | CheckpointState == ?SHUTDOWN_CHECKPOINT -> |
418 | | - %% successful checkpoint. fixme; provide indication of success to worker? |
419 | 419 | SN = sequence_number(R), |
420 | | - error_logger:info_msg("~p checkpointed at ~p (~p)~n", [WorkerState, Checkpoint, SN]), |
421 | | - case CheckpointState of |
422 | | - ?CHECKPOINT -> |
423 | | - {next_state, ?PROCESS_RECORDS, Data}; |
424 | | - ?SHUTDOWN_CHECKPOINT -> |
425 | | - success(LastAction, Data, ?SHUTDOWN) |
| 420 | + case Mod:checkpointed(WorkerState, SN, Checkpoint) of |
| 421 | + {ok, NWorkerState} -> |
| 422 | + NData = worker_state(Data, NWorkerState), |
| 423 | + case CheckpointState of |
| 424 | + ?CHECKPOINT -> |
| 425 | + {next_state, ?PROCESS_RECORDS, NData}; |
| 426 | + ?SHUTDOWN_CHECKPOINT -> |
| 427 | + success(LastAction, NData, ?SHUTDOWN) |
| 428 | + end; |
| 429 | + {error, _} = Error -> |
| 430 | + {stop, Error} |
426 | 431 | end; |
427 | 432 |
|
428 | | - |
429 | 433 | %% we were processing records and we attempted to checkpoint, but failed because another |
430 | 434 | %% worker stole our lease. abort record processing, return a 'success' response for |
431 | 435 | %% the current command, and read the next request, which should be a shutdown command. |
@@ -586,7 +590,7 @@ next_line(Bin, #data{buf = Buf} = Data) -> |
586 | 590 | %% and remaining data. an "action" is a line which should have been a json-encoded map |
587 | 591 | %% containing an "action" key. if decoding fails with a thrown error, that error is |
588 | 592 | %% returned as the decoded value. |
589 | | --spec next_action(binary(), #data{}) -> {map() | undefined, #data{}, binary()}. |
| 593 | +-spec next_action(binary(), #data{}) -> {map() | undefined | {error, term()}, #data{}, binary()}. |
590 | 594 | next_action(Bin, Data) -> |
591 | 595 | case next_line(Bin, Data) of |
592 | 596 | {undefined, NData, Rest} -> |
|
0 commit comments