Github user uce commented on a diff in the pull request:
https://github.com/apache/flink/pull/1451#discussion_r47480476
--- Diff:
flink-streaming-connectors/flink-connector-kafka/src/main/java/org/apache/flink/streaming/connectors/kafka/internals/ZookeeperOffsetHandler.java
---
@@ -98,30 +97,42 @@ public void
seekFetcherToInitialOffsets(List<KafkaTopicPartitionLeader> partitio
@Override
public void close() throws IOException {
- zkClient.close();
+ curatorClient.close();
}
//
------------------------------------------------------------------------
// Communication with Zookeeper
//
------------------------------------------------------------------------
- public static void setOffsetInZooKeeper(ZkClient zkClient, String
groupId, String topic, int partition, long offset) {
- TopicAndPartition tap = new TopicAndPartition(topic, partition);
- ZKGroupTopicDirs topicDirs = new ZKGroupTopicDirs(groupId,
tap.topic());
- ZkUtils.updatePersistentPath(zkClient,
topicDirs.consumerOffsetDir() + "/" + tap.partition(), Long.toString(offset));
+ public static void setOffsetInZooKeeper(CuratorFramework curatorClient,
String groupId, String topic, int partition, long offset) throws Exception {
+ ZKGroupTopicDirs topicDirs = new ZKGroupTopicDirs(groupId,
topic);
+ String path = topicDirs.consumerOffsetDir() + "/" + partition;
+ ensureExists(curatorClient, path);
+ byte[] data = Long.toString(offset).getBytes();
+ curatorClient.setData().forPath(path, data);
}
- public static long getOffsetFromZooKeeper(ZkClient zkClient, String
groupId, String topic, int partition) {
- TopicAndPartition tap = new TopicAndPartition(topic, partition);
- ZKGroupTopicDirs topicDirs = new ZKGroupTopicDirs(groupId,
tap.topic());
-
- scala.Tuple2<Option<String>, Stat> data =
ZkUtils.readDataMaybeNull(zkClient,
- topicDirs.consumerOffsetDir() + "/" +
tap.partition());
-
- if (data._1().isEmpty()) {
+ public static long getOffsetFromZooKeeper(CuratorFramework
curatorClient, String groupId, String topic, int partition) throws Exception {
+ ZKGroupTopicDirs topicDirs = new ZKGroupTopicDirs(groupId,
topic);
+ String path = topicDirs.consumerOffsetDir() + "/" + partition;
+ ensureExists(curatorClient, path);
+ byte[] data = curatorClient.getData().forPath(path);
+ if(data == null) {
return OFFSET_NOT_SET;
} else {
- return Long.valueOf(data._1().get());
+ String asString = new String(data);
+ if(asString.length() == 0) {
+ return OFFSET_NOT_SET;
+ } else {
+ return Long.valueOf(asString);
+ }
+ }
+ }
+
+ private static void ensureExists(CuratorFramework curatorClient, String
path) throws Exception {
--- End diff --
There is a ensure method in `CuratorFramework`, which does something
similar in a retry loop.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---