flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tzulitai <...@git.apache.org>
Subject [GitHub] flink pull request #3001: [FLINK-4821] [kinesis] Implement rescalable non-pa...
Date Wed, 19 Apr 2017 06:29:03 GMT
Github user tzulitai commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3001#discussion_r112122515
  
    --- Diff: flink-connectors/flink-connector-kinesis/src/main/java/org/apache/flink/streaming/connectors/kinesis/FlinkKinesisConsumer.java
---
    @@ -267,38 +293,84 @@ public void close() throws Exception {
     	// ------------------------------------------------------------------------
     
     	@Override
    -	public HashMap<KinesisStreamShard, SequenceNumber> snapshotState(long checkpointId,
long checkpointTimestamp) throws Exception {
    +	public void snapshotState(FunctionSnapshotContext context) throws Exception {
     		if (lastStateSnapshot == null) {
     			LOG.debug("snapshotState() requested on not yet opened source; returning null.");
    -			return null;
    -		}
    -
    -		if (fetcher == null) {
    +		} else if (fetcher == null) {
     			LOG.debug("snapshotState() requested on not yet running source; returning null.");
    -			return null;
    -		}
    -
    -		if (!running) {
    +		} else if (!running) {
     			LOG.debug("snapshotState() called on closed source; returning null.");
    -			return null;
    +		} else {
    +			if (LOG.isDebugEnabled()) {
    +				LOG.debug("Snapshotting state ...");
    +			}
    +
    +			offsetsStateForCheckpoint.clear();
    +			lastStateSnapshot = fetcher.snapshotState();
    +
    +			if (LOG.isDebugEnabled()) {
    +				LOG.debug("Snapshotted state, last processed sequence numbers: {}, checkpoint id:
{}, timestamp: {}",
    +					lastStateSnapshot.toString(), context.getCheckpointId(), context.getCheckpointTimestamp());
    +			}
    +
    +			for (Map.Entry<KinesisStreamShard, SequenceNumber> entry : lastStateSnapshot.entrySet())
{
    +				offsetsStateForCheckpoint.add(Tuple2.of(entry.getKey(), entry.getValue()));
    +			}
     		}
    +	}
     
    -		if (LOG.isDebugEnabled()) {
    -			LOG.debug("Snapshotting state ...");
    +	@Override
    +	public void initializeState(FunctionInitializationContext context) throws Exception
{
    +		TypeInformation<Tuple2<KinesisStreamShard, SequenceNumber>> tuple = new
TupleTypeInfo<>(
    +			TypeInformation.of(KinesisStreamShard.class),
    +			TypeInformation.of(SequenceNumber.class)
    +		);
    +
    +		offsetsStateForCheckpoint = context.getOperatorStateStore().getUnionListState(
    +			new ListStateDescriptor<>(DefaultOperatorStateBackend.DEFAULT_OPERATOR_STATE_NAME,
tuple));
    +
    +		if (context.isRestored()) {
    +			if (sequenceNumsToRestore == null) {
    +				sequenceNumsToRestore = new HashMap<>();
    +				for (Tuple2<KinesisStreamShard, SequenceNumber> kinesisOffset : offsetsStateForCheckpoint.get())
{
    +					sequenceNumsToRestore.put(kinesisOffset.f0, kinesisOffset.f1);
    +				}
    +
    +				LOG.info("Setting restore state in the FlinkKinesisConsumer.");
    +				if (LOG.isDebugEnabled()) {
    +					LOG.debug("Using the following offsets: {}", sequenceNumsToRestore);
    +				}
    +			} else if (sequenceNumsToRestore.isEmpty()) {
    +				sequenceNumsToRestore = null;
    +			}
    +		} else {
    +			LOG.info("No restore state for FlinkKinesisConsumer.");
     		}
    +	}
     
    -		lastStateSnapshot = fetcher.snapshotState();
    +	@Override
    +	public void restoreState(HashMap<KinesisStreamShard, SequenceNumber> restoredState)
throws Exception {
    +		LOG.info("{} (taskIdx={}) restoring offsets from an older version.",
    +			getClass().getSimpleName(), getRuntimeContext().getIndexOfThisSubtask());
    +
    +		sequenceNumsToRestore = restoredState.isEmpty() ? null : restoredState;
     
     		if (LOG.isDebugEnabled()) {
    -			LOG.debug("Snapshotted state, last processed sequence numbers: {}, checkpoint id:
{}, timestamp: {}",
    -				lastStateSnapshot.toString(), checkpointId, checkpointTimestamp);
    +			LOG.debug("{} (taskIdx={}) restored offsets from an older Flink version: {}",
    +				getClass().getSimpleName(), getRuntimeContext().getIndexOfThisSubtask(), sequenceNumsToRestore);
    --- End diff --
    
    Same here. I think this debug info can just be integrated with the previous info log message.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message