Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
e4d05f72
F
flink
项目概览
doujutun3207
/
flink
与 Fork 源项目一致
从无法访问的项目Fork
通知
24
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flink
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e4d05f72
编写于
1月 29, 2016
作者:
S
Stephan Ewen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-3312] Add accessors for various state types to RuntimeContext
上级
6f755961
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
187 addition
and
52 deletion
+187
-52
flink-contrib/flink-streaming-contrib/src/test/java/org/apache/flink/contrib/streaming/state/DBStateCheckpointingTest.java
...ink/contrib/streaming/state/DBStateCheckpointingTest.java
+3
-3
flink-core/src/main/java/org/apache/flink/api/common/functions/RuntimeContext.java
...org/apache/flink/api/common/functions/RuntimeContext.java
+101
-16
flink-core/src/main/java/org/apache/flink/api/common/functions/util/AbstractRuntimeUDFContext.java
.../api/common/functions/util/AbstractRuntimeUDFContext.java
+17
-4
flink-streaming-connectors/flink-connector-kafka-base/src/test/java/org/apache/flink/streaming/connectors/kafka/testutils/MockRuntimeContext.java
...eaming/connectors/kafka/testutils/MockRuntimeContext.java
+18
-5
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamingRuntimeContext.java
...link/streaming/api/operators/StreamingRuntimeContext.java
+32
-7
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AccumulatingAlignedProcessingTimeWindowOperatorTest.java
.../AccumulatingAlignedProcessingTimeWindowOperatorTest.java
+5
-8
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AggregatingAlignedProcessingTimeWindowOperatorTest.java
...g/AggregatingAlignedProcessingTimeWindowOperatorTest.java
+5
-3
flink-streaming-scala/src/main/scala/org/apache/flink/streaming/api/scala/function/StatefulFunction.scala
...flink/streaming/api/scala/function/StatefulFunction.scala
+1
-1
flink-tests/src/test/java/org/apache/flink/test/checkpointing/EventTimeWindowCheckpointingITCase.java
...est/checkpointing/EventTimeWindowCheckpointingITCase.java
+1
-1
flink-tests/src/test/java/org/apache/flink/test/checkpointing/PartitionedStateCheckpointingITCase.java
...st/checkpointing/PartitionedStateCheckpointingITCase.java
+3
-3
flink-tests/src/test/java/org/apache/flink/test/checkpointing/StreamCheckpointingITCase.java
...e/flink/test/checkpointing/StreamCheckpointingITCase.java
+1
-1
未找到文件。
flink-contrib/flink-streaming-contrib/src/test/java/org/apache/flink/contrib/streaming/state/DBStateCheckpointingTest.java
浏览文件 @
e4d05f72
...
...
@@ -209,7 +209,7 @@ public class DBStateCheckpointingTest extends StreamFaultToleranceTestBase {
failurePos
=
(
new
Random
().
nextLong
()
%
(
failurePosMax
-
failurePosMin
))
+
failurePosMin
;
count
=
0
;
sum
=
getRuntimeContext
().
get
Partitioned
State
(
sum
=
getRuntimeContext
().
getState
(
new
ValueStateDescriptor
<>(
"my_state"
,
0L
,
LongSerializer
.
INSTANCE
));
}
...
...
@@ -237,11 +237,11 @@ public class DBStateCheckpointingTest extends StreamFaultToleranceTestBase {
@Override
public
void
open
(
Configuration
parameters
)
throws
IOException
{
aCounts
=
getRuntimeContext
().
get
Partitioned
State
(
aCounts
=
getRuntimeContext
().
getState
(
new
ValueStateDescriptor
<>(
"a"
,
NonSerializableLong
.
of
(
0L
),
new
KryoSerializer
<>(
NonSerializableLong
.
class
,
new
ExecutionConfig
())));
bCounts
=
getRuntimeContext
().
get
Partitioned
State
(
bCounts
=
getRuntimeContext
().
getState
(
new
ValueStateDescriptor
<>(
"b"
,
0L
,
LongSerializer
.
INSTANCE
));
}
...
...
flink-core/src/main/java/org/apache/flink/api/common/functions/RuntimeContext.java
浏览文件 @
e4d05f72
...
...
@@ -31,10 +31,13 @@ import org.apache.flink.api.common.accumulators.Histogram;
import
org.apache.flink.api.common.accumulators.IntCounter
;
import
org.apache.flink.api.common.accumulators.LongCounter
;
import
org.apache.flink.api.common.cache.DistributedCache
;
import
org.apache.flink.api.common.state.ListState
;
import
org.apache.flink.api.common.state.ListStateDescriptor
;
import
org.apache.flink.api.common.state.OperatorState
;
import
org.apache.flink.api.common.state.ReducingState
;
import
org.apache.flink.api.common.state.ReducingStateDescriptor
;
import
org.apache.flink.api.common.state.ValueState
;
import
org.apache.flink.api.common.state.State
;
import
org.apache.flink.api.common.state.StateDescriptor
;
import
org.apache.flink.api.common.state.ValueStateDescriptor
;
import
org.apache.flink.api.common.typeinfo.TypeInformation
;
/**
...
...
@@ -188,13 +191,15 @@ public interface RuntimeContext {
*/
DistributedCache
getDistributedCache
();
// --------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Methods for accessing state
// ------------------------------------------------------------------------
/**
* Gets
the partitioned state, which is only accessible if the function is executed on
*
a KeyedStream. When interacting with the state only the instance bound to the key of th
e
*
element currently processed by the function is changed
.
* Each
operator may maintain
multiple partitioned states, addressed with different names.
* Gets
a handle to the system's key/value state. The key/value state is only accessible
*
if the function is executed on a KeyedStream. On each access, the state exposes the valu
e
*
for the the key of the element currently processed by the function
.
* Each
function may have
multiple partitioned states, addressed with different names.
*
* <p>Because the scope of each value is the key of the currently processed element,
* and the elements are distributed by the Flink runtime, the system can transparently
...
...
@@ -213,31 +218,111 @@ public interface RuntimeContext {
* private ValueState<Long> count;
*
* public void open(Configuration cfg) {
* state = getRuntimeContext().get
Partitioned
State(
* state = getRuntimeContext().getState(
* new ValueStateDescriptor<Long>("count", 0L, LongSerializer.INSTANCE));
* }
*
* public Tuple2<MyType, Long> map(MyType value) {
* long count = state.value();
* state.update(value
+ 1
);
* long count = state.value()
+ 1
;
* state.update(value);
* return new Tuple2<>(value, count);
* }
* });
* }</pre>
*
* @param stateProperties The descriptor defining the properties of the stats.
*
* @param <T> The type of value stored in the state.
*
* @return The partitioned state object.
*
* @throws UnsupportedOperationException Thrown, if no partitioned state is available for the
* function (function is not part of a KeyedStream).
*/
<
T
>
ValueState
<
T
>
getState
(
ValueStateDescriptor
<
T
>
stateProperties
);
/**
* Gets a handle to the system's key/value list state. This state is similar to the state
* accessed via {@link #getState(ValueStateDescriptor)}, but is optimized for state that
* holds lists. One can adds elements to the list, or retrieve the list as a whole.
*
* <p>This state is only accessible if the function is executed on a KeyedStream.
*
* <pre>{@code
* DataStream<MyType> stream = ...;
* KeyedStream<MyType> keyedStream = stream.keyBy("id");
*
* keyedStream.map(new RichFlatMapFunction<MyType, List<MyType>>() {
*
* private ListState<MyType> state;
*
* public void open(Configuration cfg) {
* state = getRuntimeContext().getListState(
* new ListStateDescriptor<>("myState", MyType.class));
* }
*
* public void flatMap(MyType value, Collector<MyType> out) {
* if (value.isDivider()) {
* for (MyType t : state.get()) {
* out.collect(t);
* }
* } else {
* state.add(value);
* }
* }
* });
* }</pre>
*
* @param stateDescriptor The StateDescriptor that contains the name and type of the
* state that is being accessed.
* @param stateProperties The descriptor defining the properties of the stats.
*
* @param <
S> The type of
the state.
* @param <
T> The type of value stored in
the state.
*
* @return The partitioned state object.
*
* @throws UnsupportedOperationException Thrown, if no partitioned state is available for the
* function (function is not part os a KeyedStream).
*/
<
S
extends
State
>
S
getPartitionedState
(
StateDescriptor
<
S
>
stateDescriptor
);
<
T
>
ListState
<
T
>
getListState
(
ListStateDescriptor
<
T
>
stateProperties
);
/**
* Gets a handle to the system's key/value list state. This state is similar to the state
* accessed via {@link #getState(ValueStateDescriptor)}, but is optimized for state that
* aggregates values.
*
* <p>This state is only accessible if the function is executed on a KeyedStream.
*
* <pre>{@code
* DataStream<MyType> stream = ...;
* KeyedStream<MyType> keyedStream = stream.keyBy("id");
*
* keyedStream.map(new RichMapFunction<MyType, List<MyType>>() {
*
* private ReducingState<Long> sum;
*
* public void open(Configuration cfg) {
* state = getRuntimeContext().getReducingState(
* new ReducingStateDescriptor<>("sum", MyType.class, 0L, (a, b) -> a + b));
* }
*
* public Tuple2<MyType, Long> map(MyType value) {
* sum.add(value.count());
* return new Tuple2<>(value, sum.get());
* }
* });
*
* }</pre>
*
* @param stateProperties The descriptor defining the properties of the stats.
*
* @param <T> The type of value stored in the state.
*
* @return The partitioned state object.
*
* @throws UnsupportedOperationException Thrown, if no partitioned state is available for the
* function (function is not part of a KeyedStream).
*/
<
T
>
ReducingState
<
T
>
getReducingState
(
ReducingStateDescriptor
<
T
>
stateProperties
);
/**
* Gets the key/value state, which is only accessible if the function is executed on
* a KeyedStream. Upon calling {@link ValueState#value()}, the key/value state will
...
...
@@ -292,7 +377,7 @@ public interface RuntimeContext {
* @throws UnsupportedOperationException Thrown, if no key/value state is available for the
* function (function is not part os a KeyedStream).
*
* @deprecated Use the more expressive {@link #get
PartitionedState(
StateDescriptor)} instead.
* @deprecated Use the more expressive {@link #get
State(Value
StateDescriptor)} instead.
*/
@Deprecated
<
S
>
OperatorState
<
S
>
getKeyValueState
(
String
name
,
Class
<
S
>
stateType
,
S
defaultState
);
...
...
@@ -344,7 +429,7 @@ public interface RuntimeContext {
* @throws UnsupportedOperationException Thrown, if no key/value state is available for the
* function (function is not part os a KeyedStream).
*
* @deprecated Use the more expressive {@link #get
PartitionedState(
StateDescriptor)} instead.
* @deprecated Use the more expressive {@link #get
State(Value
StateDescriptor)} instead.
*/
@Deprecated
<
S
>
OperatorState
<
S
>
getKeyValueState
(
String
name
,
TypeInformation
<
S
>
stateType
,
S
defaultState
);
...
...
flink-core/src/main/java/org/apache/flink/api/common/functions/util/AbstractRuntimeUDFContext.java
浏览文件 @
e4d05f72
...
...
@@ -34,10 +34,13 @@ import org.apache.flink.api.common.accumulators.IntCounter;
import
org.apache.flink.api.common.accumulators.LongCounter
;
import
org.apache.flink.api.common.cache.DistributedCache
;
import
org.apache.flink.api.common.functions.RuntimeContext
;
import
org.apache.flink.api.common.state.ListState
;
import
org.apache.flink.api.common.state.ListStateDescriptor
;
import
org.apache.flink.api.common.state.OperatorState
;
import
org.apache.flink.api.common.state.ReducingState
;
import
org.apache.flink.api.common.state.ReducingStateDescriptor
;
import
org.apache.flink.api.common.state.ValueState
;
import
org.apache.flink.api.common.state.State
;
import
org.apache.flink.api.common.state.StateDescriptor
;
import
org.apache.flink.api.common.state.ValueStateDescriptor
;
import
org.apache.flink.api.common.typeinfo.TypeInformation
;
import
org.apache.flink.core.fs.Path
;
...
...
@@ -172,10 +175,21 @@ public abstract class AbstractRuntimeUDFContext implements RuntimeContext {
}
@Override
public
<
S
extends
State
>
S
getPartitionedState
(
StateDescriptor
<
S
>
stateDescriptor
)
{
public
<
T
>
ValueState
<
T
>
getState
(
ValueStateDescriptor
<
T
>
stateProperties
)
{
throw
new
UnsupportedOperationException
(
"This state is only accessible by functions executed on a KeyedStream"
);
}
@Override
public
<
T
>
ListState
<
T
>
getListState
(
ListStateDescriptor
<
T
>
stateProperties
)
{
throw
new
UnsupportedOperationException
(
"This state is only accessible by functions executed on a KeyedStream"
);
}
@Override
public
<
T
>
ReducingState
<
T
>
getReducingState
(
ReducingStateDescriptor
<
T
>
stateProperties
)
{
throw
new
UnsupportedOperationException
(
"This state is only accessible by functions executed on a KeyedStream"
);
}
@Override
...
...
@@ -191,5 +205,4 @@ public abstract class AbstractRuntimeUDFContext implements RuntimeContext {
throw
new
UnsupportedOperationException
(
"This state is only accessible by functions executed on a KeyedStream"
);
}
}
flink-streaming-connectors/flink-connector-kafka-base/src/test/java/org/apache/flink/streaming/connectors/kafka/testutils/MockRuntimeContext.java
浏览文件 @
e4d05f72
...
...
@@ -26,10 +26,13 @@ import org.apache.flink.api.common.accumulators.IntCounter;
import
org.apache.flink.api.common.accumulators.LongCounter
;
import
org.apache.flink.api.common.cache.DistributedCache
;
import
org.apache.flink.api.common.functions.BroadcastVariableInitializer
;
import
org.apache.flink.api.common.state.ListState
;
import
org.apache.flink.api.common.state.ListStateDescriptor
;
import
org.apache.flink.api.common.state.OperatorState
;
import
org.apache.flink.api.common.state.State
;
import
org.apache.flink.api.common.state.StateDescriptor
;
import
org.apache.flink.api.common.state.
Reducing
State
;
import
org.apache.flink.api.common.state.
Reducing
StateDescriptor
;
import
org.apache.flink.api.common.state.ValueState
;
import
org.apache.flink.api.common.state.ValueStateDescriptor
;
import
org.apache.flink.api.common.typeinfo.TypeInformation
;
import
org.apache.flink.runtime.memory.MemoryManager
;
import
org.apache.flink.runtime.operators.testutils.MockEnvironment
;
...
...
@@ -54,7 +57,7 @@ public class MockRuntimeContext extends StreamingRuntimeContext {
this
.
indexOfThisSubtask
=
indexOfThisSubtask
;
}
private
static
class
MockStreamOperator
extends
AbstractStreamOperator
{
private
static
class
MockStreamOperator
extends
AbstractStreamOperator
<
Integer
>
{
private
static
final
long
serialVersionUID
=
-
1153976702711944427L
;
@Override
...
...
@@ -154,12 +157,22 @@ public class MockRuntimeContext extends StreamingRuntimeContext {
}
@Override
public
<
S
>
Value
State
<
S
>
getKeyValueState
(
String
name
,
TypeInformation
<
S
>
stateType
,
S
defaultState
)
{
public
<
S
>
Operator
State
<
S
>
getKeyValueState
(
String
name
,
TypeInformation
<
S
>
stateType
,
S
defaultState
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
<
S
extends
State
>
S
getPartitionedState
(
StateDescriptor
<
S
>
stateDescriptor
)
{
public
<
T
>
ValueState
<
T
>
getState
(
ValueStateDescriptor
<
T
>
stateProperties
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
<
T
>
ListState
<
T
>
getListState
(
ListStateDescriptor
<
T
>
stateProperties
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
<
T
>
ReducingState
<
T
>
getReducingState
(
ReducingStateDescriptor
<
T
>
stateProperties
)
{
throw
new
UnsupportedOperationException
();
}
}
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamingRuntimeContext.java
浏览文件 @
e4d05f72
...
...
@@ -21,9 +21,12 @@ package org.apache.flink.streaming.api.operators;
import
org.apache.flink.api.common.accumulators.Accumulator
;
import
org.apache.flink.api.common.functions.BroadcastVariableInitializer
;
import
org.apache.flink.api.common.functions.util.AbstractRuntimeUDFContext
;
import
org.apache.flink.api.common.state.ListState
;
import
org.apache.flink.api.common.state.ListStateDescriptor
;
import
org.apache.flink.api.common.state.OperatorState
;
import
org.apache.flink.api.common.state.State
;
import
org.apache.flink.api.common.state.StateDescriptor
;
import
org.apache.flink.api.common.state.ReducingState
;
import
org.apache.flink.api.common.state.ReducingStateDescriptor
;
import
org.apache.flink.api.common.state.ValueState
;
import
org.apache.flink.api.common.state.ValueStateDescriptor
;
import
org.apache.flink.api.common.typeinfo.TypeInformation
;
import
org.apache.flink.api.java.typeutils.TypeExtractor
;
...
...
@@ -106,11 +109,32 @@ public class StreamingRuntimeContext extends AbstractRuntimeUDFContext {
// ------------------------------------------------------------------------
@Override
public
<
S
extends
State
>
S
getPartitionedState
(
StateDescriptor
<
S
>
stateDescriptor
)
{
public
<
T
>
ValueState
<
T
>
getState
(
ValueStateDescriptor
<
T
>
stateProperties
)
{
requireNonNull
(
stateProperties
,
"The state properties must not be null"
);
try
{
return
operator
.
getPartitionedState
(
state
Descriptor
);
return
operator
.
getPartitionedState
(
state
Properties
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Error while getting state."
,
e
);
throw
new
RuntimeException
(
"Error while getting state"
,
e
);
}
}
@Override
public
<
T
>
ListState
<
T
>
getListState
(
ListStateDescriptor
<
T
>
stateProperties
)
{
requireNonNull
(
stateProperties
,
"The state properties must not be null"
);
try
{
return
operator
.
getPartitionedState
(
stateProperties
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Error while getting state"
,
e
);
}
}
@Override
public
<
T
>
ReducingState
<
T
>
getReducingState
(
ReducingStateDescriptor
<
T
>
stateProperties
)
{
requireNonNull
(
stateProperties
,
"The state properties must not be null"
);
try
{
return
operator
.
getPartitionedState
(
stateProperties
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Error while getting state"
,
e
);
}
}
...
...
@@ -138,8 +162,9 @@ public class StreamingRuntimeContext extends AbstractRuntimeUDFContext {
requireNonNull
(
name
,
"The name of the state must not be null"
);
requireNonNull
(
stateType
,
"The state type information must not be null"
);
ValueStateDescriptor
<
S
>
stateDesc
=
new
ValueStateDescriptor
<>(
name
,
defaultState
,
stateType
.
createSerializer
(
getExecutionConfig
()));
return
getPartitionedState
(
stateDesc
);
ValueStateDescriptor
<
S
>
stateProps
=
new
ValueStateDescriptor
<>(
name
,
defaultState
,
stateType
.
createSerializer
(
getExecutionConfig
()));
return
getState
(
stateProps
);
}
// ------------------ expose (read only) relevant information from the stream config -------- //
...
...
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AccumulatingAlignedProcessingTimeWindowOperatorTest.java
浏览文件 @
e4d05f72
...
...
@@ -21,7 +21,8 @@ package org.apache.flink.streaming.runtime.operators.windowing;
import
org.apache.flink.api.common.ExecutionConfig
;
import
org.apache.flink.api.common.TaskInfo
;
import
org.apache.flink.api.common.accumulators.Accumulator
;
import
org.apache.flink.api.common.state.OperatorState
;
import
org.apache.flink.api.common.state.ValueState
;
import
org.apache.flink.api.common.state.ValueStateDescriptor
;
import
org.apache.flink.api.common.typeutils.TypeSerializer
;
import
org.apache.flink.api.common.typeutils.base.IntSerializer
;
import
org.apache.flink.api.common.typeutils.base.StringSerializer
;
...
...
@@ -521,11 +522,6 @@ public class AccumulatingAlignedProcessingTimeWindowOperatorTest {
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
());
...
...
@@ -761,12 +757,13 @@ public class AccumulatingAlignedProcessingTimeWindowOperatorTest {
// get "volatile" style access to entries
static
final
Map
<
Integer
,
Integer
>
globalCounts
=
new
ConcurrentHashMap
<>();
private
Operator
State
<
Integer
>
state
;
private
Value
State
<
Integer
>
state
;
@Override
public
void
open
(
Configuration
parameters
)
{
assertNotNull
(
getRuntimeContext
());
state
=
getRuntimeContext
().
getKeyValueState
(
"totalCount"
,
Integer
.
class
,
0
);
state
=
getRuntimeContext
().
getState
(
new
ValueStateDescriptor
<>(
"totalCount"
,
0
,
IntSerializer
.
INSTANCE
));
}
@Override
...
...
flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/operators/windowing/AggregatingAlignedProcessingTimeWindowOperatorTest.java
浏览文件 @
e4d05f72
...
...
@@ -23,7 +23,8 @@ import org.apache.flink.api.common.TaskInfo;
import
org.apache.flink.api.common.accumulators.Accumulator
;
import
org.apache.flink.api.common.functions.ReduceFunction
;
import
org.apache.flink.api.common.functions.RichReduceFunction
;
import
org.apache.flink.api.common.state.OperatorState
;
import
org.apache.flink.api.common.state.ValueState
;
import
org.apache.flink.api.common.state.ValueStateDescriptor
;
import
org.apache.flink.api.common.typeinfo.BasicTypeInfo
;
import
org.apache.flink.api.common.typeutils.TypeSerializer
;
import
org.apache.flink.api.common.typeutils.base.IntSerializer
;
...
...
@@ -934,7 +935,7 @@ public class AggregatingAlignedProcessingTimeWindowOperatorTest {
static
final
Map
<
Integer
,
Integer
>
globalCounts
=
new
ConcurrentHashMap
<>();
private
Operator
State
<
Integer
>
state
;
private
Value
State
<
Integer
>
state
;
@Override
public
void
open
(
Configuration
parameters
)
{
...
...
@@ -942,7 +943,8 @@ public class AggregatingAlignedProcessingTimeWindowOperatorTest {
// start with one, so the final count is correct and we test that we do not
// initialize with 0 always by default
state
=
getRuntimeContext
().
getKeyValueState
(
"totalCount"
,
Integer
.
class
,
1
);
state
=
getRuntimeContext
().
getState
(
new
ValueStateDescriptor
<>(
"totalCount"
,
1
,
IntSerializer
.
INSTANCE
));
}
@Override
...
...
flink-streaming-scala/src/main/scala/org/apache/flink/streaming/api/scala/function/StatefulFunction.scala
浏览文件 @
e4d05f72
...
...
@@ -46,6 +46,6 @@ trait StatefulFunction[I, O, S] extends RichFunction {
override
def
open
(
c
:
Configuration
)
=
{
val
info
=
new
ValueStateDescriptor
[
S
](
"state"
,
null
.
asInstanceOf
[
S
],
stateSerializer
)
state
=
getRuntimeContext
().
get
PartitionedState
[
ValueState
[
S
]]
(
info
)
state
=
getRuntimeContext
().
get
State
(
info
)
}
}
flink-tests/src/test/java/org/apache/flink/test/checkpointing/EventTimeWindowCheckpointingITCase.java
浏览文件 @
e4d05f72
...
...
@@ -223,7 +223,7 @@ public class EventTimeWindowCheckpointingITCase extends TestLogger {
public
void
open
(
Configuration
parameters
)
{
assertEquals
(
PARALLELISM
,
getRuntimeContext
().
getNumberOfParallelSubtasks
());
open
=
true
;
count
=
getRuntimeContext
().
get
Partitioned
State
(
count
=
getRuntimeContext
().
getState
(
new
ValueStateDescriptor
<>(
"count"
,
0
,
IntSerializer
.
INSTANCE
));
}
...
...
flink-tests/src/test/java/org/apache/flink/test/checkpointing/PartitionedStateCheckpointingITCase.java
浏览文件 @
e4d05f72
...
...
@@ -172,7 +172,7 @@ public class PartitionedStateCheckpointingITCase extends StreamFaultToleranceTes
failurePos
=
(
new
Random
().
nextLong
()
%
(
failurePosMax
-
failurePosMin
))
+
failurePosMin
;
count
=
0
;
sum
=
getRuntimeContext
().
get
Partitioned
State
(
sum
=
getRuntimeContext
().
getState
(
new
ValueStateDescriptor
<>(
"my_state"
,
0L
,
LongSerializer
.
INSTANCE
));
}
...
...
@@ -201,11 +201,11 @@ public class PartitionedStateCheckpointingITCase extends StreamFaultToleranceTes
@Override
public
void
open
(
Configuration
parameters
)
throws
IOException
{
aCounts
=
getRuntimeContext
().
get
Partitioned
State
(
aCounts
=
getRuntimeContext
().
getState
(
new
ValueStateDescriptor
<>(
"a"
,
NonSerializableLong
.
of
(
0L
),
new
KryoSerializer
<>(
NonSerializableLong
.
class
,
new
ExecutionConfig
())));
bCounts
=
getRuntimeContext
().
get
Partitioned
State
(
bCounts
=
getRuntimeContext
().
getState
(
new
ValueStateDescriptor
<>(
"b"
,
0L
,
LongSerializer
.
INSTANCE
));
}
...
...
flink-tests/src/test/java/org/apache/flink/test/checkpointing/StreamCheckpointingITCase.java
浏览文件 @
e4d05f72
...
...
@@ -255,7 +255,7 @@ public class StreamCheckpointingITCase extends StreamFaultToleranceTestBase {
failurePos
=
(
new
Random
().
nextLong
()
%
(
failurePosMax
-
failurePosMin
))
+
failurePosMin
;
count
=
0
;
pCount
=
getRuntimeContext
().
get
Partitioned
State
(
pCount
=
getRuntimeContext
().
getState
(
new
ValueStateDescriptor
<>(
"pCount"
,
0L
,
LongSerializer
.
INSTANCE
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录