Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
43b8e57b
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,发现更多精彩内容 >>
提交
43b8e57b
编写于
11月 08, 2015
作者:
G
Gyula Fora
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-2924] [streaming] Improve compacting logic
上级
c254bda3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
20 addition
and
10 deletion
+20
-10
flink-contrib/flink-streaming-contrib/src/main/java/org/apache/flink/contrib/streaming/state/LazyDbKvState.java
...g/apache/flink/contrib/streaming/state/LazyDbKvState.java
+16
-9
flink-contrib/flink-streaming-contrib/src/main/java/org/apache/flink/contrib/streaming/state/MySqlAdapter.java
...rg/apache/flink/contrib/streaming/state/MySqlAdapter.java
+2
-0
flink-contrib/flink-streaming-contrib/src/test/java/org/apache/flink/contrib/streaming/state/DerbyAdapter.java
...rg/apache/flink/contrib/streaming/state/DerbyAdapter.java
+2
-1
未找到文件。
flink-contrib/flink-streaming-contrib/src/main/java/org/apache/flink/contrib/streaming/state/LazyDbKvState.java
浏览文件 @
43b8e57b
...
...
@@ -96,6 +96,8 @@ public class LazyDbKvState<K, V> implements KvState<K, V, DbStateBackend>, Check
private
long
nextTs
;
private
Map
<
Long
,
Long
>
completedCheckpoints
=
new
HashMap
<>();
private
long
lastCompactedTs
;
// ------------------------------------------------------
/**
...
...
@@ -104,14 +106,15 @@ public class LazyDbKvState<K, V> implements KvState<K, V, DbStateBackend>, Check
*/
public
LazyDbKvState
(
String
kvStateId
,
boolean
compact
,
ShardedConnection
cons
,
DbBackendConfig
conf
,
TypeSerializer
<
K
>
keySerializer
,
TypeSerializer
<
V
>
valueSerializer
,
V
defaultValue
)
throws
IOException
{
this
(
kvStateId
,
compact
,
cons
,
conf
,
keySerializer
,
valueSerializer
,
defaultValue
,
1
);
this
(
kvStateId
,
compact
,
cons
,
conf
,
keySerializer
,
valueSerializer
,
defaultValue
,
1
,
0
);
}
/**
* Initialize the {@link LazyDbKvState} from a snapshot.
*/
public
LazyDbKvState
(
String
kvStateId
,
boolean
compact
,
ShardedConnection
cons
,
final
DbBackendConfig
conf
,
TypeSerializer
<
K
>
keySerializer
,
TypeSerializer
<
V
>
valueSerializer
,
V
defaultValue
,
long
nextTs
)
TypeSerializer
<
K
>
keySerializer
,
TypeSerializer
<
V
>
valueSerializer
,
V
defaultValue
,
long
nextTs
,
long
lastCompactedTs
)
throws
IOException
{
this
.
kvStateId
=
kvStateId
;
...
...
@@ -130,6 +133,7 @@ public class LazyDbKvState<K, V> implements KvState<K, V, DbStateBackend>, Check
this
.
sqlRetrySleep
=
conf
.
getSleepBetweenSqlRetries
();
this
.
nextTs
=
nextTs
;
this
.
lastCompactedTs
=
lastCompactedTs
;
this
.
cache
=
new
StateCache
(
conf
.
getKvCacheSize
(),
conf
.
getNumElementsToEvict
());
...
...
@@ -192,7 +196,7 @@ public class LazyDbKvState<K, V> implements KvState<K, V, DbStateBackend>, Check
nextTs
=
timestamp
+
1
;
completedCheckpoints
.
put
(
checkpointId
,
timestamp
);
return
new
DbKvStateSnapshot
<
K
,
V
>(
kvStateId
,
timestamp
);
return
new
DbKvStateSnapshot
<
K
,
V
>(
kvStateId
,
timestamp
,
lastCompactedTs
);
}
/**
...
...
@@ -245,8 +249,9 @@ public class LazyDbKvState<K, V> implements KvState<K, V, DbStateBackend>, Check
if
(
compactEvery
>
0
&&
compact
&&
checkpointId
%
compactEvery
==
0
)
{
try
{
for
(
Connection
c
:
connections
.
connections
())
{
dbAdapter
.
compactKvStates
(
kvStateId
,
c
,
0
,
ts
);
dbAdapter
.
compactKvStates
(
kvStateId
,
c
,
lastCompactedTs
,
ts
);
}
lastCompactedTs
=
ts
;
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"State succesfully compacted for {}."
,
kvStateId
);
}
...
...
@@ -294,10 +299,10 @@ public class LazyDbKvState<K, V> implements KvState<K, V, DbStateBackend>, Check
}
/**
* Snapshot that stores a specific checkpoint
id
and state id, and also
* Snapshot that stores a specific checkpoint
timestamp
and state id, and also
* rolls back the database to that point upon restore. The rollback is done
* by removing all state checkpoints that have
id
s between the checkpoint
* and recovery
id
.
* by removing all state checkpoints that have
timestamp
s between the checkpoint
* and recovery
timestamp
.
*
*/
private
static
class
DbKvStateSnapshot
<
K
,
V
>
implements
KvStateSnapshot
<
K
,
V
,
DbStateBackend
>
{
...
...
@@ -306,10 +311,12 @@ public class LazyDbKvState<K, V> implements KvState<K, V, DbStateBackend>, Check
private
final
String
kvStateId
;
private
final
long
checkpointTimestamp
;
private
final
long
lastCompactedTimestamp
;
public
DbKvStateSnapshot
(
String
kvStateId
,
long
checkpointTimestamp
)
{
public
DbKvStateSnapshot
(
String
kvStateId
,
long
checkpointTimestamp
,
long
lastCompactedTs
)
{
this
.
checkpointTimestamp
=
checkpointTimestamp
;
this
.
kvStateId
=
kvStateId
;
this
.
lastCompactedTimestamp
=
lastCompactedTs
;
}
@Override
...
...
@@ -346,7 +353,7 @@ public class LazyDbKvState<K, V> implements KvState<K, V, DbStateBackend>, Check
// Restore the KvState
LazyDbKvState
<
K
,
V
>
restored
=
new
LazyDbKvState
<
K
,
V
>(
kvStateId
,
cleanup
,
stateBackend
.
getConnections
(),
stateBackend
.
getConfiguration
(),
keySerializer
,
valueSerializer
,
defaultValue
,
recoveryTimestamp
);
defaultValue
,
recoveryTimestamp
,
lastCompactedTimestamp
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"KV state({},{}) restored."
,
kvStateId
,
recoveryTimestamp
);
...
...
flink-contrib/flink-streaming-contrib/src/main/java/org/apache/flink/contrib/streaming/state/MySqlAdapter.java
浏览文件 @
43b8e57b
...
...
@@ -141,6 +141,7 @@ public class MySqlAdapter implements DbAdapter {
return
"SELECT v"
+
" FROM kvstate_"
+
stateId
+
" WHERE k = ?"
+
" AND timestamp <= ?"
+
" ORDER BY timestamp DESC LIMIT 1"
;
}
...
...
@@ -148,6 +149,7 @@ public class MySqlAdapter implements DbAdapter {
public
byte
[]
lookupKey
(
String
stateId
,
PreparedStatement
lookupStatement
,
byte
[]
key
,
long
lookupTs
)
throws
SQLException
{
lookupStatement
.
setBytes
(
1
,
key
);
lookupStatement
.
setLong
(
2
,
lookupTs
);
ResultSet
res
=
lookupStatement
.
executeQuery
();
...
...
flink-contrib/flink-streaming-contrib/src/test/java/org/apache/flink/contrib/streaming/state/DerbyAdapter.java
浏览文件 @
43b8e57b
...
...
@@ -98,7 +98,8 @@ public class DerbyAdapter extends MySqlAdapter {
validateStateId
(
stateId
);
return
"SELECT v "
+
"FROM kvstate_"
+
stateId
+
" WHERE k = ? "
+
"ORDER BY timestamp DESC"
;
+
" AND timestamp <= ?"
+
" ORDER BY timestamp DESC"
;
}
@Override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录