@@ -208,18 +208,19 @@ public void shutdown(ShutdownInput shutdownInput) {
208
208
* Called on ShutdownReason.TERMINATE
209
209
*/
210
210
private void onTerminate (ShutdownInput shutdownInput ) throws InvalidStateException , ShutdownException , InterruptedException {
211
- if (!lastProcessedSeqNo .isEmpty ()) {
212
- ShardInfo processorRegister = shardRegister .get (this .shardId );
213
-
214
- while (!processorRegister .getLastCommittedRecordSeqNo ().equals (this .lastProcessedSeqNo )) {
215
- LOGGER .info (
216
- "Shard ended. Waiting for all data table: {} from shard: {} to be committed. " +
217
- "lastCommittedRecordSeqNo: {} lastProcessedSeqNo: {}" ,
218
- tableName ,
219
- shardId ,
220
- processorRegister .getLastCommittedRecordSeqNo (),
221
- this .lastProcessedSeqNo );
222
- Thread .sleep (1000 );
211
+ if (lastProcessedSeqNo != null && !lastProcessedSeqNo .isEmpty ()) {
212
+ ShardInfo processorRegister = shardRegister .getOrDefault (this .shardId , null );
213
+ if (processorRegister != null ) {
214
+ while (!processorRegister .getLastCommittedRecordSeqNo ().equals (this .lastProcessedSeqNo )) {
215
+ LOGGER .info (
216
+ "Shard ended. Waiting for all data table: {} from shard: {} to be committed. " +
217
+ "lastCommittedRecordSeqNo: {} lastProcessedSeqNo: {}" ,
218
+ tableName ,
219
+ shardId ,
220
+ processorRegister .getLastCommittedRecordSeqNo (),
221
+ this .lastProcessedSeqNo );
222
+ Thread .sleep (500 );
223
+ }
223
224
}
224
225
}
225
226
@@ -231,7 +232,10 @@ private void onTerminate(ShutdownInput shutdownInput) throws InvalidStateExcepti
231
232
"Shard ended. All data committed. Checkpoint and proceed to next one. Table: {} ShardID: {}" ,
232
233
tableName ,
233
234
shardId );
234
- shutdownInput .getCheckpointer ().checkpoint ();
235
+ IRecordProcessorCheckpointer checkpointer = shutdownInput .getCheckpointer ();
236
+ if (checkpointer != null ) {
237
+ checkpointer .checkpoint ();
238
+ }
235
239
}
236
240
237
241
/**
0 commit comments