You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2016/01/28 16:32:16 UTC
[1/5] flink git commit: [FLINK-3178] Don't Emit In-Flight Windows
When Closing Window Operator
Repository: flink
Updated Branches:
refs/heads/master 2e2330737 -> 6b01a8902
[FLINK-3178] Don't Emit In-Flight Windows When Closing Window Operator
This closes #1542
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/c4e5a55f
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/c4e5a55f
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/c4e5a55f
Branch: refs/heads/master
Commit: c4e5a55f027ed73ce557f10d5125a0b168832889
Parents: 2e23307
Author: Aljoscha Krettek <al...@gmail.com>
Authored: Mon Jan 18 13:25:03 2016 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Thu Jan 28 14:19:17 2016 +0100
----------------------------------------------------------------------
.../examples/windowing/SessionWindowing.java | 2 +-
.../util/TopSpeedWindowingExampleData.java | 8 +-
...ractAlignedProcessingTimeWindowOperator.java | 5 -
.../windowing/NonKeyedWindowOperator.java | 14 +--
.../operators/windowing/WindowOperator.java | 17 ++-
.../api/complex/ComplexIntegrationTest.java | 3 +-
...AlignedProcessingTimeWindowOperatorTest.java | 110 ++-----------------
...AlignedProcessingTimeWindowOperatorTest.java | 89 ++++-----------
.../util/OneInputStreamOperatorTestHarness.java | 3 +-
9 files changed, 54 insertions(+), 197 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/c4e5a55f/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/SessionWindowing.java
----------------------------------------------------------------------
diff --git a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/SessionWindowing.java b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/SessionWindowing.java
index 035727a..baa4af8 100644
--- a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/SessionWindowing.java
+++ b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/SessionWindowing.java
@@ -116,7 +116,7 @@ public class SessionWindowing {
// Update the last seen event time
lastSeenState.update(timestamp);
- ctx.registerEventTimeTimer(lastSeen + sessionTimeout);
+ ctx.registerEventTimeTimer(timestamp + sessionTimeout);
if (timeSinceLastEvent > sessionTimeout) {
return TriggerResult.FIRE_AND_PURGE;
http://git-wip-us.apache.org/repos/asf/flink/blob/c4e5a55f/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/util/TopSpeedWindowingExampleData.java
----------------------------------------------------------------------
diff --git a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/util/TopSpeedWindowingExampleData.java b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/util/TopSpeedWindowingExampleData.java
index bf63695..4718b8b 100644
--- a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/util/TopSpeedWindowingExampleData.java
+++ b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/util/TopSpeedWindowingExampleData.java
@@ -192,9 +192,7 @@ public class TopSpeedWindowingExampleData {
"(1,95,1973.6111111111115,1424952007664)\n" +
"(0,100,1709.7222222222229,1424952006663)\n" +
"(0,100,1737.5000000000007,1424952007664)\n" +
- "(1,95,1973.6111111111115,1424952007664)\n" +
- "(0,100,1791.6666666666674,1424952009664)\n" +
- "(1,95,2211.1111111111118,1424952017668)\n";
+ "(1,95,1973.6111111111115,1424952007664)\n";
public static final String TOP_CASE_CLASS_SPEEDS =
"CarEvent(0,55,15.277777777777777,1424951918630)\n" +
@@ -267,9 +265,7 @@ public class TopSpeedWindowingExampleData {
"CarEvent(1,95,1973.6111111111115,1424952007664)\n" +
"CarEvent(0,100,1709.7222222222229,1424952006663)\n" +
"CarEvent(0,100,1737.5000000000007,1424952007664)\n" +
- "CarEvent(1,95,1973.6111111111115,1424952007664)\n" +
- "CarEvent(0,100,1791.6666666666674,1424952009664)\n" +
- "CarEvent(1,95,2211.1111111111118,1424952017668)\n";
+ "CarEvent(1,95,1973.6111111111115,1424952007664)\n";
private TopSpeedWindowingExampleData() {
}
http://git-wip-us.apache.org/repos/asf/flink/blob/c4e5a55f/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/AbstractAlignedProcessingTimeWindowOperator.java
----------------------------------------------------------------------
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/AbstractAlignedProcessingTimeWindowOperator.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/AbstractAlignedProcessingTimeWindowOperator.java
index 677a7dd..b8c95aa 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/AbstractAlignedProcessingTimeWindowOperator.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/AbstractAlignedProcessingTimeWindowOperator.java
@@ -171,13 +171,8 @@ public abstract class AbstractAlignedProcessingTimeWindowOperator<KEY, IN, OUT,
public void close() throws Exception {
super.close();
- final long finalWindowTimestamp = nextEvaluationTime;
-
// early stop the triggering thread, so it does not attempt to return any more data
stopTriggers();
-
- // emit the remaining data
- computeWindow(finalWindowTimestamp);
}
@Override
http://git-wip-us.apache.org/repos/asf/flink/blob/c4e5a55f/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/NonKeyedWindowOperator.java
----------------------------------------------------------------------
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/NonKeyedWindowOperator.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/NonKeyedWindowOperator.java
index 7823631..2afa1e7 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/NonKeyedWindowOperator.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/NonKeyedWindowOperator.java
@@ -217,14 +217,14 @@ public class NonKeyedWindowOperator<IN, OUT, W extends Window>
}
@Override
- public final void close() throws Exception {
- super.close();
- // emit the elements that we still keep
- for (Context window: windows.values()) {
- emitWindow(window);
- }
+ public final void dispose() {
+ super.dispose();
windows.clear();
- windowBufferFactory.close();
+ try {
+ windowBufferFactory.close();
+ } catch (Exception e) {
+ throw new RuntimeException("Error while closing WindowBufferFactory.", e);
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/flink/blob/c4e5a55f/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperator.java
----------------------------------------------------------------------
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperator.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperator.java
index 68c3a5f..4a50efb 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperator.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperator.java
@@ -251,17 +251,14 @@ public class WindowOperator<K, IN, OUT, W extends Window>
}
@Override
- public final void close() throws Exception {
- super.close();
- // emit the elements that we still keep
- for (Map.Entry<K, Map<W, Context>> entry: windows.entrySet()) {
- Map<W, Context> keyWindows = entry.getValue();
- for (Context window: keyWindows.values()) {
- emitWindow(window);
- }
- }
+ public final void dispose() {
+ super.dispose();
windows.clear();
- windowBufferFactory.close();
+ try {
+ windowBufferFactory.close();
+ } catch (Exception e) {
+ throw new RuntimeException("Error while closing WindowBufferFactory.", e);
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/flink/blob/c4e5a55f/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/complex/ComplexIntegrationTest.java
----------------------------------------------------------------------
diff --git a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/complex/ComplexIntegrationTest.java b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/complex/ComplexIntegrationTest.java
index 020dda3..9b0a6d0 100644
--- a/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/complex/ComplexIntegrationTest.java
+++ b/flink-streaming-java/src/test/java/org/apache/flink/streaming/api/complex/ComplexIntegrationTest.java
@@ -214,6 +214,7 @@ public class ComplexIntegrationTest extends StreamingMultipleProgramsTestBase {
@SuppressWarnings("unchecked")
@Test
+ @Ignore
public void complexIntegrationTest3() throws Exception {
//Heavy prime factorisation with maps and flatmaps
@@ -225,7 +226,7 @@ public class ComplexIntegrationTest extends StreamingMultipleProgramsTestBase {
expected1 = "541\n" + "1223\n" + "1987\n" + "2741\n" + "3571\n" + "10939\n" + "4409\n" +
"5279\n" + "11927\n" + "6133\n" + "6997\n" + "12823\n" + "7919\n" + "8831\n" +
"13763\n" + "9733\n" + "9973\n" + "14759\n" + "15671\n" + "16673\n" + "17659\n" +
- "18617\n" + "19697\n" + "19997\n";
+ "18617\n";
for (int i = 2; i < 100; i++) {
expected2 += "(" + i + "," + 20000 / i + ")\n";
http://git-wip-us.apache.org/repos/asf/flink/blob/c4e5a55f/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AccumulatingAlignedProcessingTimeWindowOperatorTest.java
----------------------------------------------------------------------
diff --git a/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AccumulatingAlignedProcessingTimeWindowOperatorTest.java b/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AccumulatingAlignedProcessingTimeWindowOperatorTest.java
index ed0f04a..8722802 100644
--- a/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AccumulatingAlignedProcessingTimeWindowOperatorTest.java
+++ b/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AccumulatingAlignedProcessingTimeWindowOperatorTest.java
@@ -251,12 +251,14 @@ public class AccumulatingAlignedProcessingTimeWindowOperatorTest {
Thread.sleep(1);
}
+ // get and verify the result
+ out.waitForNElements(numElements, 60_000);
+
synchronized (lock) {
op.close();
}
op.dispose();
- // get and verify the result
List<Integer> result = out.getElements();
assertEquals(numElements, result.size());
@@ -441,102 +443,7 @@ public class AccumulatingAlignedProcessingTimeWindowOperatorTest {
timerService.shutdown();
}
}
-
- @Test
- public void testEmitTrailingDataOnClose() {
- final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor();
- try {
- final CollectingOutput<Integer> out = new CollectingOutput<>();
- final Object lock = new Object();
- final StreamTask<?, ?> mockTask = createMockTaskWithTimer(timerService, lock);
-
- // the operator has a window time that is so long that it will not fire in this test
- final long oneYear = 365L * 24 * 60 * 60 * 1000;
- AccumulatingProcessingTimeWindowOperator<Integer, Integer, Integer> op =
- new AccumulatingProcessingTimeWindowOperator<>(
- validatingIdentityFunction, identitySelector,
- IntSerializer.INSTANCE, IntSerializer.INSTANCE,
- oneYear, oneYear);
-
- op.setup(mockTask, new StreamConfig(new Configuration()), out);
- op.open();
-
- List<Integer> data = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
- for (Integer i : data) {
- synchronized (lock) {
- op.processElement(new StreamRecord<Integer>(i));
- }
- }
-
- synchronized (lock) {
- op.close();
- }
- op.dispose();
-
- // get and verify the result
- List<Integer> result = out.getElements();
- Collections.sort(result);
- assertEquals(data, result);
- }
- catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- finally {
- timerService.shutdown();
- }
- }
-
- @Test
- public void testPropagateExceptionsFromClose() {
- final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor();
- try {
- final CollectingOutput<Integer> out = new CollectingOutput<>();
- final Object lock = new Object();
- final StreamTask<?, ?> mockTask = createMockTaskWithTimer(timerService, lock);
-
- WindowFunction<Integer, Integer, Integer, TimeWindow> failingFunction = new FailingFunction(100);
-
- // the operator has a window time that is so long that it will not fire in this test
- final long hundredYears = 100L * 365 * 24 * 60 * 60 * 1000;
- AccumulatingProcessingTimeWindowOperator<Integer, Integer, Integer> op =
- new AccumulatingProcessingTimeWindowOperator<>(
- failingFunction, identitySelector,
- IntSerializer.INSTANCE, IntSerializer.INSTANCE,
- hundredYears, hundredYears);
-
- op.setup(mockTask, new StreamConfig(new Configuration()), out);
- op.open();
-
- for (int i = 0; i < 150; i++) {
- synchronized (lock) {
- op.processElement(new StreamRecord<Integer>(i));
- }
- }
-
- try {
- synchronized (lock) {
- op.close();
- }
- fail("This should fail with an exception");
- }
- catch (Exception e) {
- assertTrue(
- e.getMessage().contains("Artificial Test Exception") ||
- (e.getCause() != null && e.getCause().getMessage().contains("Artificial Test Exception")));
- }
- op.dispose();
- }
- catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- finally {
- timerService.shutdown();
- }
- }
-
@Test
public void checkpointRestoreWithPendingWindowTumbling() {
final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor();
@@ -607,16 +514,19 @@ public class AccumulatingAlignedProcessingTimeWindowOperatorTest {
Thread.sleep(1);
}
- synchronized (lock) {
- op.close();
- }
- op.dispose();
+
+ out2.waitForNElements(numElements - resultAtSnapshot.size(), 60_000);
// get and verify the result
List<Integer> finalResult = new ArrayList<>(resultAtSnapshot);
finalResult.addAll(out2.getElements());
assertEquals(numElements, finalResult.size());
+ synchronized (lock) {
+ op.close();
+ }
+ op.dispose();
+
Collections.sort(finalResult);
for (int i = 0; i < numElements; i++) {
assertEquals(i, finalResult.get(i).intValue());
http://git-wip-us.apache.org/repos/asf/flink/blob/c4e5a55f/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AggregatingAlignedProcessingTimeWindowOperatorTest.java
----------------------------------------------------------------------
diff --git a/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AggregatingAlignedProcessingTimeWindowOperatorTest.java b/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AggregatingAlignedProcessingTimeWindowOperatorTest.java
index b3e59e5..611916e 100644
--- a/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AggregatingAlignedProcessingTimeWindowOperatorTest.java
+++ b/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AggregatingAlignedProcessingTimeWindowOperatorTest.java
@@ -269,14 +269,17 @@ public class AggregatingAlignedProcessingTimeWindowOperatorTest {
Thread.sleep(1);
}
+ out.waitForNElements(numElements, 60_000);
+
+ // get and verify the result
+ List<Tuple2<Integer, Integer>> result = out.getElements();
+ assertEquals(numElements, result.size());
+
synchronized (lock) {
op.close();
}
op.dispose();
- // get and verify the result
- List<Tuple2<Integer, Integer>> result = out.getElements();
- assertEquals(numElements, result.size());
Collections.sort(result, tupleComparator);
for (int i = 0; i < numElements; i++) {
@@ -335,13 +338,15 @@ public class AggregatingAlignedProcessingTimeWindowOperatorTest {
Thread.sleep(1);
}
+ out.waitForNElements(numWindows, 60_000);
+
+ List<Tuple2<Integer, Integer>> result = out.getElements();
+
synchronized (lock) {
op.close();
}
op.dispose();
-
- List<Tuple2<Integer, Integer>> result = out.getElements();
-
+
// we have ideally one element per window. we may have more, when we emitted a value into the
// successive window (corner case), so we can have twice the number of elements, in the worst case.
assertTrue(result.size() >= numWindows && result.size() <= 2 * numWindows);
@@ -487,57 +492,6 @@ public class AggregatingAlignedProcessingTimeWindowOperatorTest {
timerService.shutdown();
}
}
-
- @Test
- public void testEmitTrailingDataOnClose() {
- final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor();
- try {
- final CollectingOutput<Tuple2<Integer, Integer>> out = new CollectingOutput<>();
- final Object lock = new Object();
- final StreamTask<?, ?> mockTask = createMockTaskWithTimer(timerService, lock);
-
- // the operator has a window time that is so long that it will not fire in this test
- final long oneYear = 365L * 24 * 60 * 60 * 1000;
- AggregatingProcessingTimeWindowOperator<Integer, Tuple2<Integer, Integer>> op =
- new AggregatingProcessingTimeWindowOperator<>(
- sumFunction, fieldOneSelector,
- IntSerializer.INSTANCE, tupleSerializer, oneYear, oneYear);
-
- op.setup(mockTask, new StreamConfig(new Configuration()), out);
- op.open();
-
- List<Integer> data = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
- for (Integer i : data) {
- synchronized (lock) {
- StreamRecord<Tuple2<Integer, Integer>> next = new StreamRecord<>(new Tuple2<>(i, i));
- op.setKeyContextElement(next);
- op.processElement(next);
- }
- }
-
- synchronized (lock) {
- op.close();
- }
- op.dispose();
-
- // get and verify the result
- List<Tuple2<Integer, Integer>> result = out.getElements();
- assertEquals(data.size(), result.size());
-
- Collections.sort(result, tupleComparator);
- for (int i = 0; i < data.size(); i++) {
- assertEquals(data.get(i), result.get(i).f0);
- assertEquals(data.get(i), result.get(i).f1);
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- finally {
- timerService.shutdown();
- }
- }
@Test
public void testPropagateExceptionsFromProcessElement() {
@@ -667,16 +621,18 @@ public class AggregatingAlignedProcessingTimeWindowOperatorTest {
Thread.sleep(1);
}
- synchronized (lock) {
- op.close();
- }
- op.dispose();
+ out2.waitForNElements(numElements - resultAtSnapshot.size(), 60_000);
// get and verify the result
List<Tuple2<Integer, Integer>> finalResult = new ArrayList<>(resultAtSnapshot);
finalResult.addAll(out2.getElements());
assertEquals(numElements, finalResult.size());
+ synchronized (lock) {
+ op.close();
+ }
+ op.dispose();
+
Collections.sort(finalResult, tupleComparator);
for (int i = 0; i < numElements; i++) {
assertEquals(i, finalResult.get(i).f0.intValue());
@@ -812,7 +768,7 @@ public class AggregatingAlignedProcessingTimeWindowOperatorTest {
public void testKeyValueStateInWindowFunctionTumbling() {
final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor();
try {
- final long hundredYears = 100L * 365 * 24 * 60 * 60 * 1000;
+ final long thirtySeconds = 30_000;
final CollectingOutput<Tuple2<Integer, Integer>> out = new CollectingOutput<>();
final Object lock = new Object();
@@ -823,7 +779,7 @@ public class AggregatingAlignedProcessingTimeWindowOperatorTest {
AggregatingProcessingTimeWindowOperator<Integer, Tuple2<Integer, Integer>> op =
new AggregatingProcessingTimeWindowOperator<>(
new StatefulFunction(), fieldOneSelector,
- IntSerializer.INSTANCE, tupleSerializer, hundredYears, hundredYears);
+ IntSerializer.INSTANCE, tupleSerializer, thirtySeconds, thirtySeconds);
op.setup(mockTask, createTaskConfig(fieldOneSelector, IntSerializer.INSTANCE), out);
op.open();
@@ -841,10 +797,10 @@ public class AggregatingAlignedProcessingTimeWindowOperatorTest {
op.setKeyContextElement(next2);
op.processElement(next2);
}
-
- op.close();
}
+ out.waitForNElements(2, 60_000);
+
List<Tuple2<Integer, Integer>> result = out.getElements();
assertEquals(2, result.size());
@@ -854,7 +810,8 @@ public class AggregatingAlignedProcessingTimeWindowOperatorTest {
assertEquals(10, StatefulFunction.globalCounts.get(1).intValue());
assertEquals(10, StatefulFunction.globalCounts.get(2).intValue());
-
+
+ op.close();
op.dispose();
}
catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/flink/blob/c4e5a55f/flink-streaming-java/src/test/java/org/apache/flink/streaming/util/OneInputStreamOperatorTestHarness.java
----------------------------------------------------------------------
diff --git a/flink-streaming-java/src/test/java/org/apache/flink/streaming/util/OneInputStreamOperatorTestHarness.java b/flink-streaming-java/src/test/java/org/apache/flink/streaming/util/OneInputStreamOperatorTestHarness.java
index 01f95bc..258e30a 100644
--- a/flink-streaming-java/src/test/java/org/apache/flink/streaming/util/OneInputStreamOperatorTestHarness.java
+++ b/flink-streaming-java/src/test/java/org/apache/flink/streaming/util/OneInputStreamOperatorTestHarness.java
@@ -111,10 +111,11 @@ public class OneInputStreamOperatorTestHarness<IN, OUT> {
}
/**
- * Calls close on the operator.
+ * Calls close and dispose on the operator.
*/
public void close() throws Exception {
operator.close();
+ operator.dispose();
}
public void processElement(StreamRecord<IN> element) throws Exception {
[4/5] flink git commit: [FLINK-3292]Fix for Bug in flink-jdbc. Not
all JDBC drivers supported
Posted by se...@apache.org.
[FLINK-3292]Fix for Bug in flink-jdbc. Not all JDBC drivers supported
This closes #1551
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/d97fcda6
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/d97fcda6
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/d97fcda6
Branch: refs/heads/master
Commit: d97fcda6635b6821ac3f61c39e0fa156bc7c7fd4
Parents: 83b88c2
Author: Subhobrata Dey <sb...@gmail.com>
Authored: Wed Jan 27 17:00:37 2016 -0500
Committer: Stephan Ewen <se...@apache.org>
Committed: Thu Jan 28 14:37:53 2016 +0100
----------------------------------------------------------------------
.../flink/api/java/io/jdbc/JDBCInputFormat.java | 16 +++++++++++++++-
.../flink/api/java/io/jdbc/JDBCInputFormatTest.java | 3 +++
.../api/java/io/jdbc/JDBCOutputFormatTest.java | 3 +++
3 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/d97fcda6/flink-batch-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCInputFormat.java
----------------------------------------------------------------------
diff --git a/flink-batch-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCInputFormat.java b/flink-batch-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCInputFormat.java
index eb3ac31..84eb309 100644
--- a/flink-batch-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCInputFormat.java
+++ b/flink-batch-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCInputFormat.java
@@ -58,6 +58,8 @@ public class JDBCInputFormat<OUT extends Tuple> extends RichInputFormat<OUT, Inp
private String drivername;
private String dbURL;
private String query;
+ private int resultSetType;
+ private int resultSetConcurrency;
private transient Connection dbConn;
private transient Statement statement;
@@ -82,7 +84,7 @@ public class JDBCInputFormat<OUT extends Tuple> extends RichInputFormat<OUT, Inp
public void open(InputSplit ignored) throws IOException {
try {
establishConnection();
- statement = dbConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ statement = dbConn.createStatement(resultSetType, resultSetConcurrency);
resultSet = statement.executeQuery(query);
} catch (SQLException se) {
close();
@@ -308,6 +310,8 @@ public class JDBCInputFormat<OUT extends Tuple> extends RichInputFormat<OUT, Inp
public JDBCInputFormatBuilder() {
this.format = new JDBCInputFormat();
+ this.format.resultSetType = ResultSet.TYPE_FORWARD_ONLY;
+ this.format.resultSetConcurrency = ResultSet.CONCUR_READ_ONLY;
}
public JDBCInputFormatBuilder setUsername(String username) {
@@ -335,6 +339,16 @@ public class JDBCInputFormat<OUT extends Tuple> extends RichInputFormat<OUT, Inp
return this;
}
+ public JDBCInputFormatBuilder setResultSetType(int resultSetType) {
+ format.resultSetType = resultSetType;
+ return this;
+ }
+
+ public JDBCInputFormatBuilder setResultSetConcurrency(int resultSetConcurrency) {
+ format.resultSetConcurrency = resultSetConcurrency;
+ return this;
+ }
+
public JDBCInputFormat finish() {
if (format.username == null) {
LOG.info("Username was not supplied separately.");
http://git-wip-us.apache.org/repos/asf/flink/blob/d97fcda6/flink-batch-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCInputFormatTest.java
----------------------------------------------------------------------
diff --git a/flink-batch-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCInputFormatTest.java b/flink-batch-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCInputFormatTest.java
index b76f8b8..b1d43df 100644
--- a/flink-batch-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCInputFormatTest.java
+++ b/flink-batch-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCInputFormatTest.java
@@ -23,6 +23,8 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
+import java.sql.ResultSet;
+
import org.junit.Assert;
@@ -172,6 +174,7 @@ public class JDBCInputFormatTest {
.setDrivername("org.apache.derby.jdbc.EmbeddedDriver")
.setDBUrl("jdbc:derby:memory:ebookshop")
.setQuery("select * from books")
+ .setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)
.finish();
jdbcInputFormat.open(null);
Tuple5 tuple = new Tuple5();
http://git-wip-us.apache.org/repos/asf/flink/blob/d97fcda6/flink-batch-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormatTest.java
----------------------------------------------------------------------
diff --git a/flink-batch-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormatTest.java b/flink-batch-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormatTest.java
index 7d004f9..276518b 100644
--- a/flink-batch-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormatTest.java
+++ b/flink-batch-connectors/flink-jdbc/src/test/java/org/apache/flink/api/java/io/jdbc/JDBCOutputFormatTest.java
@@ -23,6 +23,7 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
+import java.sql.ResultSet;
import org.junit.Assert;
@@ -199,6 +200,7 @@ public class JDBCOutputFormatTest {
.setDrivername(driverPath)
.setDBUrl(dbUrl)
.setQuery("select * from " + sourceTable)
+ .setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)
.finish();
jdbcInputFormat.open(null);
@@ -215,6 +217,7 @@ public class JDBCOutputFormatTest {
.setDrivername(driverPath)
.setDBUrl(dbUrl)
.setQuery("select * from " + targetTable)
+ .setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)
.finish();
jdbcInputFormat.open(null);
[5/5] flink git commit: [FLINK-3265] [rabbitmq] Fix concurrency bug
in RabbitMQ
Posted by se...@apache.org.
[FLINK-3265] [rabbitmq] Fix concurrency bug in RabbitMQ
This closes #1534
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/6b01a890
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/6b01a890
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/6b01a890
Branch: refs/heads/master
Commit: 6b01a89020f2de3f7710cf72336291b1e8ca8562
Parents: d97fcda
Author: Robert Metzger <rm...@apache.org>
Authored: Thu Jan 21 12:22:21 2016 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Thu Jan 28 14:43:03 2016 +0100
----------------------------------------------------------------------
.../connectors/rabbitmq/RMQSource.java | 4 +-
.../connectors/rabbitmq/RMQSourceTest.java | 79 ++++++++++++++++++++
.../source/MessageAcknowledgingSourceBase.java | 51 +++++++------
...ltipleIdsMessageAcknowledgingSourceBase.java | 24 +++---
4 files changed, 124 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/6b01a890/flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSource.java
----------------------------------------------------------------------
diff --git a/flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSource.java b/flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSource.java
index 09bb07c..59bc057 100644
--- a/flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSource.java
+++ b/flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSource.java
@@ -196,7 +196,9 @@ public class RMQSource<OUT> extends MultipleIdsMessageAcknowledgingSourceBase<OU
continue;
}
}
- sessionIds.add(deliveryTag);
+ synchronized (sessionIdsPerSnapshot) {
+ sessionIds.add(deliveryTag);
+ }
}
ctx.collect(result);
http://git-wip-us.apache.org/repos/asf/flink/blob/6b01a890/flink-streaming-connectors/flink-connector-rabbitmq/src/test/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSourceTest.java
----------------------------------------------------------------------
diff --git a/flink-streaming-connectors/flink-connector-rabbitmq/src/test/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSourceTest.java b/flink-streaming-connectors/flink-connector-rabbitmq/src/test/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSourceTest.java
index aa19e5d..0a3de84 100644
--- a/flink-streaming-connectors/flink-connector-rabbitmq/src/test/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSourceTest.java
+++ b/flink-streaming-connectors/flink-connector-rabbitmq/src/test/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSourceTest.java
@@ -23,6 +23,7 @@ import com.rabbitmq.client.Envelope;
import com.rabbitmq.client.QueueingConsumer;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.common.typeutils.base.StringSerializer;
+import org.apache.flink.api.java.tuple.Tuple1;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.java.typeutils.TypeExtractor;
import org.apache.flink.configuration.Configuration;
@@ -31,6 +32,7 @@ import org.apache.flink.streaming.api.functions.source.SourceFunction;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.util.serialization.DeserializationSchema;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -103,6 +105,83 @@ public class RMQSourceTest {
sourceThread.join();
}
+ /**
+ * Make sure concurrent access to snapshotState() and notifyCheckpointComplete() don't cause
+ * an issue.
+ *
+ * Without proper synchronization, the test will fail with a concurrent modification exception
+ *
+ */
+ @Test
+ public void testConcurrentAccess() throws Exception {
+ source.autoAck = false;
+ sourceThread.start();
+
+ final Tuple1<Throwable> error = new Tuple1<>(null);
+
+ Thread.sleep(5);
+
+ Thread snapshotThread = new Thread(new Runnable() {
+ public long id = 0;
+
+ @Override
+ public void run() {
+ while (!Thread.interrupted()) {
+ try {
+ source.snapshotState(id++, 0);
+ } catch (Exception e) {
+ error.f0 = e;
+ break; // stop thread
+ }
+ }
+ }
+ });
+
+ Thread notifyThread = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ while (!Thread.interrupted()) {
+ try {
+ // always remove all checkpoints
+ source.notifyCheckpointComplete(Long.MAX_VALUE);
+ } catch (Exception e) {
+ error.f0 = e;
+ break; // stop thread
+ }
+ }
+ }
+ });
+
+ snapshotThread.start();
+ notifyThread.start();
+
+ long deadline = System.currentTimeMillis() + 1000L;
+ while(System.currentTimeMillis() < deadline) {
+ if(!snapshotThread.isAlive()) {
+ notifyThread.interrupt();
+ break;
+ }
+ if(!notifyThread.isAlive()) {
+ snapshotThread.interrupt();
+ break;
+ }
+ Thread.sleep(10);
+ }
+ if(snapshotThread.isAlive()) {
+ snapshotThread.interrupt();
+ snapshotThread.join();
+ }
+ if(notifyThread.isAlive()) {
+ notifyThread.interrupt();
+ notifyThread.join();
+ }
+ if(error.f0 != null) {
+ error.f0.printStackTrace();
+ Assert.fail("Test failed with " + error.f0.getClass().getCanonicalName());
+ }
+
+ }
+
@Test
public void testCheckpointing() throws Exception {
source.autoAck = false;
http://git-wip-us.apache.org/repos/asf/flink/blob/6b01a890/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/MessageAcknowledgingSourceBase.java
----------------------------------------------------------------------
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/MessageAcknowledgingSourceBase.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/MessageAcknowledgingSourceBase.java
index 4385884..2f865d1 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/MessageAcknowledgingSourceBase.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/MessageAcknowledgingSourceBase.java
@@ -76,6 +76,7 @@ import org.slf4j.LoggerFactory;
* @param <Type> The type of the messages created by the source.
* @param <UId> The type of unique IDs which may be used to acknowledge elements.
*/
+@SuppressWarnings("SynchronizeOnNonFinalField")
public abstract class MessageAcknowledgingSourceBase<Type, UId>
extends RichSourceFunction<Type>
implements Checkpointed<SerializedCheckpointData[]>, CheckpointNotifier {
@@ -166,41 +167,45 @@ public abstract class MessageAcknowledgingSourceBase<Type, UId>
LOG.debug("Snapshotting state. Messages: {}, checkpoint id: {}, timestamp: {}",
idsForCurrentCheckpoint, checkpointId, checkpointTimestamp);
- pendingCheckpoints.addLast(new Tuple2<>(checkpointId, idsForCurrentCheckpoint));
+ synchronized (pendingCheckpoints) {
+ pendingCheckpoints.addLast(new Tuple2<>(checkpointId, idsForCurrentCheckpoint));
- idsForCurrentCheckpoint = new ArrayList<>(64);
+ idsForCurrentCheckpoint = new ArrayList<>(64);
- return SerializedCheckpointData.fromDeque(pendingCheckpoints, idSerializer);
+ return SerializedCheckpointData.fromDeque(pendingCheckpoints, idSerializer);
+ }
}
@Override
public void restoreState(SerializedCheckpointData[] state) throws Exception {
- pendingCheckpoints = SerializedCheckpointData.toDeque(state, idSerializer);
- // build a set which contains all processed ids. It may be used to check if we have
- // already processed an incoming message.
- for (Tuple2<Long, List<UId>> checkpoint : pendingCheckpoints) {
- idsProcessedButNotAcknowledged.addAll(checkpoint.f1);
+ synchronized (pendingCheckpoints) {
+ pendingCheckpoints = SerializedCheckpointData.toDeque(state, idSerializer);
+ // build a set which contains all processed ids. It may be used to check if we have
+ // already processed an incoming message.
+ for (Tuple2<Long, List<UId>> checkpoint : pendingCheckpoints) {
+ idsProcessedButNotAcknowledged.addAll(checkpoint.f1);
+ }
}
}
@Override
public void notifyCheckpointComplete(long checkpointId) throws Exception {
LOG.debug("Committing Messages externally for checkpoint {}", checkpointId);
-
- for (Iterator<Tuple2<Long, List<UId>>> iter = pendingCheckpoints.iterator(); iter.hasNext();) {
- Tuple2<Long, List<UId>> checkpoint = iter.next();
- long id = checkpoint.f0;
-
- if (id <= checkpointId) {
- LOG.trace("Committing Messages with following IDs {}", checkpoint.f1);
- acknowledgeIDs(checkpointId, checkpoint.f1);
- // remove deduplication data
- idsProcessedButNotAcknowledged.removeAll(checkpoint.f1);
- // remove checkpoint data
- iter.remove();
- }
- else {
- break;
+ synchronized (pendingCheckpoints) {
+ for (Iterator<Tuple2<Long, List<UId>>> iter = pendingCheckpoints.iterator(); iter.hasNext(); ) {
+ Tuple2<Long, List<UId>> checkpoint = iter.next();
+ long id = checkpoint.f0;
+
+ if (id <= checkpointId) {
+ LOG.trace("Committing Messages with following IDs {}", checkpoint.f1);
+ acknowledgeIDs(checkpointId, checkpoint.f1);
+ // remove deduplication data
+ idsProcessedButNotAcknowledged.removeAll(checkpoint.f1);
+ // remove checkpoint data
+ iter.remove();
+ } else {
+ break;
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/6b01a890/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/MultipleIdsMessageAcknowledgingSourceBase.java
----------------------------------------------------------------------
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/MultipleIdsMessageAcknowledgingSourceBase.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/MultipleIdsMessageAcknowledgingSourceBase.java
index c097066..4709759 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/MultipleIdsMessageAcknowledgingSourceBase.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/source/MultipleIdsMessageAcknowledgingSourceBase.java
@@ -107,14 +107,16 @@ public abstract class MultipleIdsMessageAcknowledgingSourceBase<Type, UId, Sessi
*/
protected final void acknowledgeIDs(long checkpointId, List<UId> uniqueIds) {
LOG.debug("Acknowledging ids for checkpoint {}", checkpointId);
- Iterator<Tuple2<Long, List<SessionId>>> iterator = sessionIdsPerSnapshot.iterator();
- while (iterator.hasNext()) {
- final Tuple2<Long, List<SessionId>> next = iterator.next();
- long id = next.f0;
- if (id <= checkpointId) {
- acknowledgeSessionIDs(next.f1);
- // remove ids for this session
- iterator.remove();
+ synchronized (sessionIdsPerSnapshot) {
+ Iterator<Tuple2<Long, List<SessionId>>> iterator = sessionIdsPerSnapshot.iterator();
+ while (iterator.hasNext()) {
+ final Tuple2<Long, List<SessionId>> next = iterator.next();
+ long id = next.f0;
+ if (id <= checkpointId) {
+ acknowledgeSessionIDs(next.f1);
+ // remove ids for this session
+ iterator.remove();
+ }
}
}
}
@@ -132,8 +134,10 @@ public abstract class MultipleIdsMessageAcknowledgingSourceBase<Type, UId, Sessi
@Override
public SerializedCheckpointData[] snapshotState(long checkpointId, long checkpointTimestamp) throws Exception {
- sessionIdsPerSnapshot.add(new Tuple2<>(checkpointId, sessionIds));
- sessionIds = new ArrayList<>(64);
+ synchronized (sessionIdsPerSnapshot) {
+ sessionIdsPerSnapshot.add(new Tuple2<>(checkpointId, sessionIds));
+ sessionIds = new ArrayList<>(64);
+ }
return super.snapshotState(checkpointId, checkpointTimestamp);
}
}
[3/5] flink git commit: [FLINK-3242] Also Set User-specified
StateBackend without Checkpointing
Posted by se...@apache.org.
[FLINK-3242] Also Set User-specified StateBackend without Checkpointing
Before, the user-specified StateBackedn would not be set when generating the
JobGraph if checkpointing was disabled.
This closes #1516
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/83b88c2c
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/83b88c2c
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/83b88c2c
Branch: refs/heads/master
Commit: 83b88c2c606f0d36bc04a7250629eb00516af919
Parents: f6d2ce9
Author: Aljoscha Krettek <al...@gmail.com>
Authored: Mon Jan 18 11:53:31 2016 +0100
Committer: Stephan Ewen <se...@apache.org>
Committed: Thu Jan 28 14:30:28 2016 +0100
----------------------------------------------------------------------
.../api/graph/StreamingJobGraphGenerator.java | 2 +-
.../runtime/state/StateBackendITCase.java | 134 +++++++++++++++++++
2 files changed, 135 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/83b88c2c/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamingJobGraphGenerator.java
----------------------------------------------------------------------
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamingJobGraphGenerator.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamingJobGraphGenerator.java
index 50c6a15..56b16a4 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamingJobGraphGenerator.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/graph/StreamingJobGraphGenerator.java
@@ -317,10 +317,10 @@ public class StreamingJobGraphGenerator {
final CheckpointConfig ceckpointCfg = streamGraph.getCheckpointConfig();
+ config.setStateBackend(streamGraph.getStateBackend());
config.setCheckpointingEnabled(ceckpointCfg.isCheckpointingEnabled());
if (ceckpointCfg.isCheckpointingEnabled()) {
config.setCheckpointMode(ceckpointCfg.getCheckpointingMode());
- config.setStateBackend(streamGraph.getStateBackend());
}
else {
// the "at-least-once" input handler is slightly cheaper (in the absence of checkpoints),
http://git-wip-us.apache.org/repos/asf/flink/blob/83b88c2c/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/state/StateBackendITCase.java
----------------------------------------------------------------------
diff --git a/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/state/StateBackendITCase.java b/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/state/StateBackendITCase.java
new file mode 100644
index 0000000..cdfef85
--- /dev/null
+++ b/flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/state/StateBackendITCase.java
@@ -0,0 +1,134 @@
+/*
+ * 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://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.runtime.state;
+
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.client.JobExecutionException;
+import org.apache.flink.runtime.execution.Environment;
+import org.apache.flink.runtime.state.KvState;
+import org.apache.flink.runtime.state.StateBackend;
+import org.apache.flink.runtime.state.StateHandle;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.util.StreamingMultipleProgramsTestBase;
+import org.junit.Test;
+
+import java.io.Serializable;
+
+import static org.junit.Assert.assertTrue;
+
+
+public class StateBackendITCase extends StreamingMultipleProgramsTestBase {
+
+ /**
+ * Verify that the user-specified state backend is used even if checkpointing is disabled.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testStateBackendWithoutCheckpointing() throws Exception {
+
+ StreamExecutionEnvironment see = StreamExecutionEnvironment.getExecutionEnvironment();
+ see.setParallelism(1);
+
+ see.setNumberOfExecutionRetries(0);
+ see.setStateBackend(new FailingStateBackend());
+
+
+ see.fromElements(new Tuple2<>("Hello", 1))
+ .keyBy(0)
+ .map(new RichMapFunction<Tuple2<String,Integer>, String>() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void open(Configuration parameters) throws Exception {
+ super.open(parameters);
+ getRuntimeContext().getKeyValueState("test", String.class, "");
+ }
+
+ @Override
+ public String map(Tuple2<String, Integer> value) throws Exception {
+ return value.f0;
+ }
+ })
+ .print();
+
+ boolean caughtSuccess = false;
+ try {
+ see.execute();
+ } catch (JobExecutionException e) {
+ if (e.getCause() instanceof SuccessException) {
+ caughtSuccess = true;
+ } else {
+ throw e;
+ }
+ }
+
+ assertTrue(caughtSuccess);
+ }
+
+
+ public static class FailingStateBackend extends StateBackend<FailingStateBackend> {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void initializeForJob(Environment env) throws Exception {
+ throw new SuccessException();
+ }
+
+ @Override
+ public void disposeAllStateForCurrentJob() throws Exception {
+
+ }
+
+ @Override
+ public void close() throws Exception {
+
+ }
+
+ @Override
+ public <K, V> KvState<K, V, FailingStateBackend> createKvState(String stateId,
+ String stateName,
+ TypeSerializer<K> keySerializer,
+ TypeSerializer<V> valueSerializer,
+ V defaultValue) throws Exception {
+ return null;
+ }
+
+ @Override
+ public CheckpointStateOutputStream createCheckpointStateOutputStream(long checkpointID,
+ long timestamp) throws Exception {
+ return null;
+ }
+
+ @Override
+ public <S extends Serializable> StateHandle<S> checkpointStateSerializable(S state,
+ long checkpointID,
+ long timestamp) throws Exception {
+ return null;
+ }
+ }
+
+ static final class SuccessException extends Exception {
+ private static final long serialVersionUID = -9218191172606739598L;
+ }
+
+}
[2/5] flink git commit: [FLINK-3196] InputStream should be closed in
EnvironmentInformation#getRevisionInformation()
Posted by se...@apache.org.
[FLINK-3196] InputStream should be closed in EnvironmentInformation#getRevisionInformation()
This closes #1552
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/f6d2ce91
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/f6d2ce91
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/f6d2ce91
Branch: refs/heads/master
Commit: f6d2ce91eccb92ab7e4c63dd799d7e0f6a9df9bf
Parents: c4e5a55
Author: smarthi <sm...@apache.org>
Authored: Tue Jan 26 23:42:33 2016 -0500
Committer: Stephan Ewen <se...@apache.org>
Committed: Thu Jan 28 14:21:32 2016 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/flink/optimizer/util/Utils.java | 4 ++--
.../org/apache/flink/runtime/util/EnvironmentInformation.java | 6 ++----
2 files changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/f6d2ce91/flink-optimizer/src/main/java/org/apache/flink/optimizer/util/Utils.java
----------------------------------------------------------------------
diff --git a/flink-optimizer/src/main/java/org/apache/flink/optimizer/util/Utils.java b/flink-optimizer/src/main/java/org/apache/flink/optimizer/util/Utils.java
index 1099028..97dd917 100644
--- a/flink-optimizer/src/main/java/org/apache/flink/optimizer/util/Utils.java
+++ b/flink-optimizer/src/main/java/org/apache/flink/optimizer/util/Utils.java
@@ -104,10 +104,10 @@ public final class Utils {
throw new RuntimeException("Unrecognized type: " + typeInfo);
}
- return new RuntimeComparatorFactory<T>(comparator);
+ return new RuntimeComparatorFactory<>(comparator);
}
- private static final boolean[] getSortOrders(FieldList keys, boolean[] orders) {
+ private static boolean[] getSortOrders(FieldList keys, boolean[] orders) {
if (orders == null) {
orders = new boolean[keys.size()];
Arrays.fill(orders, true);
http://git-wip-us.apache.org/repos/asf/flink/blob/f6d2ce91/flink-runtime/src/main/java/org/apache/flink/runtime/util/EnvironmentInformation.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/util/EnvironmentInformation.java b/flink-runtime/src/main/java/org/apache/flink/runtime/util/EnvironmentInformation.java
index 1cb403b..3b75b9f 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/util/EnvironmentInformation.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/util/EnvironmentInformation.java
@@ -60,8 +60,7 @@ public class EnvironmentInformation {
public static RevisionInformation getRevisionInformation() {
String revision = UNKNOWN;
String commitDate = UNKNOWN;
- try {
- InputStream propFile = EnvironmentInformation.class.getClassLoader().getResourceAsStream(".version.properties");
+ try (InputStream propFile = EnvironmentInformation.class.getClassLoader().getResourceAsStream(".version.properties")) {
if (propFile != null) {
Properties properties = new Properties();
properties.load(propFile);
@@ -70,8 +69,7 @@ public class EnvironmentInformation {
revision = propRevision != null ? propRevision : UNKNOWN;
commitDate = propCommitDate != null ? propCommitDate : UNKNOWN;
}
- }
- catch (Throwable t) {
+ } catch (Throwable t) {
if (LOG.isDebugEnabled()) {
LOG.debug("Cannot determine code revision: Unable to read version property file.", t);
} else {