Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
pulsar
提交
b06ea5e8
pulsar
项目概览
apache
/
pulsar
通知
129
Star
40
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
pulsar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
b06ea5e8
编写于
8月 29, 2020
作者:
B
Boyang Jerry Peng
提交者:
GitHub
8月 29, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rewind ByteBuffers Read/Written to Function's state store (#7929)
Co-authored-by:
N
Jerry Peng
<
jerryp@splunk.com
>
上级
1443c6b0
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
10 addition
and
4 deletion
+10
-4
pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/state/StateContextImpl.java
...che/pulsar/functions/instance/state/StateContextImpl.java
+10
-4
未找到文件。
pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/state/StateContextImpl.java
浏览文件 @
b06ea5e8
...
@@ -18,19 +18,17 @@
...
@@ -18,19 +18,17 @@
*/
*/
package
org.apache.pulsar.functions.instance.state
;
package
org.apache.pulsar.functions.instance.state
;
import
static
java
.
nio
.
charset
.
StandardCharsets
.
UTF_8
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.buffer.Unpooled
;
import
io.netty.buffer.Unpooled
;
import
io.netty.util.ReferenceCountUtil
;
import
io.netty.util.ReferenceCountUtil
;
import
org.apache.bookkeeper.api.kv.Table
;
import
org.apache.bookkeeper.api.kv.Table
;
import
org.apache.bookkeeper.api.kv.options.DeleteOption
;
import
org.apache.bookkeeper.api.kv.options.Option
;
import
org.apache.bookkeeper.api.kv.options.Options
;
import
org.apache.bookkeeper.api.kv.options.Options
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.CompletableFuture
;
import
static
java
.
nio
.
charset
.
StandardCharsets
.
UTF_8
;
/**
/**
* This class accumulates the state updates from one function.
* This class accumulates the state updates from one function.
*
*
...
@@ -55,6 +53,10 @@ public class StateContextImpl implements StateContext {
...
@@ -55,6 +53,10 @@ public class StateContextImpl implements StateContext {
@Override
@Override
public
CompletableFuture
<
Void
>
put
(
String
key
,
ByteBuffer
value
)
{
public
CompletableFuture
<
Void
>
put
(
String
key
,
ByteBuffer
value
)
{
if
(
value
!=
null
)
{
if
(
value
!=
null
)
{
// Set position to off the buffer to the beginning.
// If a user used an operation like ByteBuffer.allocate(4).putInt(count) to create a ByteBuffer to store to the state store
// the position of the buffer will be at the end and nothing will be written to table service
value
.
position
(
0
);
return
table
.
put
(
return
table
.
put
(
Unpooled
.
wrappedBuffer
(
key
.
getBytes
(
UTF_8
)),
Unpooled
.
wrappedBuffer
(
key
.
getBytes
(
UTF_8
)),
Unpooled
.
wrappedBuffer
(
value
));
Unpooled
.
wrappedBuffer
(
value
));
...
@@ -81,6 +83,10 @@ public class StateContextImpl implements StateContext {
...
@@ -81,6 +83,10 @@ public class StateContextImpl implements StateContext {
if
(
data
!=
null
)
{
if
(
data
!=
null
)
{
ByteBuffer
result
=
ByteBuffer
.
allocate
(
data
.
readableBytes
());
ByteBuffer
result
=
ByteBuffer
.
allocate
(
data
.
readableBytes
());
data
.
readBytes
(
result
);
data
.
readBytes
(
result
);
// Set position to off the buffer to the beginning, since the position after the read is going to be end of the buffer
// If we do not rewind to the begining here, users will have to explicitly do this in their function code
// in order to use any of the ByteBuffer operations
result
.
position
(
0
);
return
result
;
return
result
;
}
}
return
null
;
return
null
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录