forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-10531][e2e] Fix unstable TTL end-to-end test.
This closes apache#7036.
- Loading branch information
Showing
16 changed files
with
276 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...ate-ttl-test/src/main/java/org/apache/flink/streaming/tests/MonotonicTTLTimeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.streaming.tests; | ||
|
||
import org.apache.flink.runtime.state.ttl.TtlTimeProvider; | ||
|
||
import javax.annotation.concurrent.NotThreadSafe; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* A stub implementation of a {@link TtlTimeProvider} which guarantees that | ||
* processing time increases monotonically. | ||
*/ | ||
@NotThreadSafe | ||
final class MonotonicTTLTimeProvider implements TtlTimeProvider, Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/* | ||
* The following variables are static because the whole TTLTimeProvider will go | ||
* through serialization and, eventually, the state backend and the task executing | ||
* the TtlVerifyUpdateFunction will have different instances of it. | ||
* | ||
* If these were not static, then the TtlVerifyUpdateFunction would e.g. freeze | ||
* the time, but the backend would not be notified about it, resulting in inconsistent | ||
* state. | ||
* | ||
* If the number of task slots per TM changes, then we may need to add also synchronization. | ||
*/ | ||
|
||
private static boolean timeIsFrozen = false; | ||
|
||
private static long lastReturnedProcessingTime = Long.MIN_VALUE; | ||
|
||
@Override | ||
public long currentTimestamp() { | ||
if (timeIsFrozen && lastReturnedProcessingTime != Long.MIN_VALUE) { | ||
return lastReturnedProcessingTime; | ||
} | ||
|
||
timeIsFrozen = true; | ||
|
||
final long currentProcessingTime = System.currentTimeMillis(); | ||
if (currentProcessingTime < lastReturnedProcessingTime) { | ||
return lastReturnedProcessingTime; | ||
} | ||
|
||
lastReturnedProcessingTime = currentProcessingTime; | ||
return lastReturnedProcessingTime; | ||
} | ||
|
||
long unfreezeTime() { | ||
timeIsFrozen = false; | ||
return lastReturnedProcessingTime; | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...tream-state-ttl-test/src/main/java/org/apache/flink/streaming/tests/StubStateBackend.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.streaming.tests; | ||
|
||
import org.apache.flink.api.common.JobID; | ||
import org.apache.flink.api.common.typeutils.TypeSerializer; | ||
import org.apache.flink.metrics.MetricGroup; | ||
import org.apache.flink.runtime.execution.Environment; | ||
import org.apache.flink.runtime.query.TaskKvStateRegistry; | ||
import org.apache.flink.runtime.state.AbstractKeyedStateBackend; | ||
import org.apache.flink.runtime.state.CheckpointStorage; | ||
import org.apache.flink.runtime.state.CompletedCheckpointStorageLocation; | ||
import org.apache.flink.runtime.state.KeyGroupRange; | ||
import org.apache.flink.runtime.state.OperatorStateBackend; | ||
import org.apache.flink.runtime.state.StateBackend; | ||
import org.apache.flink.runtime.state.ttl.TtlTimeProvider; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.apache.flink.util.Preconditions.checkNotNull; | ||
|
||
/** | ||
* A stub implementation of the {@link StateBackend} that allows the use of | ||
* a custom {@link TtlTimeProvider}. | ||
*/ | ||
final class StubStateBackend implements StateBackend { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private final TtlTimeProvider ttlTimeProvider; | ||
|
||
private final StateBackend backend; | ||
|
||
StubStateBackend(final StateBackend wrappedBackend, final TtlTimeProvider ttlTimeProvider) { | ||
this.backend = checkNotNull(wrappedBackend); | ||
this.ttlTimeProvider = checkNotNull(ttlTimeProvider); | ||
} | ||
|
||
@Override | ||
public CompletedCheckpointStorageLocation resolveCheckpoint(String externalPointer) throws IOException { | ||
return backend.resolveCheckpoint(externalPointer); | ||
} | ||
|
||
@Override | ||
public CheckpointStorage createCheckpointStorage(JobID jobId) throws IOException { | ||
return backend.createCheckpointStorage(jobId); | ||
} | ||
|
||
@Override | ||
public <K> AbstractKeyedStateBackend<K> createKeyedStateBackend( | ||
Environment env, | ||
JobID jobID, | ||
String operatorIdentifier, | ||
TypeSerializer<K> keySerializer, | ||
int numberOfKeyGroups, | ||
KeyGroupRange keyGroupRange, | ||
TaskKvStateRegistry kvStateRegistry, | ||
TtlTimeProvider ttlTimeProvider, | ||
MetricGroup metricGroup) throws Exception { | ||
|
||
return backend.createKeyedStateBackend( | ||
env, | ||
jobID, | ||
operatorIdentifier, | ||
keySerializer, | ||
numberOfKeyGroups, | ||
keyGroupRange, | ||
kvStateRegistry, | ||
this.ttlTimeProvider, | ||
metricGroup | ||
); | ||
} | ||
|
||
@Override | ||
public OperatorStateBackend createOperatorStateBackend(Environment env, String operatorIdentifier) throws Exception { | ||
return backend.createOperatorStateBackend(env, operatorIdentifier); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.