diff --git hbase-native-client/connection/client-dispatcher.cc hbase-native-client/connection/client-dispatcher.cc index 0a03396..1ace99c 100644 --- hbase-native-client/connection/client-dispatcher.cc +++ hbase-native-client/connection/client-dispatcher.cc @@ -57,6 +57,4 @@ Future ClientDispatcher::operator()(std::unique_ptr arg) { Future ClientDispatcher::close() { return ClientDispatcherBase::close(); } -Future ClientDispatcher::close(Context *ctx) { - return ClientDispatcherBase::close(ctx); -} +Future ClientDispatcher::close(Context *ctx) { return ClientDispatcherBase::close(ctx); } diff --git hbase-native-client/connection/client-dispatcher.h hbase-native-client/connection/client-dispatcher.h index 67e604e..0489717 100644 --- hbase-native-client/connection/client-dispatcher.h +++ hbase-native-client/connection/client-dispatcher.h @@ -36,8 +36,7 @@ namespace hbase { * future. */ class ClientDispatcher - : public wangle::ClientDispatcherBase, Response> { + : public wangle::ClientDispatcherBase, Response> { public: /** Create a new ClientDispatcher */ ClientDispatcher(); diff --git hbase-native-client/connection/client-handler.cc hbase-native-client/connection/client-handler.cc index e445444..5a6dce2 100644 --- hbase-native-client/connection/client-handler.cc +++ hbase-native-client/connection/client-handler.cc @@ -41,8 +41,8 @@ ClientHandler::ClientHandler(std::string user_name) serde_(), once_flag_(std::make_unique()), resp_msgs_( - make_unique>>(5000)) {} + make_unique>>( + 5000)) {} void ClientHandler::read(Context *ctx, std::unique_ptr buf) { if (LIKELY(buf != nullptr)) { @@ -51,8 +51,7 @@ void ClientHandler::read(Context *ctx, std::unique_ptr buf) { ResponseHeader header; int used_bytes = serde_.ParseDelimited(buf.get(), &header); - LOG(INFO) << "Read ResponseHeader size=" << used_bytes - << " call_id=" << header.call_id() + LOG(INFO) << "Read ResponseHeader size=" << used_bytes << " call_id=" << header.call_id() << " has_exception=" << header.has_exception(); // Get the response protobuf from the map @@ -96,6 +95,5 @@ Future ClientHandler::write(Context *ctx, std::unique_ptr r) { // Now store the call id to response. resp_msgs_->insert(r->call_id(), r->resp_msg()); // Send the data down the pipeline. - return ctx->fireWrite( - serde_.Request(r->call_id(), r->method(), r->req_msg().get())); + return ctx->fireWrite(serde_.Request(r->call_id(), r->method(), r->req_msg().get())); } diff --git hbase-native-client/connection/client-handler.h hbase-native-client/connection/client-handler.h index 7306c9a..d860cc1 100644 --- hbase-native-client/connection/client-handler.h +++ hbase-native-client/connection/client-handler.h @@ -50,9 +50,9 @@ namespace hbase { * This class deals with sending the connection header and preamble * on first request. */ -class ClientHandler : public wangle::Handler, - Response, std::unique_ptr, - std::unique_ptr> { +class ClientHandler + : public wangle::Handler, Response, std::unique_ptr, + std::unique_ptr> { public: /** * Create the handler @@ -70,8 +70,7 @@ class ClientHandler : public wangle::Handler, /** * Write the data down the wire. */ - folly::Future write(Context *ctx, - std::unique_ptr r) override; + folly::Future write(Context *ctx, std::unique_ptr r) override; private: std::unique_ptr once_flag_; @@ -79,8 +78,7 @@ class ClientHandler : public wangle::Handler, RpcSerde serde_; // in flight requests - std::unique_ptr>> + std::unique_ptr>> resp_msgs_; }; } // namespace hbase diff --git hbase-native-client/connection/connection-factory.cc hbase-native-client/connection/connection-factory.cc index beec6d5..ff83212 100644 --- hbase-native-client/connection/connection-factory.cc +++ hbase-native-client/connection/connection-factory.cc @@ -26,13 +26,10 @@ using namespace folly; using namespace hbase; -ConnectionFactory::ConnectionFactory( - std::shared_ptr io_pool) - : io_pool_(io_pool), - pipeline_factory_(std::make_shared()) {} +ConnectionFactory::ConnectionFactory(std::shared_ptr io_pool) + : io_pool_(io_pool), pipeline_factory_(std::make_shared()) {} -std::shared_ptr> -ConnectionFactory::MakeBootstrap() { +std::shared_ptr> ConnectionFactory::MakeBootstrap() { auto client = std::make_shared>(); client->group(io_pool_); client->pipelineFactory(pipeline_factory_); @@ -40,8 +37,8 @@ ConnectionFactory::MakeBootstrap() { return client; } std::shared_ptr ConnectionFactory::Connect( - std::shared_ptr> client, - const std::string &hostname, int port) { + std::shared_ptr> client, const std::string &hostname, + int port) { // Yes this will block however it makes dealing with connection pool soooooo // much nicer. // TODO see about using shared promise for this. diff --git hbase-native-client/connection/connection-factory.h hbase-native-client/connection/connection-factory.h index 17d9941..da44c35 100644 --- hbase-native-client/connection/connection-factory.h +++ hbase-native-client/connection/connection-factory.h @@ -40,16 +40,14 @@ class ConnectionFactory { * Constructor. * There should only be one ConnectionFactory per client. */ - explicit ConnectionFactory( - std::shared_ptr io_pool); + explicit ConnectionFactory(std::shared_ptr io_pool); /** Default Desctructor */ virtual ~ConnectionFactory() = default; /** * Create a BootStrap from which a connection can be made. */ - virtual std::shared_ptr> - MakeBootstrap(); + virtual std::shared_ptr> MakeBootstrap(); /** * Connect a ClientBootstrap to a server and return the pipeline. diff --git hbase-native-client/connection/connection-id.h hbase-native-client/connection/connection-id.h index 62fe222..78b9780 100644 --- hbase-native-client/connection/connection-id.h +++ hbase-native-client/connection/connection-id.h @@ -21,9 +21,9 @@ #include "if/HBase.pb.h" #include "security/user.h" +#include #include #include -#include using hbase::pb::ServerName; using hbase::security::User; @@ -34,12 +34,11 @@ class ConnectionId { ConnectionId(const std::string &host, uint16_t port) : ConnectionId(host, port, User::defaultUser(), "") {} - ConnectionId(const std::string &host, uint16_t port, - std::shared_ptr user) + ConnectionId(const std::string &host, uint16_t port, std::shared_ptr user) : ConnectionId(host, port, user, "") {} - ConnectionId(const std::string &host, uint16_t port, - std::shared_ptr user, const std::string &service_name) + ConnectionId(const std::string &host, uint16_t port, std::shared_ptr user, + const std::string &service_name) : user_(user), service_name_(service_name), host_(host), port_(port) {} virtual ~ConnectionId() = default; @@ -66,11 +65,9 @@ struct ConnectionIdEquals { } private: - bool userEquals(const std::shared_ptr &lhs, - const std::shared_ptr &rhs) const { + bool userEquals(const std::shared_ptr &lhs, const std::shared_ptr &rhs) const { return lhs == nullptr ? rhs == nullptr - : (rhs == nullptr ? false : lhs->user_name() == - rhs->user_name()); + : (rhs == nullptr ? false : lhs->user_name() == rhs->user_name()); } }; diff --git hbase-native-client/connection/connection-pool-test.cc hbase-native-client/connection/connection-pool-test.cc index 4547b30..0930095 100644 --- hbase-native-client/connection/connection-pool-test.cc +++ hbase-native-client/connection/connection-pool-test.cc @@ -17,9 +17,9 @@ * */ -#include "connection/connection-id.h" #include "connection/connection-pool.h" #include "connection/connection-factory.h" +#include "connection/connection-id.h" #include "if/HBase.pb.h" #include "serde/server-name.h" @@ -37,12 +37,10 @@ using hbase::ConnectionId; class MockConnectionFactory : public ConnectionFactory { public: MockConnectionFactory() : ConnectionFactory(nullptr) {} - MOCK_METHOD0(MakeBootstrap, - std::shared_ptr>()); - MOCK_METHOD3(Connect, - std::shared_ptr( - std::shared_ptr>, - const std::string &hostname, int port)); + MOCK_METHOD0(MakeBootstrap, std::shared_ptr>()); + MOCK_METHOD3(Connect, std::shared_ptr( + std::shared_ptr>, + const std::string &hostname, int port)); }; class MockBootstrap : public wangle::ClientBootstrap {}; @@ -69,12 +67,8 @@ TEST(TestConnectionPool, TestOnlyCreateOnce) { auto mock_cf = std::make_shared(); uint32_t port{999}; - EXPECT_CALL((*mock_cf), Connect(_, _, _)) - .Times(1) - .WillRepeatedly(Return(mock_service)); - EXPECT_CALL((*mock_cf), MakeBootstrap()) - .Times(1) - .WillRepeatedly(Return(mock_boot)); + EXPECT_CALL((*mock_cf), Connect(_, _, _)).Times(1).WillRepeatedly(Return(mock_service)); + EXPECT_CALL((*mock_cf), MakeBootstrap()).Times(1).WillRepeatedly(Return(mock_boot)); ConnectionPool cp{mock_cf}; auto remote_id = std::make_shared(hostname, port); @@ -92,12 +86,8 @@ TEST(TestConnectionPool, TestOnlyCreateMultipleDispose) { auto mock_service = std::make_shared(); auto mock_cf = std::make_shared(); - EXPECT_CALL((*mock_cf), Connect(_, _, _)) - .Times(2) - .WillRepeatedly(Return(mock_service)); - EXPECT_CALL((*mock_cf), MakeBootstrap()) - .Times(2) - .WillRepeatedly(Return(mock_boot)); + EXPECT_CALL((*mock_cf), Connect(_, _, _)).Times(2).WillRepeatedly(Return(mock_service)); + EXPECT_CALL((*mock_cf), MakeBootstrap()).Times(2).WillRepeatedly(Return(mock_boot)); ConnectionPool cp{mock_cf}; { diff --git hbase-native-client/connection/connection-pool.cc hbase-native-client/connection/connection-pool.cc index ee14c9d..07518c5 100644 --- hbase-native-client/connection/connection-pool.cc +++ hbase-native-client/connection/connection-pool.cc @@ -33,8 +33,7 @@ using hbase::HBaseService; using folly::SharedMutexWritePriority; using folly::SocketAddress; -ConnectionPool::ConnectionPool( - std::shared_ptr io_executor) +ConnectionPool::ConnectionPool(std::shared_ptr io_executor) : cf_(std::make_shared(io_executor)), clients_(), connections_(), @@ -95,8 +94,7 @@ std::shared_ptr ConnectionPool::GetNewConnection( /* create new connection */ auto clientBootstrap = cf_->MakeBootstrap(); - auto dispatcher = - cf_->Connect(clientBootstrap, remote_id->host(), remote_id->port()); + auto dispatcher = cf_->Connect(clientBootstrap, remote_id->host(), remote_id->port()); auto conneciton = std::make_shared(remote_id, dispatcher); @@ -118,5 +116,4 @@ void ConnectionPool::Close(std::shared_ptr remote_id) { connections_.erase(found); } -void ConnectionPool::Close() { -} +void ConnectionPool::Close() {} diff --git hbase-native-client/connection/connection-pool.h hbase-native-client/connection/connection-pool.h index 5101c68..1f2a182 100644 --- hbase-native-client/connection/connection-pool.h +++ hbase-native-client/connection/connection-pool.h @@ -30,7 +30,6 @@ #include "connection/service.h" #include "if/HBase.pb.h" - using hbase::ConnectionId; using hbase::ConnectionIdEquals; using hbase::ConnectionIdHash; @@ -47,8 +46,7 @@ namespace hbase { class ConnectionPool { public: /** Create connection pool wit default connection factory */ - explicit ConnectionPool( - std::shared_ptr io_executor); + explicit ConnectionPool(std::shared_ptr io_executor); /** * Desctructor. @@ -67,8 +65,7 @@ class ConnectionPool { * Get a connection to the server name. Start time is ignored. * This can be a blocking operation for a short time. */ - std::shared_ptr GetConnection( - std::shared_ptr remote_id); + std::shared_ptr GetConnection(std::shared_ptr remote_id); /** * Close/remove a connection. @@ -81,18 +78,14 @@ class ConnectionPool { void Close(); private: - std::shared_ptr GetCachedConnection( - std::shared_ptr remote_id); - std::shared_ptr GetNewConnection( - std::shared_ptr remote_id); + std::shared_ptr GetCachedConnection(std::shared_ptr remote_id); + std::shared_ptr GetNewConnection(std::shared_ptr remote_id); + std::unordered_map, std::shared_ptr, + ConnectionIdHash, ConnectionIdEquals> + connections_; std::unordered_map, - std::shared_ptr, ConnectionIdHash, + std::shared_ptr>, ConnectionIdHash, ConnectionIdEquals> - connections_; - std::unordered_map< - std::shared_ptr, - std::shared_ptr>, - ConnectionIdHash, ConnectionIdEquals> clients_; folly::SharedMutexWritePriority map_mutex_; std::shared_ptr cf_; diff --git hbase-native-client/connection/pipeline.h hbase-native-client/connection/pipeline.h index c4f3bbb..343219d 100644 --- hbase-native-client/connection/pipeline.h +++ hbase-native-client/connection/pipeline.h @@ -30,8 +30,7 @@ namespace hbase { /** Pipeline to turn IOBuf into requests */ -using SerializePipeline = - wangle::Pipeline>; +using SerializePipeline = wangle::Pipeline>; /** * Factory to create new pipelines for HBase RPC's. @@ -52,8 +51,7 @@ class RpcPipelineFactory : public wangle::PipelineFactory { * - Length Field Based Frame Decoder * - Client Handler */ - SerializePipeline::Ptr newPipeline( - std::shared_ptr sock) override; + SerializePipeline::Ptr newPipeline(std::shared_ptr sock) override; private: UserUtil user_util_; diff --git hbase-native-client/connection/request.cc hbase-native-client/connection/request.cc index d4a4603..189130e 100644 --- hbase-native-client/connection/request.cc +++ hbase-native-client/connection/request.cc @@ -24,22 +24,18 @@ using namespace hbase; Request::Request(std::shared_ptr req, - std::shared_ptr resp, - std::string method) + std::shared_ptr resp, std::string method) : req_msg_(req), resp_msg_(resp), method_(method), call_id_(0) {} std::unique_ptr Request::get() { return std::make_unique(std::make_shared(), - std::make_shared(), - "Get"); + std::make_shared(), "Get"); } std::unique_ptr Request::mutate() { - return std::make_unique( - std::make_shared(), - std::make_shared(), "Mutate"); + return std::make_unique(std::make_shared(), + std::make_shared(), "Mutate"); } std::unique_ptr Request::scan() { return std::make_unique(std::make_shared(), - std::make_shared(), - "Scan"); + std::make_shared(), "Scan"); } diff --git hbase-native-client/connection/response.h hbase-native-client/connection/response.h index f032d09..560387c 100644 --- hbase-native-client/connection/response.h +++ hbase-native-client/connection/response.h @@ -55,9 +55,7 @@ class Response { * The caller is reponsible for knowing the type. In practice the call id is * used to figure out the type. */ - std::shared_ptr resp_msg() const { - return resp_msg_; - } + std::shared_ptr resp_msg() const { return resp_msg_; } /** Set the response message. */ void set_resp_msg(std::shared_ptr response) { diff --git hbase-native-client/connection/rpc-client.cc hbase-native-client/connection/rpc-client.cc index 3f0cfaf..9cfefb8 100644 --- hbase-native-client/connection/rpc-client.cc +++ hbase-native-client/connection/rpc-client.cc @@ -28,41 +28,32 @@ namespace hbase { class RpcChannelImplementation : public AbstractRpcChannel { public: - RpcChannelImplementation(std::shared_ptr rpc_client, - const std::string& host, uint16_t port, - std::shared_ptr ticket, int rpc_timeout) + RpcChannelImplementation(std::shared_ptr rpc_client, const std::string& host, + uint16_t port, std::shared_ptr ticket, int rpc_timeout) : AbstractRpcChannel(rpc_client, host, port, ticket, rpc_timeout) {} - void CallMethod(const MethodDescriptor* method, RpcController* controller, - const Message* request, Message* response, - Closure* done) override { - rpc_client_->CallMethod(method, controller, request, response, done, host_, - port_, ticket_); + void CallMethod(const MethodDescriptor* method, RpcController* controller, const Message* request, + Message* response, Closure* done) override { + rpc_client_->CallMethod(method, controller, request, response, done, host_, port_, ticket_); } }; } // namespace hbase RpcClient::RpcClient() { - io_executor_ = std::make_shared( - sysconf(_SC_NPROCESSORS_ONLN)); + io_executor_ = std::make_shared(sysconf(_SC_NPROCESSORS_ONLN)); cp_ = std::make_shared(io_executor_); } -void RpcClient::Close() { - io_executor_->stop(); -} +void RpcClient::Close() { io_executor_->stop(); } -std::shared_ptr RpcClient::SyncCall(const std::string& host, - uint16_t port, +std::shared_ptr RpcClient::SyncCall(const std::string& host, uint16_t port, std::unique_ptr req, std::shared_ptr ticket) { - return std::make_shared( - AsyncCall(host, port, std::move(req), ticket).get()); + return std::make_shared(AsyncCall(host, port, std::move(req), ticket).get()); } -std::shared_ptr RpcClient::SyncCall(const std::string& host, - uint16_t port, +std::shared_ptr RpcClient::SyncCall(const std::string& host, uint16_t port, std::unique_ptr req, std::shared_ptr ticket, const std::string& service_name) { @@ -70,54 +61,44 @@ std::shared_ptr RpcClient::SyncCall(const std::string& host, AsyncCall(host, port, std::move(req), ticket, service_name).get()); } -folly::Future RpcClient::AsyncCall(const std::string& host, - uint16_t port, +folly::Future RpcClient::AsyncCall(const std::string& host, uint16_t port, std::unique_ptr req, std::shared_ptr ticket) { auto remote_id = std::make_shared(host, port, ticket); return GetConnection(remote_id)->SendRequest(std::move(req)); } -folly::Future RpcClient::AsyncCall(const std::string& host, - uint16_t port, +folly::Future RpcClient::AsyncCall(const std::string& host, uint16_t port, std::unique_ptr req, std::shared_ptr ticket, const std::string& service_name) { - auto remote_id = - std::make_shared(host, port, ticket, service_name); + auto remote_id = std::make_shared(host, port, ticket, service_name); return GetConnection(remote_id)->SendRequest(std::move(req)); } -std::shared_ptr RpcClient::GetConnection( - std::shared_ptr remote_id) { +std::shared_ptr RpcClient::GetConnection(std::shared_ptr remote_id) { return cp_->GetConnection(remote_id); } -std::shared_ptr RpcClient::CreateRpcChannel( - const std::string& host, uint16_t port, std::shared_ptr ticket, - int rpc_timeout) { - std::shared_ptr channel = - std::make_shared(shared_from_this(), host, port, - ticket, rpc_timeout); +std::shared_ptr RpcClient::CreateRpcChannel(const std::string& host, uint16_t port, + std::shared_ptr ticket, + int rpc_timeout) { + std::shared_ptr channel = std::make_shared( + shared_from_this(), host, port, ticket, rpc_timeout); /* static_pointer_cast is safe since RpcChannelImplementation derives * from RpcChannel, otherwise, dynamic_pointer_cast should be used. */ return std::static_pointer_cast(channel); } -void RpcClient::CallMethod(const MethodDescriptor* method, - RpcController* controller, const Message* req_msg, - Message* resp_msg, Closure* done, - const std::string& host, uint16_t port, - std::shared_ptr ticket) { +void RpcClient::CallMethod(const MethodDescriptor* method, RpcController* controller, + const Message* req_msg, Message* resp_msg, Closure* done, + const std::string& host, uint16_t port, std::shared_ptr ticket) { std::shared_ptr shared_req(const_cast(req_msg)); std::shared_ptr shared_resp(resp_msg); - std::unique_ptr req = - std::make_unique(shared_req, shared_resp, method->name()); + std::unique_ptr req = std::make_unique(shared_req, shared_resp, method->name()); AsyncCall(host, port, std::move(req), ticket, method->service()->name()) - .then([done, this](Response resp) { - done->Run(); - }); + .then([done, this](Response resp) { done->Run(); }); } diff --git hbase-native-client/connection/rpc-client.h hbase-native-client/connection/rpc-client.h index dbf857d..407d588 100644 --- hbase-native-client/connection/rpc-client.h +++ hbase-native-client/connection/rpc-client.h @@ -53,41 +53,35 @@ class RpcClient : public std::enable_shared_from_this { virtual ~RpcClient() { Close(); } - virtual std::shared_ptr SyncCall(const std::string &host, - uint16_t port, + virtual std::shared_ptr SyncCall(const std::string &host, uint16_t port, std::unique_ptr req, std::shared_ptr ticket); - virtual std::shared_ptr SyncCall(const std::string &host, - uint16_t port, + virtual std::shared_ptr SyncCall(const std::string &host, uint16_t port, std::unique_ptr req, std::shared_ptr ticket, const std::string &service_name); - virtual folly::Future AsyncCall(const std::string &host, - uint16_t port, + virtual folly::Future AsyncCall(const std::string &host, uint16_t port, std::unique_ptr req, std::shared_ptr ticket); - virtual folly::Future AsyncCall(const std::string &host, - uint16_t port, + virtual folly::Future AsyncCall(const std::string &host, uint16_t port, std::unique_ptr req, std::shared_ptr ticket, const std::string &service_name); virtual void Close(); - virtual std::shared_ptr CreateRpcChannel( - const std::string &host, uint16_t port, std::shared_ptr ticket, - int rpc_timeout); + virtual std::shared_ptr CreateRpcChannel(const std::string &host, uint16_t port, + std::shared_ptr ticket, + int rpc_timeout); private: - void CallMethod(const MethodDescriptor *method, RpcController *controller, - const Message *req_msg, Message *resp_msg, Closure *done, - const std::string &host, uint16_t port, + void CallMethod(const MethodDescriptor *method, RpcController *controller, const Message *req_msg, + Message *resp_msg, Closure *done, const std::string &host, uint16_t port, std::shared_ptr ticket); - std::shared_ptr GetConnection( - std::shared_ptr remote_id); + std::shared_ptr GetConnection(std::shared_ptr remote_id); private: std::shared_ptr cp_; @@ -96,8 +90,7 @@ class RpcClient : public std::enable_shared_from_this { class AbstractRpcChannel : public RpcChannel { public: - AbstractRpcChannel(std::shared_ptr rpc_client, - const std::string &host, uint16_t port, + AbstractRpcChannel(std::shared_ptr rpc_client, const std::string &host, uint16_t port, std::shared_ptr ticket, int rpc_timeout) : rpc_client_(rpc_client), host_(host), diff --git hbase-native-client/connection/rpc-connection.h hbase-native-client/connection/rpc-connection.h index 2e06ec3..e2500b2 100644 --- hbase-native-client/connection/rpc-connection.h +++ hbase-native-client/connection/rpc-connection.h @@ -37,13 +37,9 @@ class RpcConnection { virtual ~RpcConnection() { Close(); } - virtual std::shared_ptr remote_id() const { - return connection_id_; - } + virtual std::shared_ptr remote_id() const { return connection_id_; } - virtual std::shared_ptr get_service() const { - return hbase_service_; - } + virtual std::shared_ptr get_service() const { return hbase_service_; } virtual folly::Future SendRequest(std::unique_ptr req) { return (*hbase_service_)(std::move(req)); diff --git hbase-native-client/core/cell-test.cc hbase-native-client/core/cell-test.cc index 53574e8..fb4d033 100644 --- hbase-native-client/core/cell-test.cc +++ hbase-native-client/core/cell-test.cc @@ -32,8 +32,7 @@ TEST(CellTest, CellFailureTest) { std::string value = "value"; int64_t timestamp = std::numeric_limits::max(); std::string tags = ""; - std::unique_ptr cell( - new Cell(row, family, column, timestamp, value, cell_type)); + std::unique_ptr cell(new Cell(row, family, column, timestamp, value, cell_type)); if (cell.get()) { EXPECT_NE("row-value", cell.get()->Row()); EXPECT_NE("family-value", cell.get()->Family()); @@ -51,8 +50,7 @@ TEST(CellTest, CellSuceessTest) { std::string value = "value-value"; int64_t timestamp = std::numeric_limits::max(); CellType cell_type = CellType::PUT; - const std::unique_ptr cell( - new Cell(row, family, column, timestamp, value, cell_type)); + const std::unique_ptr cell(new Cell(row, family, column, timestamp, value, cell_type)); if (cell.get()) { EXPECT_EQ(row, cell.get()->Row()); EXPECT_EQ(family, cell.get()->Family()); @@ -74,8 +72,7 @@ TEST(CellTest, MultipleCellsTest) { row += std::to_string(i); value += std::to_string(i); CellType cell_type = CellType::PUT; - const Cell *cell = - new Cell(row, family, column, timestamp, value, cell_type); + const Cell *cell = new Cell(row, family, column, timestamp, value, cell_type); cells.push_back(cell); } int i = 0; @@ -105,8 +102,7 @@ TEST(CellTest, CellRowTest) { std::string value = ""; int64_t timestamp = std::numeric_limits::max(); CellType cell_type = CellType::PUT; - std::unique_ptr cell( - new Cell(row, family, column, timestamp, value, cell_type)); + std::unique_ptr cell(new Cell(row, family, column, timestamp, value, cell_type)); if (cell.get()) { EXPECT_EQ(row, cell.get()->Row()); EXPECT_EQ(family, cell.get()->Family()); @@ -124,8 +120,7 @@ TEST(CellTest, CellRowFamilyTest) { std::string value = ""; int64_t timestamp = std::numeric_limits::max(); CellType cell_type = CellType::PUT; - const std::unique_ptr cell( - new Cell(row, family, column, timestamp, value, cell_type)); + const std::unique_ptr cell(new Cell(row, family, column, timestamp, value, cell_type)); if (cell.get()) { EXPECT_EQ(row, cell.get()->Row()); EXPECT_EQ(family, cell.get()->Family()); @@ -143,8 +138,7 @@ TEST(CellTest, CellRowFamilyValueTest) { std::string value = "only-value"; int64_t timestamp = std::numeric_limits::max(); CellType cell_type = CellType::PUT; - const std::unique_ptr cell( - new Cell(row, family, column, timestamp, value, cell_type)); + const std::unique_ptr cell(new Cell(row, family, column, timestamp, value, cell_type)); if (cell.get()) { EXPECT_EQ(row, cell.get()->Row()); EXPECT_EQ(family, cell.get()->Family()); @@ -162,8 +156,7 @@ TEST(CellTest, CellRowFamilyColumnValueTest) { std::string value = "only-value"; int64_t timestamp = std::numeric_limits::max(); CellType cell_type = CellType::PUT; - std::unique_ptr cell( - new Cell(row, family, column, timestamp, value, cell_type)); + std::unique_ptr cell(new Cell(row, family, column, timestamp, value, cell_type)); if (cell.get()) { EXPECT_EQ(row, cell.get()->Row()); EXPECT_EQ(family, cell.get()->Family()); diff --git hbase-native-client/core/cell.cc hbase-native-client/core/cell.cc index 3102e53..4982406 100644 --- hbase-native-client/core/cell.cc +++ hbase-native-client/core/cell.cc @@ -22,9 +22,8 @@ namespace hbase { -Cell::Cell(const std::string &row, const std::string &family, - const std::string &qualifier, const int64_t timestamp, - const std::string &value, const hbase::CellType &cell_type) +Cell::Cell(const std::string &row, const std::string &family, const std::string &qualifier, + const int64_t timestamp, const std::string &value, const hbase::CellType &cell_type) : row_(row), family_(family), qualifier_(qualifier), @@ -32,14 +31,11 @@ Cell::Cell(const std::string &row, const std::string &family, cell_type_(cell_type), value_(value), sequence_id_(0) { - if (0 == row.size()) - throw std::runtime_error("Row size should be greater than 0"); + if (0 == row.size()) throw std::runtime_error("Row size should be greater than 0"); - if (0 == family.size()) - throw std::runtime_error("Column family size should be greater than 0"); + if (0 == family.size()) throw std::runtime_error("Column family size should be greater than 0"); - if (0 >= timestamp) - throw std::runtime_error("Timestamp should be greater than 0"); + if (0 >= timestamp) throw std::runtime_error("Timestamp should be greater than 0"); } Cell::~Cell() {} diff --git hbase-native-client/core/cell.h hbase-native-client/core/cell.h index f55655c..5a39dc3 100644 --- hbase-native-client/core/cell.h +++ hbase-native-client/core/cell.h @@ -36,9 +36,8 @@ enum CellType { class Cell { public: - Cell(const std::string &row, const std::string &family, - const std::string &qualifier, const int64_t timestamp, - const std::string &value, const hbase::CellType &cell_type); + Cell(const std::string &row, const std::string &family, const std::string &qualifier, + const int64_t timestamp, const std::string &value, const hbase::CellType &cell_type); virtual ~Cell(); const std::string &Row() const; const std::string &Family() const; diff --git hbase-native-client/core/client-test.cc hbase-native-client/core/client-test.cc index 0fe0225..28eec6f 100644 --- hbase-native-client/core/client-test.cc +++ hbase-native-client/core/client-test.cc @@ -17,8 +17,8 @@ * */ -#include #include "core/client.h" +#include #include "core/configuration.h" #include "core/get.h" #include "core/hbase_configuration_loader.h" @@ -84,9 +84,7 @@ const std::string ClientTest::kHBaseXmlData( "the License.\n " "*/\n-->\n\n\n"); -TEST(Client, EmptyConfigurationPassedToClient) { - ASSERT_ANY_THROW(hbase::Client client); -} +TEST(Client, EmptyConfigurationPassedToClient) { ASSERT_ANY_THROW(hbase::Client client); } TEST(Client, ConfigurationPassedToClient) { // Remove already configured env if present. diff --git hbase-native-client/core/client.h hbase-native-client/core/client.h index 2bb506b..da71624 100644 --- hbase-native-client/core/client.h +++ hbase-native-client/core/client.h @@ -27,13 +27,13 @@ #include #include +#include "connection/rpc-client.h" #include "core/configuration.h" #include "core/hbase_configuration_loader.h" #include "core/location-cache.h" -#include "connection/rpc-client.h" #include "core/table.h" -#include "serde/table-name.h" #include "if/Cell.pb.h" +#include "serde/table-name.h" using hbase::pb::TableName; diff --git hbase-native-client/core/configuration.cc hbase-native-client/core/configuration.cc index 134f05f..bd582d8 100644 --- hbase-native-client/core/configuration.cc +++ hbase-native-client/core/configuration.cc @@ -28,13 +28,11 @@ namespace hbase { -Configuration::Configuration(ConfigMap &config_map) - : hb_property_(std::move(config_map)) {} +Configuration::Configuration(ConfigMap &config_map) : hb_property_(std::move(config_map)) {} Configuration::~Configuration() {} -size_t Configuration::IsSubVariable(const std::string &expr, - std::string &sub_variable) const { +size_t Configuration::IsSubVariable(const std::string &expr, std::string &sub_variable) const { size_t start_pos = expr.find("${"); if (std::string::npos != start_pos) { size_t pos_next = expr.find("}", start_pos + 1); @@ -57,8 +55,7 @@ std::string Configuration::SubstituteVars(const std::string &expr) const { if (start_pos != std::string::npos) { // We are blindly checking for environment property at first. // If we don't get any value from GetEnv, check in hbase-site.xml. - value_to_be_replaced = - GetEnv(var).value_or(GetProperty(var).value_or("")); + value_to_be_replaced = GetEnv(var).value_or(GetProperty(var).value_or("")); // we haven't found any value yet so we are returning eval if (0 == value_to_be_replaced.size()) { @@ -148,8 +145,7 @@ optional Configuration::Get(const std::string &key) const { } } -std::string Configuration::Get(const std::string &key, - const std::string &default_value) const { +std::string Configuration::Get(const std::string &key, const std::string &default_value) const { return Get(key).value_or(default_value); } @@ -157,8 +153,7 @@ optional Configuration::GetInt(const std::string &key) const { optional raw = Get(key); if (raw) { try { - return std::experimental::make_optional( - boost::lexical_cast(*raw)); + return std::experimental::make_optional(boost::lexical_cast(*raw)); } catch (const boost::bad_lexical_cast &blex) { throw std::runtime_error(blex.what()); } @@ -166,8 +161,7 @@ optional Configuration::GetInt(const std::string &key) const { return optional(); } -int32_t Configuration::GetInt(const std::string &key, - int32_t default_value) const { +int32_t Configuration::GetInt(const std::string &key, int32_t default_value) const { return GetInt(key).value_or(default_value); } @@ -175,8 +169,7 @@ optional Configuration::GetLong(const std::string &key) const { optional raw = Get(key); if (raw) { try { - return std::experimental::make_optional( - boost::lexical_cast(*raw)); + return std::experimental::make_optional(boost::lexical_cast(*raw)); } catch (const boost::bad_lexical_cast &blex) { throw std::runtime_error(blex.what()); } @@ -184,8 +177,7 @@ optional Configuration::GetLong(const std::string &key) const { return optional(); } -int64_t Configuration::GetLong(const std::string &key, - int64_t default_value) const { +int64_t Configuration::GetLong(const std::string &key, int64_t default_value) const { return GetLong(key).value_or(default_value); } @@ -193,8 +185,7 @@ optional Configuration::GetDouble(const std::string &key) const { optional raw = Get(key); if (raw) { try { - return std::experimental::make_optional( - boost::lexical_cast(*raw)); + return std::experimental::make_optional(boost::lexical_cast(*raw)); } catch (const boost::bad_lexical_cast &blex) { throw std::runtime_error(blex.what()); } @@ -202,8 +193,7 @@ optional Configuration::GetDouble(const std::string &key) const { return optional(); } -double Configuration::GetDouble(const std::string &key, - double default_value) const { +double Configuration::GetDouble(const std::string &key, double default_value) const { return GetDouble(key).value_or(default_value); } @@ -215,8 +205,7 @@ optional Configuration::GetBool(const std::string &key) const { } else if (!strcasecmp((*raw).c_str(), "false")) { return std::experimental::make_optional(false); } else { - throw std::runtime_error( - "Unexpected value found while conversion to bool."); + throw std::runtime_error("Unexpected value found while conversion to bool."); } } return optional(); diff --git hbase-native-client/core/configuration.h hbase-native-client/core/configuration.h index f09bbac..69bef75 100644 --- hbase-native-client/core/configuration.h +++ hbase-native-client/core/configuration.h @@ -41,8 +41,7 @@ class Configuration { * @param key Property whose value is to be fetched. SubstituteVars will be * called for any variable expansion. */ - std::string Get(const std::string &key, - const std::string &default_value) const; + std::string Get(const std::string &key, const std::string &default_value) const; /** * @brief Returns int32_t identified by key in ConfigMap else default value if @@ -89,8 +88,7 @@ class Configuration { std::string value; bool final; ConfigData() : final(false) {} - explicit ConfigData(const std::string &value) - : value(value), final(false) {} + explicit ConfigData(const std::string &value) : value(value), final(false) {} void operator=(const std::string &new_value) { value = new_value; final = false; @@ -174,8 +172,7 @@ class Configuration { * @param sub_variable Extracted variable from expr which will be checked * against environment value or ConfigMap values. */ - size_t IsSubVariable(const std::string &expr, - std::string &sub_variable) const; + size_t IsSubVariable(const std::string &expr, std::string &sub_variable) const; /** * @brief This method will fetch value for key from environment if present. diff --git hbase-native-client/core/get-test.cc hbase-native-client/core/get-test.cc index cef99b9..07d0003 100644 --- hbase-native-client/core/get-test.cc +++ hbase-native-client/core/get-test.cc @@ -121,8 +121,7 @@ void GetMethods(Get &get, const std::string &row) { // Test initial values EXPECT_EQ(0, get.Timerange().MinTimeStamp()); - EXPECT_EQ(std::numeric_limits::max(), - get.Timerange().MaxTimeStamp()); + EXPECT_EQ(std::numeric_limits::max(), get.Timerange().MaxTimeStamp()); // Set & Test new values using TimeRange and TimeStamp get.SetTimeRange(1000, 2000); @@ -136,13 +135,11 @@ void GetMethods(Get &get, const std::string &row) { ASSERT_THROW(get.SetTimeRange(-1000, 2000), std::runtime_error); ASSERT_THROW(get.SetTimeRange(1000, -2000), std::runtime_error); ASSERT_THROW(get.SetTimeRange(1000, 200), std::runtime_error); - ASSERT_THROW(get.SetTimeStamp(std::numeric_limits::max()), - std::runtime_error); + ASSERT_THROW(get.SetTimeStamp(std::numeric_limits::max()), std::runtime_error); // Test some exceptions ASSERT_THROW(get.SetMaxVersions(0), std::runtime_error); - ASSERT_THROW(get.SetMaxVersions(std::numeric_limits::max() + 1), - std::runtime_error); + ASSERT_THROW(get.SetMaxVersions(std::numeric_limits::max() + 1), std::runtime_error); } TEST(Get, SingleGet) { diff --git hbase-native-client/core/get.cc hbase-native-client/core/get.cc index 6ba4e86..5c5f446 100644 --- hbase-native-client/core/get.cc +++ hbase-native-client/core/get.cc @@ -34,8 +34,7 @@ Get::Get(const Get &get) { cache_blocks_ = get.cache_blocks_; check_existence_only_ = get.check_existence_only_; consistency_ = get.consistency_; - tr_.reset(new TimeRange(get.Timerange().MinTimeStamp(), - get.Timerange().MaxTimeStamp())); + tr_.reset(new TimeRange(get.Timerange().MinTimeStamp(), get.Timerange().MaxTimeStamp())); family_map_.insert(get.family_map_.begin(), get.family_map_.end()); } @@ -45,8 +44,7 @@ Get &Get::operator=(const Get &get) { cache_blocks_ = get.cache_blocks_; check_existence_only_ = get.check_existence_only_; consistency_ = get.consistency_; - tr_.reset(new TimeRange(get.Timerange().MinTimeStamp(), - get.Timerange().MaxTimeStamp())); + tr_.reset(new TimeRange(get.Timerange().MinTimeStamp(), get.Timerange().MaxTimeStamp())); family_map_.insert(get.family_map_.begin(), get.family_map_.end()); return *this; } @@ -68,8 +66,7 @@ Get &Get::AddFamily(const std::string &family) { } Get &Get::AddColumn(const std::string &family, const std::string &qualifier) { - const auto &it = std::find(family_map_[family].begin(), - family_map_[family].end(), qualifier); + const auto &it = std::find(family_map_[family].begin(), family_map_[family].end(), qualifier); /** * Check if any qualifiers are already present or not. @@ -97,8 +94,7 @@ const FamilyMap &Get::Family() const { return family_map_; } int Get::MaxVersions() const { return max_versions_; } Get &Get::SetMaxVersions(int32_t max_versions) { - if (0 == max_versions) - throw std::runtime_error("max_versions must be positive"); + if (0 == max_versions) throw std::runtime_error("max_versions must be positive"); max_versions_ = max_versions; return *this; @@ -130,8 +126,7 @@ void Get::CheckRow(const std::string &row) { throw std::runtime_error("Row length can't be 0"); } if (row_length > kMaxRowLength) { - throw std::runtime_error("Length of " + row + - " is greater than max row size: " + + throw std::runtime_error("Length of " + row + " is greater than max row size: " + std::to_string(kMaxRowLength)); } } diff --git hbase-native-client/core/hbase_configuration-test.cc hbase-native-client/core/hbase_configuration-test.cc index eec500e..07a6358 100644 --- hbase-native-client/core/hbase_configuration-test.cc +++ hbase-native-client/core/hbase_configuration-test.cc @@ -28,10 +28,8 @@ using namespace hbase; -const std::string kDefHBaseConfPath( - "./build/test-data/hbase-configuration-test/conf/"); -const std::string kHBaseConfPath( - "./build/test-data/hbase-configuration-test/custom-conf/"); +const std::string kDefHBaseConfPath("./build/test-data/hbase-configuration-test/conf/"); +const std::string kHBaseConfPath("./build/test-data/hbase-configuration-test/custom-conf/"); const std::string kHBaseDefaultXml("hbase-default.xml"); const std::string kHBaseSiteXml("hbase-site.xml"); @@ -121,8 +119,7 @@ void WriteDataToFile(const std::string &file, const std::string &xml_data) { hbase_conf.close(); } -void CreateHBaseConf(const std::string &dir, const std::string &file, - const std::string xml_data) { +void CreateHBaseConf(const std::string &dir, const std::string &file, const std::string xml_data) { // Directory will be created if not present if (!boost::filesystem::exists(dir)) { boost::filesystem::create_directories(dir); @@ -153,10 +150,8 @@ TEST(Configuration, LoadConfFromDefaultLocation) { HBaseConfigurationLoader loader; hbase::optional conf = loader.LoadDefaultResources(); ASSERT_TRUE(conf) << "No configuration object present."; - EXPECT_STREQ((*conf).Get("custom-prop", "Set this value").c_str(), - "custom-value"); - EXPECT_STREQ((*conf).Get("default-prop", "Set this value").c_str(), - "default-value"); + EXPECT_STREQ((*conf).Get("custom-prop", "Set this value").c_str(), "custom-value"); + EXPECT_STREQ((*conf).Get("default-prop", "Set this value").c_str(), "default-value"); } /* @@ -170,8 +165,7 @@ TEST(Configuration, LoadConfFromCustomLocation) { HBaseConfigurationLoader loader; std::vector resources{kHBaseSiteXml}; - hbase::optional conf = - loader.LoadResources(kHBaseConfPath, resources); + hbase::optional conf = loader.LoadResources(kHBaseConfPath, resources); ASSERT_TRUE(conf) << "No configuration object present."; EXPECT_STREQ((*conf).Get("custom-prop", "").c_str(), "custom-value"); EXPECT_STRNE((*conf).Get("custom-prop", "").c_str(), "some-value"); @@ -192,11 +186,9 @@ TEST(Configuration, LoadConfFromMultipleLocatons) { HBaseConfigurationLoader loader; std::string conf_paths = kDefHBaseConfPath + ":" + kHBaseConfPath; std::vector resources{kHBaseDefaultXml, kHBaseSiteXml}; - hbase::optional conf = - loader.LoadResources(conf_paths, resources); + hbase::optional conf = loader.LoadResources(conf_paths, resources); ASSERT_TRUE(conf) << "No configuration object present."; - EXPECT_STREQ((*conf).Get("default-prop", "From hbase-default.xml").c_str(), - "default-value"); + EXPECT_STREQ((*conf).Get("default-prop", "From hbase-default.xml").c_str(), "default-value"); EXPECT_STREQ((*conf).Get("custom-prop", "").c_str(), "custom-value"); EXPECT_STRNE((*conf).Get("custom-prop", "").c_str(), "some-value"); } @@ -215,10 +207,8 @@ TEST(Configuration, DefaultValues) { HBaseConfigurationLoader loader; hbase::optional conf = loader.LoadDefaultResources(); ASSERT_TRUE(conf) << "No configuration object present."; - EXPECT_STREQ((*conf).Get("default-prop", "Set this value.").c_str(), - "default-value"); - EXPECT_STREQ((*conf).Get("custom-prop", "Set this value.").c_str(), - "custom-value"); + EXPECT_STREQ((*conf).Get("default-prop", "Set this value.").c_str(), "default-value"); + EXPECT_STREQ((*conf).Get("custom-prop", "Set this value.").c_str(), "custom-value"); } TEST(Configuration, FinalValues) { @@ -229,12 +219,10 @@ TEST(Configuration, FinalValues) { HBaseConfigurationLoader loader; hbase::optional conf = loader.LoadDefaultResources(); ASSERT_TRUE(conf) << "No configuration object present."; - EXPECT_STREQ((*conf).Get("hbase.rootdir", "").c_str(), - "/root/hbase-docker/apps/hbase/data"); + EXPECT_STREQ((*conf).Get("hbase.rootdir", "").c_str(), "/root/hbase-docker/apps/hbase/data"); EXPECT_STREQ((*conf).Get("hbase.zookeeper.property.datadir", "").c_str(), "/root/hbase-docker/zookeeper"); - EXPECT_STRNE((*conf).Get("hbase.rootdir", "").c_str(), - "This value will not be be overwritten"); + EXPECT_STRNE((*conf).Get("hbase.rootdir", "").c_str(), "This value will not be be overwritten"); EXPECT_STRNE((*conf).Get("hbase.zookeeper.property.datadir", "").c_str(), "This value will be overwritten"); } @@ -253,10 +241,8 @@ TEST(Configuration, EnvVars) { HBaseConfigurationLoader loader; hbase::optional conf = loader.LoadDefaultResources(); ASSERT_TRUE(conf) << "No configuration object present."; - EXPECT_STREQ((*conf).Get("hbase-client.user.name", "").c_str(), - "${user.name}"); - EXPECT_STRNE((*conf).Get("hbase-client.user.name", "root").c_str(), - "test-user"); + EXPECT_STREQ((*conf).Get("hbase-client.user.name", "").c_str(), "${user.name}"); + EXPECT_STRNE((*conf).Get("hbase-client.user.name", "root").c_str(), "test-user"); } TEST(Configuration, SelfRef) { @@ -292,8 +278,7 @@ TEST(Configuration, VarExpansionException) { HBaseConfigurationLoader loader; hbase::optional conf = loader.LoadDefaultResources(); ASSERT_TRUE(conf) << "No configuration object present."; - ASSERT_THROW((*conf).Get("foo.substs.exception", "foo-value").c_str(), - std::runtime_error); + ASSERT_THROW((*conf).Get("foo.substs.exception", "foo-value").c_str(), std::runtime_error); } TEST(Configuration, GetInt) { diff --git hbase-native-client/core/hbase_configuration_loader.cc hbase-native-client/core/hbase_configuration_loader.cc index 20d0449..38a617b 100644 --- hbase-native-client/core/hbase_configuration_loader.cc +++ hbase-native-client/core/hbase_configuration_loader.cc @@ -94,8 +94,7 @@ void HBaseConfigurationLoader::AddToSearchPath(const std::string &search_path) { if (search_path.back() != kFileSeparator) { path_to_add += kFileSeparator; } - if (std::find(search_paths_.begin(), search_paths_.end(), path_to_add) == - search_paths_.end()) + if (std::find(search_paths_.begin(), search_paths_.end(), path_to_add) == search_paths_.end()) search_paths_.push_back(path_to_add); } @@ -105,8 +104,7 @@ void HBaseConfigurationLoader::AddDefaultResources() { } void HBaseConfigurationLoader::AddResources(const std::string &filename) { - if (std::find(resources_.begin(), resources_.end(), filename) == - resources_.end()) + if (std::find(resources_.begin(), resources_.end(), filename) == resources_.end()) resources_.push_back(filename); } @@ -127,8 +125,7 @@ optional HBaseConfigurationLoader::LoadDefaultResources() { } } if (success) { - return std::experimental::make_optional( - Configuration(conf_property)); + return std::experimental::make_optional(Configuration(conf_property)); } else { return optional(); } @@ -152,15 +149,13 @@ optional HBaseConfigurationLoader::LoadResources( } } if (success) { - return std::experimental::make_optional( - Configuration(conf_property)); + return std::experimental::make_optional(Configuration(conf_property)); } else { return optional(); } } -bool HBaseConfigurationLoader::LoadProperties(const std::string &file, - ConfigMap &property_map) { +bool HBaseConfigurationLoader::LoadProperties(const std::string &file, ConfigMap &property_map) { // Create empty property tree object using boost::property_tree::ptree; ptree pt; @@ -179,23 +174,21 @@ bool HBaseConfigurationLoader::LoadProperties(const std::string &file, std::string name_node = v.second.get("name"); std::string value_node = v.second.get("value"); if ((name_node.size() > 0) && (value_node.size() > 0)) { - boost::optional final_node = - v.second.get_optional("final"); + boost::optional final_node = v.second.get_optional("final"); UpdateMapWithValue(property_map, name_node, value_node, final_node); } } } } catch (std::exception &ex) { - DLOG(WARNING) << "Exception in parsing file [" << file << "]:[" << ex.what() - << "]"; + DLOG(WARNING) << "Exception in parsing file [" << file << "]:[" << ex.what() << "]"; return false; } return true; } -bool HBaseConfigurationLoader::UpdateMapWithValue( - ConfigMap &map, const std::string &key, const std::string &value, - boost::optional final_text) { +bool HBaseConfigurationLoader::UpdateMapWithValue(ConfigMap &map, const std::string &key, + const std::string &value, + boost::optional final_text) { auto map_value = map.find(key); if (map_value != map.end() && map_value->second.final) { return false; diff --git hbase-native-client/core/hbase_configuration_loader.h hbase-native-client/core/hbase_configuration_loader.h index 49dc2b9..a1c1d3f 100644 --- hbase-native-client/core/hbase_configuration_loader.h +++ hbase-native-client/core/hbase_configuration_loader.h @@ -58,9 +58,8 @@ class HBaseConfigurationLoader { * @param search_path - ':' search paths to load resources. * @param resources - list of resources used to load configuration properties. */ - optional LoadResources( - const std::string &search_path, - const std::vector &resources); + optional LoadResources(const std::string &search_path, + const std::vector &resources); private: using ConfigMap = Configuration::ConfigMap; @@ -137,8 +136,7 @@ class HBaseConfigurationLoader { * @param value value of value node. * @param final_text value of final node true or false if present */ - bool UpdateMapWithValue(ConfigMap &map, const std::string &key, - const std::string &value, + bool UpdateMapWithValue(ConfigMap &map, const std::string &key, const std::string &value, boost::optional final_text); }; diff --git hbase-native-client/core/location-cache.cc hbase-native-client/core/location-cache.cc index 4c29a61..6c2a790 100644 --- hbase-native-client/core/location-cache.cc +++ hbase-native-client/core/location-cache.cc @@ -53,10 +53,9 @@ using hbase::pb::RegionInfo; // TODO(eclark): make this configurable on client creation static const char META_ZNODE_NAME[] = "/hbase/meta-region-server"; -LocationCache::LocationCache( - std::string quorum_spec, - std::shared_ptr cpu_executor, - std::shared_ptr io_executor) +LocationCache::LocationCache(std::string quorum_spec, + std::shared_ptr cpu_executor, + std::shared_ptr io_executor) : quorum_spec_(quorum_spec), cpu_executor_(cpu_executor), meta_promise_(nullptr), @@ -91,9 +90,7 @@ void LocationCache::InvalidateMeta() { /// MUST hold the meta_lock_ void LocationCache::RefreshMetaLocation() { meta_promise_ = make_unique>(); - cpu_executor_->add([&] { - meta_promise_->setWith([&] { return this->ReadMetaLocation(); }); - }); + cpu_executor_->add([&] { meta_promise_->setWith([&] { return this->ReadMetaLocation(); }); }); } ServerName LocationCache::ReadMetaLocation() { @@ -103,9 +100,8 @@ ServerName LocationCache::ReadMetaLocation() { // This needs to be int rather than size_t as that's what ZK expects. int len = buf->capacity(); // TODO(elliott): handle disconnects/reconntion as needed. - int zk_result = - zoo_get(this->zk_, META_ZNODE_NAME, 0, - reinterpret_cast(buf->writableData()), &len, nullptr); + int zk_result = zoo_get(this->zk_, META_ZNODE_NAME, 0, + reinterpret_cast(buf->writableData()), &len, nullptr); if (zk_result != ZOK || len < 9) { LOG(ERROR) << "Error getting meta location."; throw runtime_error("Error getting meta location"); @@ -119,18 +115,16 @@ ServerName LocationCache::ReadMetaLocation() { return mrs.server(); } -Future> LocationCache::LocateFromMeta( - const TableName &tn, const string &row) { +Future> LocationCache::LocateFromMeta(const TableName &tn, + const string &row) { return this->LocateMeta() .via(cpu_executor_.get()) .then([this](ServerName sn) { - auto remote_id = - std::make_shared(sn.host_name(), sn.port()); + auto remote_id = std::make_shared(sn.host_name(), sn.port()); return this->cp_.GetConnection(remote_id); }) .then([tn, row, this](std::shared_ptr rpc_connection) { - return (*rpc_connection->get_service())( - std::move(meta_util_.MetaRequest(tn, row))); + return (*rpc_connection->get_service())(std::move(meta_util_.MetaRequest(tn, row))); }) .then([this](Response resp) { // take the protobuf response and make it into @@ -146,16 +140,15 @@ Future> LocationCache::LocateFromMeta( return rl; }) .then([this](std::shared_ptr rl) { - auto remote_id = std::make_shared( - rl->server_name().host_name(), rl->server_name().port()); + auto remote_id = + std::make_shared(rl->server_name().host_name(), rl->server_name().port()); // Now fill out the connection. rl->set_service(cp_.GetConnection(remote_id)->get_service()); return rl; }); } -std::shared_ptr LocationCache::CreateLocation( - const Response &resp) { +std::shared_ptr LocationCache::CreateLocation(const Response &resp) { auto resp_msg = static_pointer_cast(resp.resp_msg()); auto &results = resp_msg->results().Get(0); auto &cells = results.cell(); @@ -168,6 +161,5 @@ std::shared_ptr LocationCache::CreateLocation( auto region_info = folly::to(cell_zero); auto server_name = folly::to(cell_one); - return std::make_shared(row, std::move(region_info), - server_name, nullptr); + return std::make_shared(row, std::move(region_info), server_name, nullptr); } diff --git hbase-native-client/core/location-cache.h hbase-native-client/core/location-cache.h index 53e41ab..b290a1f 100644 --- hbase-native-client/core/location-cache.h +++ hbase-native-client/core/location-cache.h @@ -79,8 +79,8 @@ class LocationCache { * @param row of the table to look up. This object must live until after the * future is returned */ - folly::Future> LocateFromMeta( - const hbase::pb::TableName &tn, const std::string &row); + folly::Future> LocateFromMeta(const hbase::pb::TableName &tn, + const std::string &row); /** * Remove the cached location of meta. diff --git hbase-native-client/core/meta-utils.cc hbase-native-client/core/meta-utils.cc index e1946d6..f92300c 100644 --- hbase-native-client/core/meta-utils.cc +++ hbase-native-client/core/meta-utils.cc @@ -37,13 +37,11 @@ using hbase::pb::RegionSpecifier_RegionSpecifierType; static const std::string META_REGION = "1588230740"; -std::string MetaUtil::RegionLookupRowkey(const TableName &tn, - const std::string &row) const { +std::string MetaUtil::RegionLookupRowkey(const TableName &tn, const std::string &row) const { return folly::to(tn, ",", row, ",", "999999999999999999"); } -std::unique_ptr MetaUtil::MetaRequest(const TableName tn, - const std::string &row) const { +std::unique_ptr MetaUtil::MetaRequest(const TableName tn, const std::string &row) const { auto request = Request::scan(); auto msg = std::static_pointer_cast(request->req_msg()); @@ -53,8 +51,8 @@ std::unique_ptr MetaUtil::MetaRequest(const TableName tn, // Set the region this scan goes to auto region = msg->mutable_region(); region->set_value(META_REGION); - region->set_type(RegionSpecifier_RegionSpecifierType:: - RegionSpecifier_RegionSpecifierType_ENCODED_REGION_NAME); + region->set_type( + RegionSpecifier_RegionSpecifierType::RegionSpecifier_RegionSpecifierType_ENCODED_REGION_NAME); auto scan = msg->mutable_scan(); // We don't care about before, just now. diff --git hbase-native-client/core/meta-utils.h hbase-native-client/core/meta-utils.h index 33da1a8..075215e 100644 --- hbase-native-client/core/meta-utils.h +++ hbase-native-client/core/meta-utils.h @@ -36,14 +36,12 @@ class MetaUtil { * Given a table and a row give the row key from which to start a scan to find * region locations. */ - std::string RegionLookupRowkey(const hbase::pb::TableName &tn, - const std::string &row) const; + std::string RegionLookupRowkey(const hbase::pb::TableName &tn, const std::string &row) const; /** * Given a row we're trying to access create a request to look up the * location. */ - std::unique_ptr MetaRequest(const hbase::pb::TableName tn, - const std::string &row) const; + std::unique_ptr MetaRequest(const hbase::pb::TableName tn, const std::string &row) const; }; } // namespace hbase diff --git hbase-native-client/core/region-location.h hbase-native-client/core/region-location.h index f0295b1..e7b76d3 100644 --- hbase-native-client/core/region-location.h +++ hbase-native-client/core/region-location.h @@ -42,8 +42,7 @@ class RegionLocation { * this region. * @param service the connected service to the regionserver. */ - RegionLocation(std::string region_name, hbase::pb::RegionInfo ri, - hbase::pb::ServerName sn, + RegionLocation(std::string region_name, hbase::pb::RegionInfo ri, hbase::pb::ServerName sn, std::shared_ptr service) : region_name_(region_name), ri_(ri), sn_(sn), service_(service) {} diff --git hbase-native-client/core/response_converter.h hbase-native-client/core/response_converter.h index 7cbde81..86fb632 100644 --- hbase-native-client/core/response_converter.h +++ hbase-native-client/core/response_converter.h @@ -20,8 +20,8 @@ #pragma once #include -#include "core/result.h" #include "connection/response.h" +#include "core/result.h" namespace hbase { diff --git hbase-native-client/core/result-test.cc hbase-native-client/core/result-test.cc index 134e80f..09d4e15 100644 --- hbase-native-client/core/result-test.cc +++ hbase-native-client/core/result-test.cc @@ -19,11 +19,11 @@ #include "core/result.h" +#include #include #include -#include #include -#include +#include #include "core/cell.h" using namespace hbase; @@ -41,36 +41,35 @@ void PopulateCells(std::vector > &cells) { switch (i) { case 5: { - cells.push_back(std::make_shared( - row, family, column, 1482113040506, "value-5", CellType::PUT)); - cells.push_back(std::make_shared( - row, family, column, 1482111803856, "value-X", CellType::PUT)); + cells.push_back( + std::make_shared(row, family, column, 1482113040506, "value-5", CellType::PUT)); + cells.push_back( + std::make_shared(row, family, column, 1482111803856, "value-X", CellType::PUT)); break; } case 8: { - cells.push_back(std::make_shared( - row, family, column, 1482113040506, "value-8", CellType::PUT)); - cells.push_back(std::make_shared( - row, family, column, 1482111803856, "value-X", CellType::PUT)); - cells.push_back(std::make_shared( - row, family, column, 1482110969958, "value-Y", CellType::PUT)); + cells.push_back( + std::make_shared(row, family, column, 1482113040506, "value-8", CellType::PUT)); + cells.push_back( + std::make_shared(row, family, column, 1482111803856, "value-X", CellType::PUT)); + cells.push_back( + std::make_shared(row, family, column, 1482110969958, "value-Y", CellType::PUT)); break; } case 9: { - cells.push_back(std::make_shared( - row, family, column, 1482113040506, "value-9", CellType::PUT)); - cells.push_back(std::make_shared( - row, family, column, 1482111803856, "value-X", CellType::PUT)); - cells.push_back(std::make_shared( - row, family, column, 1482110969958, "value-Y", CellType::PUT)); - cells.push_back(std::make_shared( - row, family, column, 1482110876075, "value-Z", CellType::PUT)); + cells.push_back( + std::make_shared(row, family, column, 1482113040506, "value-9", CellType::PUT)); + cells.push_back( + std::make_shared(row, family, column, 1482111803856, "value-X", CellType::PUT)); + cells.push_back( + std::make_shared(row, family, column, 1482110969958, "value-Y", CellType::PUT)); + cells.push_back( + std::make_shared(row, family, column, 1482110876075, "value-Z", CellType::PUT)); break; } default: { - cells.push_back(std::make_shared(row, family, column, - std::numeric_limits::max(), - value, CellType::PUT)); + cells.push_back(std::make_shared( + row, family, column, std::numeric_limits::max(), value, CellType::PUT)); } } } @@ -111,12 +110,9 @@ TEST(Result, FilledResult) { // Value will be present as family and qualifier is present ASSERT_TRUE(result.Value("family-4", "column-4")); // Value should be present and match. - EXPECT_EQ(latest_cell->Value(), - (*result.ColumnLatestCell("family-4", "column-4")).Value()); - EXPECT_EQ("value-5", - (*result.ColumnLatestCell("family-5", "column-5")).Value()); - EXPECT_EQ("value-8", - (*result.ColumnLatestCell("family-8", "column-8")).Value()); + EXPECT_EQ(latest_cell->Value(), (*result.ColumnLatestCell("family-4", "column-4")).Value()); + EXPECT_EQ("value-5", (*result.ColumnLatestCell("family-5", "column-5")).Value()); + EXPECT_EQ("value-8", (*result.ColumnLatestCell("family-8", "column-8")).Value()); EXPECT_EQ("value-7", *result.Value("family-7", "column-7")); // Get cells for the given family and qualifier diff --git hbase-native-client/core/result.cc hbase-native-client/core/result.cc index 9842915..d73a5b2 100644 --- hbase-native-client/core/result.cc +++ hbase-native-client/core/result.cc @@ -23,15 +23,14 @@ namespace hbase { Result::~Result() {} -Result::Result(const std::vector > &cells, bool exists, - bool stale, bool partial) +Result::Result(const std::vector > &cells, bool exists, bool stale, + bool partial) : exists_(exists), stale_(stale), partial_(partial) { for (const auto &cell : cells) { cells_.push_back(cell); // We create the map when cells are added. unlike java where map is created // when result.getMap() is called - result_map_[cell->Family()][cell->Qualifier()][cell->Timestamp()] = - cell->Value(); + result_map_[cell->Family()][cell->Qualifier()][cell->Timestamp()] = cell->Value(); } row_ = (cells_.size() == 0 ? "" : cells_[0]->Row()); } @@ -44,17 +43,14 @@ Result::Result(const Result &result) { if (!result.cells_.empty()) { for (const auto &cell : result.cells_) { cells_.push_back(cell); - result_map_[cell->Family()][cell->Qualifier()][cell->Timestamp()] = - cell->Value(); + result_map_[cell->Family()][cell->Qualifier()][cell->Timestamp()] = cell->Value(); } } } -const std::vector > &Result::Cells() const { - return cells_; -} +const std::vector > &Result::Cells() const { return cells_; } -std::vector > Result::ColumnCells( - const std::string &family, const std::string &qualifier) const { +std::vector > Result::ColumnCells(const std::string &family, + const std::string &qualifier) const { std::vector > column_cells; // TODO implement a BinarySearch here ? for (const auto &cell : cells_) { @@ -65,8 +61,8 @@ std::vector > Result::ColumnCells( return column_cells; } -const std::shared_ptr Result::ColumnLatestCell( - const std::string &family, const std::string &qualifier) const { +const std::shared_ptr Result::ColumnLatestCell(const std::string &family, + const std::string &qualifier) const { // TODO implement a BinarySearch here ? for (const auto &cell : cells_) { // We find the latest(first) occurrence of the Cell for a given column and @@ -100,10 +96,8 @@ const ResultFamilyMap Result::FamilyMap(const std::string &family) const { if (!IsEmpty()) { for (auto itr = result_map_.begin(); itr != result_map_.end(); ++itr) { if (family == itr->first) { - for (auto qitr = itr->second.begin(); qitr != itr->second.end(); - ++qitr) { - for (auto vitr = qitr->second.begin(); vitr != qitr->second.end(); - ++vitr) { + for (auto qitr = itr->second.begin(); qitr != itr->second.end(); ++qitr) { + for (auto vitr = qitr->second.begin(); vitr != qitr->second.end(); ++vitr) { // We break after inserting the first value. Result.java takes only // the first value family_map[qitr->first] = vitr->second; diff --git hbase-native-client/core/result.h hbase-native-client/core/result.h index ecfdd55..cd41cf0 100644 --- hbase-native-client/core/result.h +++ hbase-native-client/core/result.h @@ -34,9 +34,9 @@ namespace hbase { * We need to have a reverse ordered map, when storing TS -> value, so that the * most recent value is stored first */ -using ResultMap = std::map< - std::string, std::map > > >; +using ResultMap = + std::map > > >; /** * @brief Map of qualifiers to values. @@ -48,8 +48,7 @@ class Result { /** * Constructors */ - Result(const std::vector > &cells, bool exists, - bool stale, bool partial); + Result(const std::vector > &cells, bool exists, bool stale, bool partial); Result(const Result &result); ~Result(); @@ -67,8 +66,8 @@ class Result { * @param family - column family * @param qualifier - column qualifier */ - std::vector > ColumnCells( - const std::string &family, const std::string &qualifier) const; + std::vector > ColumnCells(const std::string &family, + const std::string &qualifier) const; /** * @brief Returns the Cell for the most recent timestamp for a given family @@ -77,16 +76,15 @@ class Result { * @param family - column family. * @param qualifier - column qualifier */ - const std::shared_ptr ColumnLatestCell( - const std::string &family, const std::string &qualifier) const; + const std::shared_ptr ColumnLatestCell(const std::string &family, + const std::string &qualifier) const; /** * @brief Get the latest version of the specified family and qualifier. * @param family - column family * @param qualifier - column qualifier */ - std::shared_ptr Value(const std::string &family, - const std::string &qualifier) const; + std::shared_ptr Value(const std::string &family, const std::string &qualifier) const; /** * @brief Returns if the underlying Cell vector is empty or not diff --git hbase-native-client/core/scan-test.cc hbase-native-client/core/scan-test.cc index 0a4001a..9a26407 100644 --- hbase-native-client/core/scan-test.cc +++ hbase-native-client/core/scan-test.cc @@ -154,8 +154,7 @@ void ScanMethods(Scan &scan) { // Test initial values EXPECT_EQ(0, scan.Timerange().MinTimeStamp()); - EXPECT_EQ(std::numeric_limits::max(), - scan.Timerange().MaxTimeStamp()); + EXPECT_EQ(std::numeric_limits::max(), scan.Timerange().MaxTimeStamp()); // Set & Test new values using TimeRange and TimeStamp scan.SetTimeRange(1000, 2000); @@ -169,8 +168,7 @@ void ScanMethods(Scan &scan) { ASSERT_THROW(scan.SetTimeRange(-1000, 2000), std::runtime_error); ASSERT_THROW(scan.SetTimeRange(1000, -2000), std::runtime_error); ASSERT_THROW(scan.SetTimeRange(1000, 200), std::runtime_error); - ASSERT_THROW(scan.SetTimeStamp(std::numeric_limits::max()), - std::runtime_error); + ASSERT_THROW(scan.SetTimeStamp(std::numeric_limits::max()), std::runtime_error); } TEST(Scan, Object) { diff --git hbase-native-client/core/scan.cc hbase-native-client/core/scan.cc index 036acfb..5335abd 100644 --- hbase-native-client/core/scan.cc +++ hbase-native-client/core/scan.cc @@ -30,9 +30,7 @@ Scan::Scan() {} Scan::~Scan() {} -Scan::Scan(const std::string &start_row) : start_row_(start_row) { - CheckRow(start_row_); -} +Scan::Scan(const std::string &start_row) : start_row_(start_row) { CheckRow(start_row_); } Scan::Scan(const std::string &start_row, const std::string &stop_row) : start_row_(start_row), stop_row_(stop_row) { @@ -76,8 +74,7 @@ Scan &Scan::operator=(const Scan &scan) { Scan::Scan(const Get &get) { cache_blocks_ = get.CacheBlocks(); max_versions_ = get.MaxVersions(); - tr_.reset(new TimeRange(get.Timerange().MinTimeStamp(), - get.Timerange().MaxTimeStamp())); + tr_.reset(new TimeRange(get.Timerange().MinTimeStamp(), get.Timerange().MaxTimeStamp())); family_map_.insert(get.Family().begin(), get.Family().end()); } @@ -97,8 +94,7 @@ Scan &Scan::AddFamily(const std::string &family) { } Scan &Scan::AddColumn(const std::string &family, const std::string &qualifier) { - const auto &it = std::find(family_map_[family].begin(), - family_map_[family].end(), qualifier); + const auto &it = std::find(family_map_[family].begin(), family_map_[family].end(), qualifier); /** * Check if any qualifiers are already present or not. * Add only if qualifiers for a given family are not present @@ -156,9 +152,7 @@ void Scan::SetLoadColumnFamiliesOnDemand(bool load_column_families_on_demand) { load_column_families_on_demand_ = load_column_families_on_demand; } -bool Scan::LoadColumnFamiliesOnDemand() const { - return load_column_families_on_demand_; -} +bool Scan::LoadColumnFamiliesOnDemand() const { return load_column_families_on_demand_; } Scan &Scan::SetMaxVersions(uint32_t max_versions) { max_versions_ = max_versions; @@ -167,9 +161,7 @@ Scan &Scan::SetMaxVersions(uint32_t max_versions) { int Scan::MaxVersions() const { return max_versions_; } -void Scan::SetMaxResultSize(int64_t max_result_size) { - max_result_size_ = max_result_size; -} +void Scan::SetMaxResultSize(int64_t max_result_size) { max_result_size_ = max_result_size; } int64_t Scan::MaxResultSize() const { return max_result_size_; } @@ -192,8 +184,7 @@ void Scan::CheckRow(const std::string &row) { throw std::runtime_error("Row length can't be 0"); } if (row_length > kMaxRowLength) { - throw std::runtime_error("Length of " + row + - " is greater than max row size: " + + throw std::runtime_error("Length of " + row + " is greater than max row size: " + std::to_string(kMaxRowLength)); } } diff --git hbase-native-client/core/simple-client.cc hbase-native-client/core/simple-client.cc index f3f6c42..90e7cd4 100644 --- hbase-native-client/core/simple-client.cc +++ hbase-native-client/core/simple-client.cc @@ -65,12 +65,11 @@ std::unique_ptr MakeRequest(uint64_t col, std::string region_name) { auto suf = folly::to(col); region->set_value(region_name); - region->set_type(RegionSpecifier_RegionSpecifierType:: - RegionSpecifier_RegionSpecifierType_REGION_NAME); + region->set_type( + RegionSpecifier_RegionSpecifierType::RegionSpecifier_RegionSpecifierType_REGION_NAME); auto mutation = msg->mutable_mutation(); mutation->set_row(FLAGS_row + suf); - mutation->set_mutate_type( - MutationProto_MutationType::MutationProto_MutationType_PUT); + mutation->set_mutate_type(MutationProto_MutationType::MutationProto_MutationType_PUT); auto column = mutation->add_column_value(); column->set_family("d"); auto qual = column->add_qualifier_value(); @@ -81,14 +80,12 @@ std::unique_ptr MakeRequest(uint64_t col, std::string region_name) { } int main(int argc, char *argv[]) { - google::SetUsageMessage( - "Simple client to get a single row from HBase on the comamnd line"); + google::SetUsageMessage("Simple client to get a single row from HBase on the comamnd line"); google::ParseCommandLineFlags(&argc, &argv, true); google::InitGoogleLogging(argv[0]); // Set up thread pools. - auto cpu_pool = - std::make_shared(FLAGS_threads); + auto cpu_pool = std::make_shared(FLAGS_threads); auto io_pool = std::make_shared(5); // Create the cache. @@ -105,14 +102,13 @@ int main(int argc, char *argv[]) { auto results = std::vector>{}; auto col = uint64_t{0}; for (; col < num_puts; col++) { - results.push_back(folly::makeFuture(col) - .via(cpu_pool.get()) - .then([loc](uint64_t col) { - return MakeRequest(col, loc->region_name()); - }) - .then([connection](std::unique_ptr req) { - return (*connection)(std::move(req)); - })); + results.push_back( + folly::makeFuture(col) + .via(cpu_pool.get()) + .then([loc](uint64_t col) { return MakeRequest(col, loc->region_name()); }) + .then([connection](std::unique_ptr req) { + return (*connection)(std::move(req)); + })); } auto allf = folly::collect(results).get(); diff --git hbase-native-client/core/time_range.cc hbase-native-client/core/time_range.cc index 8c37b29..04b70ec 100644 --- hbase-native-client/core/time_range.cc +++ hbase-native-client/core/time_range.cc @@ -25,9 +25,7 @@ namespace hbase { TimeRange::TimeRange() - : min_timestamp_(0L), - max_timestamp_(std::numeric_limits::max()), - all_time_(true) {} + : min_timestamp_(0L), max_timestamp_(std::numeric_limits::max()), all_time_(true) {} TimeRange::TimeRange(const TimeRange &tr) { this->all_time_ = tr.all_time_; @@ -53,8 +51,7 @@ TimeRange::TimeRange(int64_t min_timestamp) { TimeRange::TimeRange(int64_t min_timestamp, int64_t max_timestamp) { if (min_timestamp < 0 || max_timestamp < 0) { throw std::runtime_error("Timestamp cannot be negative. min_timestamp: " + - std::to_string(min_timestamp) + - ", max_timestamp:" + + std::to_string(min_timestamp) + ", max_timestamp:" + std::to_string(max_timestamp)); } if (max_timestamp < min_timestamp) { diff --git hbase-native-client/security/BUCK hbase-native-client/security/BUCK index 5b935d3..e176c90 100644 --- hbase-native-client/security/BUCK +++ hbase-native-client/security/BUCK @@ -19,12 +19,8 @@ # to a single server. cxx_library( name="security", - exported_headers=[ - "user.h", - ], - srcs=[ - ], - deps=[ - ], + exported_headers=["user.h",], + srcs=[], + deps=[], compiler_flags=['-Weffc++'], - visibility=['//core/...','//connection/...'],) + visibility=['//core/...', '//connection/...'],) diff --git hbase-native-client/security/user.h hbase-native-client/security/user.h index 795f5ac..8a15891 100644 --- hbase-native-client/security/user.h +++ hbase-native-client/security/user.h @@ -23,16 +23,15 @@ namespace hbase { namespace security { class User { -public: + public: explicit User(const std::string& user_name) : user_name_(user_name) {} - virtual ~User() = default; + virtual ~User() = default; - std::string user_name() {return user_name_;} + std::string user_name() { return user_name_; } - static std::shared_ptr defaultUser() { - return std::make_shared("__drwho"); - } -private: + static std::shared_ptr defaultUser() { return std::make_shared("__drwho"); } + + private: std::string user_name_; }; } diff --git hbase-native-client/serde/client-deserializer-test.cc hbase-native-client/serde/client-deserializer-test.cc index 8c571b1..a30f904 100644 --- hbase-native-client/serde/client-deserializer-test.cc +++ hbase-native-client/serde/client-deserializer-test.cc @@ -50,8 +50,7 @@ TEST(TestRpcSerde, TestGoodGetRequestFullRoundTrip) { // fill up the GetRequest. in.mutable_region()->set_value("test_region_id"); in.mutable_region()->set_type( - RegionSpecifier_RegionSpecifierType:: - RegionSpecifier_RegionSpecifierType_ENCODED_REGION_NAME); + RegionSpecifier_RegionSpecifierType::RegionSpecifier_RegionSpecifierType_ENCODED_REGION_NAME); in.mutable_get()->set_row("test_row"); // Create the buffer diff --git hbase-native-client/serde/rpc.cc hbase-native-client/serde/rpc.cc index e4ade22..3bdb489 100644 --- hbase-native-client/serde/rpc.cc +++ hbase-native-client/serde/rpc.cc @@ -70,15 +70,13 @@ int RpcSerde::ParseDelimited(const IOBuf *buf, Message *msg) { coded_stream.PushLimit(msg_size); // Parse the message. if (msg->MergeFromCodedStream(&coded_stream) == false) { - FB_LOG_EVERY_MS(ERROR, 1000) - << "Unable to read a protobuf message from data."; + FB_LOG_EVERY_MS(ERROR, 1000) << "Unable to read a protobuf message from data."; return -4; } // Make sure all the data was consumed. if (coded_stream.ConsumedEntireMessage() == false) { - FB_LOG_EVERY_MS(ERROR, 1000) - << "Orphaned data left after reading protobuf message"; + FB_LOG_EVERY_MS(ERROR, 1000) << "Orphaned data left after reading protobuf message"; return -5; } @@ -115,8 +113,8 @@ unique_ptr RpcSerde::Header(const string &user) { return PrependLength(SerializeMessage(h)); } -unique_ptr RpcSerde::Request(const uint32_t call_id, - const string &method, const Message *msg) { +unique_ptr RpcSerde::Request(const uint32_t call_id, const string &method, + const Message *msg) { pb::RequestHeader rq; rq.set_method_name(method); rq.set_call_id(call_id); @@ -169,8 +167,7 @@ unique_ptr RpcSerde::SerializeDelimited(const Message &msg) { // Now write the rest out. // We're using the protobuf output streams here to keep track // of where in the output array we are rather than IOBuf. - msg.SerializeWithCachedSizesToArray( - cos.GetDirectBufferForNBytesAndAdvance(msg_size)); + msg.SerializeWithCachedSizesToArray(cos.GetDirectBufferForNBytesAndAdvance(msg_size)); // Return the buffer. return buf; diff --git hbase-native-client/serde/rpc.h hbase-native-client/serde/rpc.h index 05ceee9..7d060c7 100644 --- hbase-native-client/serde/rpc.h +++ hbase-native-client/serde/rpc.h @@ -83,8 +83,7 @@ class RpcSerde { * - RequestHeader object * - The passed in Message object */ - std::unique_ptr Request(const uint32_t call_id, - const std::string &method, + std::unique_ptr Request(const uint32_t call_id, const std::string &method, const google::protobuf::Message *msg); /** @@ -94,21 +93,18 @@ class RpcSerde { * - A protobuf var int32 * - The message object seriailized after that. */ - std::unique_ptr SerializeDelimited( - const google::protobuf::Message &msg); + std::unique_ptr SerializeDelimited(const google::protobuf::Message &msg); /** * Serilalize a message. This does not add any length prepend. */ - std::unique_ptr SerializeMessage( - const google::protobuf::Message &msg); + std::unique_ptr SerializeMessage(const google::protobuf::Message &msg); /** * Prepend a length IOBuf to the given IOBuf chain. * This involves no copies or moves of the passed in data. */ - std::unique_ptr PrependLength( - std::unique_ptr msg); + std::unique_ptr PrependLength(std::unique_ptr msg); private: /* data */ diff --git hbase-native-client/serde/server-name-test.cc hbase-native-client/serde/server-name-test.cc index 73a68d6..87c493a 100644 --- hbase-native-client/serde/server-name-test.cc +++ hbase-native-client/serde/server-name-test.cc @@ -37,9 +37,7 @@ TEST(TestServerName, TestIps) { ASSERT_EQ(999, sn.port()); } -TEST(TestServerName, TestThrow) { - ASSERT_ANY_THROW(folly::to("Ther's no colon here")); -} +TEST(TestServerName, TestThrow) { ASSERT_ANY_THROW(folly::to("Ther's no colon here")); } TEST(TestServerName, TestIPV6) { auto sn = folly::to("[::::1]:123"); diff --git hbase-native-client/serde/zk.cc hbase-native-client/serde/zk.cc index 69b55fa..bf68400 100644 --- hbase-native-client/serde/zk.cc +++ hbase-native-client/serde/zk.cc @@ -46,8 +46,7 @@ bool ZkDeserializer::Parse(IOBuf *buf, Message *out) { // There should be a magic number for recoverable zk uint8_t magic_num = c.read(); if (magic_num != 255) { - LOG(ERROR) << "Magic number not in ZK znode data expected 255 got =" - << unsigned(magic_num); + LOG(ERROR) << "Magic number not in ZK znode data expected 255 got =" << unsigned(magic_num); throw runtime_error("Magic number not in znode data"); } // How long is the id?