zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (ZOOKEEPER-2765) modern C++ client
Date Wed, 17 May 2017 05:04:05 GMT

    [ https://issues.apache.org/jira/browse/ZOOKEEPER-2765?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16013530#comment-16013530
] 

ASF GitHub Bot commented on ZOOKEEPER-2765:
-------------------------------------------

Github user packysauce commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/234#discussion_r116910884
  
    --- Diff: src/contrib/cppclient/detail/BasicZookeeperClient.cpp ---
    @@ -0,0 +1,1112 @@
    +/**
    + * 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.
    + */
    +
    +#include "zeus/client/detail/BasicZookeeperClient.h"
    +#include <cstring>
    +
    +namespace facebook {
    +namespace zeus {
    +namespace client {
    +namespace detail {
    +
    +std::string BasicZookeeperClient::buildConnectionString(
    +    const std::vector<folly::SocketAddress>& servers,
    +    const std::string& chroot) {
    +  std::vector<std::string> hostPorts;
    +  for (const auto& server : servers) {
    +    hostPorts.push_back(folly::to<std::string>(
    +        server.getIPAddress().toFullyQualified(), ':', server.getPort()));
    +  }
    +  return folly::join(',', hostPorts) + chroot;
    +}
    +
    +Stat BasicZookeeperClient::convertStat(const ::Stat& s) {
    +  return Stat{s.czxid,
    +              s.mzxid,
    +              std::chrono::system_clock::time_point() +
    +                  std::chrono::milliseconds(s.ctime),
    +              std::chrono::system_clock::time_point() +
    +                  std::chrono::milliseconds(s.mtime),
    +              s.version,
    +              s.cversion,
    +              s.aversion,
    +              s.ephemeralOwner,
    +              s.dataLength,
    +              s.numChildren,
    +              s.pzxid};
    +}
    +
    +int BasicZookeeperClient::convertCreateMode(const CreateMode& m) {
    +  int flags = 0;
    +  if (m.isEphemeral) {
    +    flags |= ZOO_EPHEMERAL;
    +  }
    +  if (m.isSequential) {
    +    flags |= ZOO_SEQUENCE;
    +  }
    +  return flags;
    +}
    +
    +SessionState BasicZookeeperClient::convertStateType(int state) {
    +  if (state == ZOO_EXPIRED_SESSION_STATE) {
    +    return SessionState::EXPIRED;
    +  } else if (state == ZOO_AUTH_FAILED_STATE) {
    +    return SessionState::AUTH_FAILED;
    +  } else if (state == ZOO_CONNECTING_STATE) {
    +    return SessionState::CONNECTING;
    +  } else if (state == ZOO_ASSOCIATING_STATE) {
    +    return SessionState::ASSOCIATING;
    +  } else if (state == ZOO_CONNECTED_STATE) {
    +    return SessionState::CONNECTED;
    +  } else if (state == 0 || state == ZOO_NOTCONNECTED_STATE) {
    +    return SessionState::DISCONNECTED;
    +  } else if (state == ZOO_TIMED_OUT_STATE) {
    +    return SessionState::TIMED_OUT;
    +  } else {
    +    throw std::runtime_error(
    +        folly::to<std::string>("unrecognized ZK state ", state));
    +  }
    +}
    +
    +NodeEvent BasicZookeeperClient::convertWatchEventType(
    +    const char* path,
    +    int inType,
    +    int inState,
    +    size_t index) {
    +  WatchEventType type;
    +  if (inType == ZOO_CREATED_EVENT) {
    +    type = WatchEventType::CREATED;
    +  } else if (inType == ZOO_DELETED_EVENT) {
    +    type = WatchEventType::DELETED;
    +  } else if (inType == ZOO_CHANGED_EVENT) {
    +    type = WatchEventType::CHANGED;
    +  } else if (inType == ZOO_CHILD_EVENT) {
    +    type = WatchEventType::CHILD;
    +  } else if (inType == ZOO_SESSION_EVENT) {
    +    type = WatchEventType::SESSION;
    +  } else if (inType == ZOO_NOTWATCHING_EVENT) {
    +    type = WatchEventType::NOT_WATCHING;
    +  } else {
    +    throw std::runtime_error(
    +        folly::to<std::string>("unexpected watch event type ", inType));
    +  }
    +
    +  return NodeEvent{index, path, type, convertStateType(inState)};
    +}
    +
    +BasicZookeeperClient::BasicZookeeperClient(
    +    const std::string& connectionString,
    +    std::chrono::milliseconds sessionTimeout,
    +    const SessionToken* token,
    +    InitialWatches&& initialWatches)
    +    : initialWatches_(std::move(initialWatches)) {
    +  std::vector<const char*> dataWatchPaths;
    +  for (const auto& dataWatchPath : initialWatches_.getDataWatchPaths()) {
    +    dataWatchPaths.push_back(dataWatchPath.c_str());
    +  }
    +  std::vector<const char*> childWatchPaths;
    +  for (const auto& childWatchPath : initialWatches_.getChildWatchPaths()) {
    +    childWatchPaths.push_back(childWatchPath.c_str());
    +  }
    +
    +  std::unique_ptr<::clientid_t> clientid;
    +  if (token) {
    +    clientid = std::make_unique<::clientid_t>();
    +    clientid->client_id = token->sessionId;
    +    memcpy(clientid->passwd, token->passwd.data(), 16);
    +  }
    +
    +  folly::SharedMutex::WriteHolder g(zhLock_);
    +  zh_ = zookeeper_init_with_watches(
    --- End diff --
    
    This function does exist in the open source C client.


> modern C++ client
> -----------------
>
>                 Key: ZOOKEEPER-2765
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2765
>             Project: ZooKeeper
>          Issue Type: New Feature
>          Components: c client
>            Reporter: Edward Carter
>            Assignee: Edward Carter
>
> We should add a modern C++ (i.e. C++14, C++17, etc.) client library that wraps the existing
C client.  A future issue may replace the C client itself.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message