HBASE-18725 [C++] Install header files as well as library
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/128fc306 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/128fc306 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/128fc306 Branch: refs/heads/HBASE-14850 Commit: 128fc3065117ec7c86d89dc3dacb0bc26e847639 Parents: 95da699 Author: Enis Soztutar <e...@apache.org> Authored: Mon Sep 11 18:36:11 2017 -0700 Committer: Enis Soztutar <e...@apache.org> Committed: Fri Sep 15 14:19:08 2017 -0700 ---------------------------------------------------------------------- hbase-native-client/.gitignore | 2 +- hbase-native-client/Makefile | 54 +- hbase-native-client/Makefile.protos | 14 +- hbase-native-client/bin/copy-protobuf.sh | 2 +- hbase-native-client/bin/copy-version.sh | 2 +- hbase-native-client/bin/cpplint.sh | 11 +- hbase-native-client/bin/format-code.sh | 9 +- hbase-native-client/connection/BUCK | 86 -- .../connection/client-dispatcher.cc | 115 --- .../connection/client-dispatcher.h | 77 -- .../connection/client-handler.cc | 145 ---- hbase-native-client/connection/client-handler.h | 89 -- .../connection/connection-factory.cc | 88 -- .../connection/connection-factory.h | 83 -- hbase-native-client/connection/connection-id.h | 93 --- .../connection/connection-pool-test.cc | 140 ---- .../connection/connection-pool.cc | 119 --- .../connection/connection-pool.h | 90 -- hbase-native-client/connection/pipeline.cc | 55 -- hbase-native-client/connection/pipeline.h | 63 -- hbase-native-client/connection/request.cc | 46 -- hbase-native-client/connection/request.h | 79 -- hbase-native-client/connection/response.h | 93 --- hbase-native-client/connection/rpc-client.cc | 119 --- hbase-native-client/connection/rpc-client.h | 83 -- hbase-native-client/connection/rpc-connection.h | 79 -- .../connection/rpc-fault-injector-inl.h | 41 - .../connection/rpc-fault-injector.cc | 21 - .../connection/rpc-fault-injector.h | 50 -- .../connection/rpc-test-server-handler.cc | 81 -- .../connection/rpc-test-server-handler.h | 47 -- .../connection/rpc-test-server.cc | 108 --- .../connection/rpc-test-server.h | 68 -- hbase-native-client/connection/rpc-test.cc | 284 ------- hbase-native-client/connection/sasl-handler.cc | 225 ----- hbase-native-client/connection/sasl-handler.h | 78 -- hbase-native-client/connection/sasl-util.cc | 92 --- hbase-native-client/connection/sasl-util.h | 46 -- hbase-native-client/connection/service.h | 30 - hbase-native-client/core/BUCK | 348 -------- hbase-native-client/core/action.h | 43 - hbase-native-client/core/append-test.cc | 105 --- hbase-native-client/core/append.cc | 53 -- hbase-native-client/core/append.h | 56 -- .../core/async-batch-rpc-retrying-caller.cc | 488 ----------- .../core/async-batch-rpc-retrying-caller.h | 185 ----- .../core/async-batch-rpc-retrying-test.cc | 577 ------------- .../core/async-client-scanner.cc | 142 ---- hbase-native-client/core/async-client-scanner.h | 119 --- hbase-native-client/core/async-connection.cc | 70 -- hbase-native-client/core/async-connection.h | 121 --- hbase-native-client/core/async-region-locator.h | 65 -- .../core/async-rpc-retrying-caller-factory.cc | 22 - .../core/async-rpc-retrying-caller-factory.h | 343 -------- .../core/async-rpc-retrying-caller.cc | 230 ------ .../core/async-rpc-retrying-caller.h | 115 --- .../core/async-rpc-retrying-test.cc | 420 ---------- .../core/async-scan-rpc-retrying-caller.cc | 448 ---------- .../core/async-scan-rpc-retrying-caller.h | 233 ------ .../core/async-table-result-scanner.cc | 161 ---- .../core/async-table-result-scanner.h | 98 --- hbase-native-client/core/cell-test.cc | 195 ----- hbase-native-client/core/cell.cc | 123 --- hbase-native-client/core/cell.h | 72 -- hbase-native-client/core/client-test.cc | 697 ---------------- hbase-native-client/core/client.cc | 55 -- hbase-native-client/core/client.h | 77 -- hbase-native-client/core/configuration-test.cc | 119 --- hbase-native-client/core/configuration.cc | 244 ------ hbase-native-client/core/configuration.h | 232 ------ .../core/connection-configuration.h | 207 ----- hbase-native-client/core/delete-test.cc | 124 --- hbase-native-client/core/delete.cc | 131 --- hbase-native-client/core/delete.h | 111 --- hbase-native-client/core/filter-test.cc | 141 ---- hbase-native-client/core/filter.h | 479 ----------- hbase-native-client/core/get-test.cc | 221 ----- hbase-native-client/core/get.cc | 123 --- hbase-native-client/core/get.h | 132 --- .../core/hbase-configuration-loader.cc | 208 ----- .../core/hbase-configuration-loader.h | 140 ---- .../core/hbase-configuration-test.cc | 375 --------- .../core/hbase-rpc-controller.cc | 22 - hbase-native-client/core/hbase-rpc-controller.h | 59 -- hbase-native-client/core/increment-test.cc | 129 --- hbase-native-client/core/increment.cc | 56 -- hbase-native-client/core/increment.h | 57 -- hbase-native-client/core/keyvalue-codec.cc | 69 -- hbase-native-client/core/keyvalue-codec.h | 147 ---- hbase-native-client/core/load-client.cc | 390 --------- .../core/location-cache-retry-test.cc | 112 --- hbase-native-client/core/location-cache-test.cc | 164 ---- hbase-native-client/core/location-cache.cc | 334 -------- hbase-native-client/core/location-cache.h | 219 ----- hbase-native-client/core/meta-utils.cc | 125 --- hbase-native-client/core/meta-utils.h | 76 -- hbase-native-client/core/multi-response.cc | 86 -- hbase-native-client/core/multi-response.h | 79 -- hbase-native-client/core/mutation.cc | 69 -- hbase-native-client/core/mutation.h | 96 --- hbase-native-client/core/put-test.cc | 135 --- hbase-native-client/core/put.cc | 68 -- hbase-native-client/core/put.h | 68 -- hbase-native-client/core/query.h | 54 -- hbase-native-client/core/raw-async-table.cc | 259 ------ hbase-native-client/core/raw-async-table.h | 115 --- .../core/raw-scan-result-consumer.h | 131 --- hbase-native-client/core/region-location.h | 78 -- hbase-native-client/core/region-request.h | 46 -- hbase-native-client/core/region-result.cc | 53 -- hbase-native-client/core/region-result.h | 55 -- .../core/request-converter-test.cc | 126 --- hbase-native-client/core/request-converter.cc | 368 --------- hbase-native-client/core/request-converter.h | 125 --- hbase-native-client/core/response-converter.cc | 221 ----- hbase-native-client/core/response-converter.h | 71 -- hbase-native-client/core/result-scanner.h | 47 -- hbase-native-client/core/result-test.cc | 322 -------- hbase-native-client/core/result.cc | 146 ---- hbase-native-client/core/result.h | 136 --- hbase-native-client/core/row.h | 62 -- .../core/scan-result-cache-test.cc | 177 ---- hbase-native-client/core/scan-result-cache.cc | 160 ---- hbase-native-client/core/scan-result-cache.h | 80 -- hbase-native-client/core/scan-test.cc | 228 ----- hbase-native-client/core/scan.cc | 186 ----- hbase-native-client/core/scan.h | 270 ------ hbase-native-client/core/scanner-test.cc | 368 --------- hbase-native-client/core/server-request.h | 62 -- hbase-native-client/core/simple-client.cc | 207 ----- hbase-native-client/core/table.cc | 144 ---- hbase-native-client/core/table.h | 151 ---- hbase-native-client/core/time-range-test.cc | 48 -- hbase-native-client/core/time-range.cc | 73 -- hbase-native-client/core/time-range.h | 58 -- hbase-native-client/core/zk-util-test.cc | 50 -- hbase-native-client/core/zk-util.cc | 62 -- hbase-native-client/core/zk-util.h | 46 -- hbase-native-client/exceptions/BUCK | 39 - .../exceptions/exception-test.cc | 64 -- hbase-native-client/exceptions/exception.cc | 128 --- hbase-native-client/exceptions/exception.h | 328 -------- hbase-native-client/if/AccessControl.proto | 123 --- hbase-native-client/if/Admin.proto | 310 ------- hbase-native-client/if/Aggregate.proto | 63 -- hbase-native-client/if/Authentication.proto | 82 -- hbase-native-client/if/BUCK | 48 -- hbase-native-client/if/Cell.proto | 67 -- hbase-native-client/if/Client.proto | 478 ----------- hbase-native-client/if/ClusterId.proto | 34 - hbase-native-client/if/ClusterStatus.proto | 227 ----- hbase-native-client/if/Comparator.proto | 74 -- hbase-native-client/if/Encryption.proto | 33 - hbase-native-client/if/ErrorHandling.proto | 58 -- hbase-native-client/if/FS.proto | 45 - hbase-native-client/if/Filter.proto | 171 ---- hbase-native-client/if/HBase.proto | 253 ------ hbase-native-client/if/HFile.proto | 49 -- hbase-native-client/if/LoadBalancer.proto | 29 - hbase-native-client/if/MapReduce.proto | 37 - hbase-native-client/if/Master.proto | 828 ------------------- hbase-native-client/if/MasterProcedure.proto | 285 ------- hbase-native-client/if/MultiRowMutation.proto | 45 - hbase-native-client/if/Procedure.proto | 119 --- hbase-native-client/if/Quota.proto | 76 -- hbase-native-client/if/RPC.proto | 137 --- hbase-native-client/if/RSGroup.proto | 34 - hbase-native-client/if/RSGroupAdmin.proto | 136 --- hbase-native-client/if/RegionNormalizer.proto | 28 - hbase-native-client/if/RegionServerStatus.proto | 158 ---- hbase-native-client/if/RowProcessor.proto | 45 - hbase-native-client/if/SecureBulkLoad.proto | 72 -- hbase-native-client/if/Snapshot.proto | 66 -- hbase-native-client/if/Tracing.proto | 33 - hbase-native-client/if/VisibilityLabels.proto | 83 -- hbase-native-client/if/WAL.proto | 173 ---- hbase-native-client/if/ZooKeeper.proto | 176 ---- hbase-native-client/if/test.proto | 43 - hbase-native-client/if/test_rpc_service.proto | 36 - hbase-native-client/include/hbase/client/BUCK | 93 +++ .../include/hbase/client/action.h | 43 + .../include/hbase/client/append.h | 56 ++ .../client/async-batch-rpc-retrying-caller.h | 185 +++++ .../include/hbase/client/async-client-scanner.h | 119 +++ .../include/hbase/client/async-connection.h | 121 +++ .../include/hbase/client/async-region-locator.h | 65 ++ .../client/async-rpc-retrying-caller-factory.h | 343 ++++++++ .../hbase/client/async-rpc-retrying-caller.h | 115 +++ .../client/async-scan-rpc-retrying-caller.h | 233 ++++++ .../hbase/client/async-table-result-scanner.h | 98 +++ hbase-native-client/include/hbase/client/cell.h | 72 ++ .../include/hbase/client/client.h | 77 ++ .../include/hbase/client/configuration.h | 232 ++++++ .../hbase/client/connection-configuration.h | 207 +++++ .../include/hbase/client/delete.h | 111 +++ .../include/hbase/client/filter.h | 479 +++++++++++ hbase-native-client/include/hbase/client/get.h | 132 +++ .../hbase/client/hbase-configuration-loader.h | 140 ++++ .../include/hbase/client/hbase-rpc-controller.h | 59 ++ .../include/hbase/client/increment.h | 57 ++ .../include/hbase/client/keyvalue-codec.h | 147 ++++ .../include/hbase/client/location-cache.h | 219 +++++ .../include/hbase/client/meta-utils.h | 76 ++ .../include/hbase/client/multi-response.h | 79 ++ .../include/hbase/client/mutation.h | 96 +++ hbase-native-client/include/hbase/client/put.h | 68 ++ .../include/hbase/client/query.h | 54 ++ .../include/hbase/client/raw-async-table.h | 114 +++ .../hbase/client/raw-scan-result-consumer.h | 131 +++ .../include/hbase/client/region-location.h | 78 ++ .../include/hbase/client/region-request.h | 46 ++ .../include/hbase/client/region-result.h | 55 ++ .../include/hbase/client/request-converter.h | 125 +++ .../include/hbase/client/response-converter.h | 71 ++ .../include/hbase/client/result-scanner.h | 47 ++ .../include/hbase/client/result.h | 136 +++ hbase-native-client/include/hbase/client/row.h | 62 ++ .../include/hbase/client/scan-result-cache.h | 80 ++ hbase-native-client/include/hbase/client/scan.h | 270 ++++++ .../include/hbase/client/server-request.h | 62 ++ .../include/hbase/client/table.h | 151 ++++ .../include/hbase/client/time-range.h | 58 ++ .../include/hbase/client/zk-util.h | 46 ++ .../include/hbase/connection/BUCK | 57 ++ .../hbase/connection/client-dispatcher.h | 77 ++ .../include/hbase/connection/client-handler.h | 89 ++ .../hbase/connection/connection-factory.h | 83 ++ .../include/hbase/connection/connection-id.h | 93 +++ .../include/hbase/connection/connection-pool.h | 90 ++ .../include/hbase/connection/pipeline.h | 63 ++ .../include/hbase/connection/request.h | 79 ++ .../include/hbase/connection/response.h | 93 +++ .../include/hbase/connection/rpc-client.h | 83 ++ .../include/hbase/connection/rpc-connection.h | 79 ++ .../hbase/connection/rpc-fault-injector-inl.h | 41 + .../hbase/connection/rpc-fault-injector.h | 50 ++ .../hbase/connection/rpc-test-server-handler.h | 47 ++ .../include/hbase/connection/rpc-test-server.h | 68 ++ .../include/hbase/connection/sasl-handler.h | 78 ++ .../include/hbase/connection/sasl-util.h | 46 ++ .../include/hbase/connection/service.h | 30 + .../include/hbase/exceptions/BUCK | 28 + .../include/hbase/exceptions/exception.h | 328 ++++++++ hbase-native-client/include/hbase/security/BUCK | 30 + .../include/hbase/security/user.h | 46 ++ hbase-native-client/include/hbase/serde/BUCK | 37 + .../include/hbase/serde/cell-outputstream.h | 53 ++ .../include/hbase/serde/cell-scanner.h | 50 ++ hbase-native-client/include/hbase/serde/codec.h | 50 ++ .../include/hbase/serde/region-info.h | 44 + .../include/hbase/serde/rpc-serde.h | 155 ++++ .../include/hbase/serde/server-name.h | 47 ++ .../include/hbase/serde/table-name.h | 58 ++ hbase-native-client/include/hbase/serde/zk.h | 49 ++ hbase-native-client/include/hbase/utils/BUCK | 40 + .../include/hbase/utils/bytes-util.h | 68 ++ .../include/hbase/utils/concurrent-map.h | 130 +++ .../include/hbase/utils/connection-util.h | 62 ++ .../include/hbase/utils/optional.h | 32 + .../include/hbase/utils/sys-util.h | 39 + .../include/hbase/utils/time-util.h | 71 ++ .../include/hbase/utils/user-util.h | 54 ++ hbase-native-client/security/BUCK | 30 - hbase-native-client/security/user.h | 46 -- hbase-native-client/serde/BUCK | 96 --- hbase-native-client/serde/cell-outputstream.h | 53 -- hbase-native-client/serde/cell-scanner.h | 50 -- .../serde/client-deserializer-test.cc | 64 -- .../serde/client-serializer-test.cc | 75 -- hbase-native-client/serde/codec.h | 50 -- .../serde/region-info-deserializer-test.cc | 53 -- hbase-native-client/serde/region-info.h | 44 - hbase-native-client/serde/rpc-serde.cc | 261 ------ hbase-native-client/serde/rpc-serde.h | 155 ---- hbase-native-client/serde/server-name-test.cc | 47 -- hbase-native-client/serde/server-name.h | 47 -- hbase-native-client/serde/table-name-test.cc | 54 -- hbase-native-client/serde/table-name.h | 58 -- .../serde/zk-deserializer-test.cc | 123 --- hbase-native-client/serde/zk.cc | 77 -- hbase-native-client/serde/zk.h | 49 -- hbase-native-client/src/hbase/client/BUCK | 301 +++++++ .../src/hbase/client/append-test.cc | 105 +++ hbase-native-client/src/hbase/client/append.cc | 53 ++ .../client/async-batch-rpc-retrying-caller.cc | 488 +++++++++++ .../client/async-batch-rpc-retrying-test.cc | 577 +++++++++++++ .../src/hbase/client/async-client-scanner.cc | 142 ++++ .../src/hbase/client/async-connection.cc | 70 ++ .../client/async-rpc-retrying-caller-factory.cc | 22 + .../hbase/client/async-rpc-retrying-caller.cc | 230 ++++++ .../src/hbase/client/async-rpc-retrying-test.cc | 420 ++++++++++ .../client/async-scan-rpc-retrying-caller.cc | 448 ++++++++++ .../hbase/client/async-table-result-scanner.cc | 161 ++++ .../src/hbase/client/cell-test.cc | 195 +++++ hbase-native-client/src/hbase/client/cell.cc | 123 +++ .../src/hbase/client/client-test.cc | 697 ++++++++++++++++ hbase-native-client/src/hbase/client/client.cc | 55 ++ .../src/hbase/client/configuration-test.cc | 119 +++ .../src/hbase/client/configuration.cc | 244 ++++++ .../src/hbase/client/delete-test.cc | 124 +++ hbase-native-client/src/hbase/client/delete.cc | 131 +++ .../src/hbase/client/filter-test.cc | 141 ++++ .../src/hbase/client/get-test.cc | 221 +++++ hbase-native-client/src/hbase/client/get.cc | 123 +++ .../hbase/client/hbase-configuration-loader.cc | 208 +++++ .../hbase/client/hbase-configuration-test.cc | 375 +++++++++ .../src/hbase/client/hbase-rpc-controller.cc | 22 + .../src/hbase/client/increment-test.cc | 129 +++ .../src/hbase/client/increment.cc | 56 ++ .../src/hbase/client/keyvalue-codec.cc | 69 ++ .../src/hbase/client/load-client.cc | 390 +++++++++ .../hbase/client/location-cache-retry-test.cc | 112 +++ .../src/hbase/client/location-cache-test.cc | 164 ++++ .../src/hbase/client/location-cache.cc | 334 ++++++++ .../src/hbase/client/meta-utils.cc | 125 +++ .../src/hbase/client/multi-response.cc | 86 ++ .../src/hbase/client/mutation.cc | 69 ++ .../src/hbase/client/put-test.cc | 135 +++ hbase-native-client/src/hbase/client/put.cc | 68 ++ .../src/hbase/client/raw-async-table.cc | 260 ++++++ .../src/hbase/client/region-result.cc | 53 ++ .../src/hbase/client/request-converter-test.cc | 126 +++ .../src/hbase/client/request-converter.cc | 368 +++++++++ .../src/hbase/client/response-converter.cc | 221 +++++ .../src/hbase/client/result-test.cc | 322 ++++++++ hbase-native-client/src/hbase/client/result.cc | 146 ++++ .../src/hbase/client/scan-result-cache-test.cc | 177 ++++ .../src/hbase/client/scan-result-cache.cc | 160 ++++ .../src/hbase/client/scan-test.cc | 228 +++++ hbase-native-client/src/hbase/client/scan.cc | 186 +++++ .../src/hbase/client/scanner-test.cc | 368 +++++++++ .../src/hbase/client/simple-client.cc | 207 +++++ hbase-native-client/src/hbase/client/table.cc | 144 ++++ .../src/hbase/client/time-range-test.cc | 48 ++ .../src/hbase/client/time-range.cc | 73 ++ .../src/hbase/client/zk-util-test.cc | 50 ++ hbase-native-client/src/hbase/client/zk-util.cc | 62 ++ hbase-native-client/src/hbase/connection/BUCK | 68 ++ .../src/hbase/connection/client-dispatcher.cc | 115 +++ .../src/hbase/connection/client-handler.cc | 145 ++++ .../src/hbase/connection/connection-factory.cc | 88 ++ .../hbase/connection/connection-pool-test.cc | 140 ++++ .../src/hbase/connection/connection-pool.cc | 119 +++ .../src/hbase/connection/pipeline.cc | 55 ++ .../src/hbase/connection/request.cc | 46 ++ .../src/hbase/connection/rpc-client.cc | 119 +++ .../src/hbase/connection/rpc-fault-injector.cc | 21 + .../hbase/connection/rpc-test-server-handler.cc | 81 ++ .../src/hbase/connection/rpc-test-server.cc | 108 +++ .../src/hbase/connection/rpc-test.cc | 284 +++++++ .../src/hbase/connection/sasl-handler.cc | 225 +++++ .../src/hbase/connection/sasl-util.cc | 92 +++ hbase-native-client/src/hbase/exceptions/BUCK | 37 + .../src/hbase/exceptions/exception-test.cc | 64 ++ .../src/hbase/exceptions/exception.cc | 128 +++ .../src/hbase/if/AccessControl.proto | 123 +++ hbase-native-client/src/hbase/if/Admin.proto | 310 +++++++ .../src/hbase/if/Aggregate.proto | 63 ++ .../src/hbase/if/Authentication.proto | 82 ++ hbase-native-client/src/hbase/if/BUCK | 49 ++ hbase-native-client/src/hbase/if/Cell.proto | 67 ++ hbase-native-client/src/hbase/if/Client.proto | 478 +++++++++++ .../src/hbase/if/ClusterId.proto | 34 + .../src/hbase/if/ClusterStatus.proto | 227 +++++ .../src/hbase/if/Comparator.proto | 74 ++ .../src/hbase/if/Encryption.proto | 33 + .../src/hbase/if/ErrorHandling.proto | 58 ++ hbase-native-client/src/hbase/if/FS.proto | 45 + hbase-native-client/src/hbase/if/Filter.proto | 171 ++++ hbase-native-client/src/hbase/if/HBase.proto | 253 ++++++ hbase-native-client/src/hbase/if/HFile.proto | 49 ++ .../src/hbase/if/LoadBalancer.proto | 29 + .../src/hbase/if/MapReduce.proto | 37 + hbase-native-client/src/hbase/if/Master.proto | 828 +++++++++++++++++++ .../src/hbase/if/MasterProcedure.proto | 285 +++++++ .../src/hbase/if/MultiRowMutation.proto | 45 + .../src/hbase/if/Procedure.proto | 119 +++ hbase-native-client/src/hbase/if/Quota.proto | 76 ++ hbase-native-client/src/hbase/if/RPC.proto | 137 +++ hbase-native-client/src/hbase/if/RSGroup.proto | 34 + .../src/hbase/if/RSGroupAdmin.proto | 136 +++ .../src/hbase/if/RegionNormalizer.proto | 28 + .../src/hbase/if/RegionServerStatus.proto | 158 ++++ .../src/hbase/if/RowProcessor.proto | 45 + .../src/hbase/if/SecureBulkLoad.proto | 72 ++ hbase-native-client/src/hbase/if/Snapshot.proto | 66 ++ hbase-native-client/src/hbase/if/Tracing.proto | 33 + .../src/hbase/if/VisibilityLabels.proto | 83 ++ hbase-native-client/src/hbase/if/WAL.proto | 173 ++++ .../src/hbase/if/ZooKeeper.proto | 176 ++++ hbase-native-client/src/hbase/if/test.proto | 43 + .../src/hbase/if/test_rpc_service.proto | 36 + hbase-native-client/src/hbase/security/BUCK | 27 + hbase-native-client/src/hbase/serde/BUCK | 86 ++ .../src/hbase/serde/client-deserializer-test.cc | 64 ++ .../src/hbase/serde/client-serializer-test.cc | 75 ++ .../serde/region-info-deserializer-test.cc | 53 ++ .../src/hbase/serde/rpc-serde.cc | 261 ++++++ .../src/hbase/serde/server-name-test.cc | 47 ++ .../src/hbase/serde/table-name-test.cc | 54 ++ .../src/hbase/serde/zk-deserializer-test.cc | 123 +++ hbase-native-client/src/hbase/serde/zk.cc | 77 ++ hbase-native-client/src/hbase/test-util/BUCK | 53 ++ .../src/hbase/test-util/mini-cluster.cc | 311 +++++++ .../src/hbase/test-util/mini-cluster.h | 81 ++ .../src/hbase/test-util/test-util.cc | 105 +++ .../src/hbase/test-util/test-util.h | 78 ++ hbase-native-client/src/hbase/utils/BUCK | 57 ++ .../src/hbase/utils/bytes-util-test.cc | 69 ++ .../src/hbase/utils/bytes-util.cc | 88 ++ .../src/hbase/utils/concurrent-map-test.cc | 36 + .../src/hbase/utils/connection-util.cc | 26 + .../src/hbase/utils/user-util-test.cc | 35 + .../src/hbase/utils/user-util.cc | 77 ++ hbase-native-client/test-util/BUCK | 52 -- hbase-native-client/test-util/mini-cluster.cc | 311 ------- hbase-native-client/test-util/mini-cluster.h | 81 -- hbase-native-client/test-util/test-util.cc | 105 --- hbase-native-client/test-util/test-util.h | 78 -- hbase-native-client/utils/BUCK | 64 -- hbase-native-client/utils/bytes-util-test.cc | 69 -- hbase-native-client/utils/bytes-util.cc | 88 -- hbase-native-client/utils/bytes-util.h | 68 -- .../utils/concurrent-map-test.cc | 36 - hbase-native-client/utils/concurrent-map.h | 130 --- hbase-native-client/utils/connection-util.cc | 26 - hbase-native-client/utils/connection-util.h | 62 -- hbase-native-client/utils/optional.h | 32 - hbase-native-client/utils/sys-util.h | 39 - hbase-native-client/utils/time-util.h | 71 -- hbase-native-client/utils/user-util-test.cc | 35 - hbase-native-client/utils/user-util.cc | 77 -- hbase-native-client/utils/user-util.h | 54 -- 433 files changed, 27390 insertions(+), 27162 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/.gitignore ---------------------------------------------------------------------- diff --git a/hbase-native-client/.gitignore b/hbase-native-client/.gitignore index c99ce59..e8dd42d 100644 --- a/hbase-native-client/.gitignore +++ b/hbase-native-client/.gitignore @@ -26,4 +26,4 @@ third-party/* /gcc-debug/ # Generated files -utils/version.h +src/hbase/utils/version.h http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/Makefile ---------------------------------------------------------------------- diff --git a/hbase-native-client/Makefile b/hbase-native-client/Makefile index a291dfa..4d6430c 100644 --- a/hbase-native-client/Makefile +++ b/hbase-native-client/Makefile @@ -19,17 +19,20 @@ CC := g++ LD := g++ +SRC_HBASE := src/hbase +INCLUDE_HBASE := include/ BUILD_PATH := build DEBUG_PATH := $(BUILD_PATH)/debug RELEASE_PATH := $(BUILD_PATH)/release -PROTO_SRC_DIR := if -PROTO_CXX_DIR := $(BUILD_PATH)/if -MODULES := connection core exceptions security serde utils +PROTO_SRC_DIR := $(SRC_HBASE)/if +PROTO_CXX_DIR := $(BUILD_PATH)/$(PROTO_SRC_DIR) +MODULES := connection client exceptions security serde utils TEST_MODULES := test-util # These modules contain test code, not included in the build for the lib -SRC_DIR := $(MODULES) -DEBUG_BUILD_DIR := $(addprefix $(DEBUG_PATH)/,$(MODULES)) -RELEASE_BUILD_DIR := $(addprefix $(RELEASE_PATH)/,$(MODULES)) -INCLUDE_DIR := . $(BUILD_PATH) +SRC_DIR := $(addprefix $(SRC_HBASE)/,$(MODULES)) +DEBUG_BUILD_DIR := $(addprefix $(DEBUG_PATH)/hbase/,$(MODULES)) +RELEASE_BUILD_DIR := $(addprefix $(RELEASE_PATH)/hbase/,$(MODULES)) + +INCLUDE_DIR := . src $(BUILD_PATH)/src $(INCLUDE_HBASE) TEST_BUILD_INCLUDE_DIR := $(INLCUDE_DIR) $(JAVA_HOME)/include/ $(JAVA_HOME)/include/linux #flags to pass to the CPP compiler & linker @@ -42,14 +45,14 @@ LINKFLAG := -shared #define list of source files and object files ALLSRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cc)) EXCLUDE_SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*-test.cc)) \ - core/simple-client.cc core/load-client.cc + $(SRC_HBASE)/client/simple-client.cc $(SRC_HBASE)/client/load-client.cc SRC := $(filter-out $(EXCLUDE_SRC), $(ALLSRC)) -PROTOSRC := $(patsubst %.proto, $(addprefix $(BUILD_PATH)/,%.pb.cc),$(wildcard if/*.proto)) -PROTOHDR := $(patsubst %.proto, $(addprefix $(BUILD_PATH)/,%.pb.h),$(wildcard if/*.proto)) -DEBUG_OBJ := $(patsubst %.cc,$(DEBUG_PATH)/%.o,$(SRC)) -DEBUG_OBJ += $(patsubst %.cc,$(DEBUG_PATH)/%.o,$(PROTOSRC)) -RELEASE_OBJ := $(patsubst %.cc,$(RELEASE_PATH)/%.o,$(SRC)) -RELEASE_OBJ += $(patsubst %.cc,$(RELEASE_PATH)/%.o,$(PROTOSRC)) +PROTOSRC := $(patsubst $(PROTO_SRC_DIR)/%.proto, $(addprefix $(PROTO_CXX_DIR)/,%.pb.cc),$(wildcard $(PROTO_SRC_DIR)/*.proto)) +PROTOHDR := $(patsubst $(PROTO_SRC_DIR)/%.proto, $(addprefix $(PROTO_CXX_DIR)/,%.pb.h),$(wildcard $(PROTO_SRC_DIR)/*.proto)) +DEBUG_OBJ := $(patsubst $(SRC_HBASE)/%.cc,$(DEBUG_PATH)/hbase/%.o,$(SRC)) +DEBUG_OBJ += $(patsubst $(PROTO_CXX_DIR)/%.cc,$(DEBUG_PATH)/hbase/if/%.o,$(PROTOSRC)) +RELEASE_OBJ := $(patsubst $(SRC_HBASE)/%.cc,$(RELEASE_PATH)/hbase/%.o,$(SRC)) +RELEASE_OBJ += $(patsubst $(PROTO_CXX_DIR)/%.cc,$(RELEASE_PATH)/hbase/if/%.o,$(PROTOSRC)) INCLUDES := $(addprefix -I,$(INCLUDE_DIR)) LIB_DIR := /usr/local @@ -59,8 +62,9 @@ LIB_RELEASE := $(RELEASE_PATH)/libHBaseClient.so ARC_RELEASE := $(RELEASE_PATH)/libHBaseClient.a LIB_DEBUG := $(DEBUG_PATH)/libHBaseClient_d.so ARC_DEBUG := $(DEBUG_PATH)/libHBaseClient_d.a +LOCAL_INCLUDE_DIR := /usr/local/include/ -build: checkdirs protos $(LIB_DEBUG) $(LIB_RELEASE) $(ARC_DEBUG) $(ARC_RELEASE) +build: checkdirs protos copyfiles $(LIB_DEBUG) $(LIB_RELEASE) $(ARC_DEBUG) $(ARC_RELEASE) vpath %.cc $(SRC_DIR) @@ -80,7 +84,7 @@ $1/%.o: %.cc $(CC) -c $$< -o $$@ -MF$$(@:%.o=%.d) -MT$$@ $(CPPFLAGS_RELEASE) $(INCLUDES) endef -.PHONY: all clean install +.PHONY: all clean install copyfiles checkdirs: $(DEBUG_BUILD_DIR) $(RELEASE_BUILD_DIR) $(PROTO_CXX_DIR) @@ -88,22 +92,32 @@ copyfiles: @bin/copy-protobuf.sh @bin/copy-version.sh +# .proto files are in src/hbase/if. These are compiled into C++ code by the +# protoc compiler, and turned into .cc and .h files under build/src/hbase/if $(PROTO_CXX_DIR)/%.pb.cc $(PROTO_CXX_DIR)/%.pb.h: $(PROTO_SRC_DIR)/%.proto @protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_CXX_DIR) $< -#Run parallel jobs to speed up compilation +# protos target compiles the .cc and .h files into .o files for the protobuf +# generated source files protos: $(PROTO_CXX_DIR) $(PROTOSRC) $(PROTOHDR) @make -j8 all -f Makefile.protos -install: +install_headers: + cp -r $(INCLUDE_HBASE)/hbase $(LOCAL_INCLUDE_DIR) + cp -r $(PROTO_CXX_DIR) $(LOCAL_INCLUDE_DIR)/hbase/ + +uninstall_headers: + rm -rf $(LOCAL_INCLUDE_DIR)/hbase + +install: install_headers cp $(LIB_RELEASE) $(LIB_LIBDIR)/libHBaseClient.so cp $(ARC_RELEASE) $(LIB_LIBDIR)/libHBaseClient.a cp $(LIB_DEBUG) $(LIB_LIBDIR)/libHBaseClient_d.so cp $(ARC_DEBUG) $(LIB_LIBDIR)/libHBaseClient_d.a ldconfig -uninstall: - rm -f $(LIB_LIBDIR)/libHBaseClient.so $(LIB_LIBDIR)/libHBaseClient.a $(LIB_LIBDIR)/libHBaseClient_d.so $(ARC_DEBUG) $(LIB_LIBDIR)/libHBaseClient_d.a +uninstall: uninstall_headers + rm -f $(LIB_LIBDIR)/libHBaseClient.so $(LIB_LIBDIR)/libHBaseClient.a $(LIB_LIBDIR)/libHBaseClient_d.so $(LIB_LIBDIR)/libHBaseClient_d.a ldconfig $(PROTO_CXX_DIR): http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/Makefile.protos ---------------------------------------------------------------------- diff --git a/hbase-native-client/Makefile.protos b/hbase-native-client/Makefile.protos index 4cf8982..8712029 100644 --- a/hbase-native-client/Makefile.protos +++ b/hbase-native-client/Makefile.protos @@ -21,11 +21,11 @@ CC := g++ BUILD_PATH := build DEBUG_PATH := $(BUILD_PATH)/debug RELEASE_PATH := $(BUILD_PATH)/release -MODULES := $(BUILD_PATH)/if -SRC_DIR := $(MODULES) -DEBUG_BUILD_DIR := $(addprefix $(DEBUG_PATH)/,$(MODULES)) -RELEASE_BUILD_DIR := $(addprefix $(RELEASE_PATH)/,$(MODULES)) -INCLUDE_DIR := . $(BUILD_PATH)/if +MODULES := if +SRC_DIR := $(BUILD_PATH)/src/hbase/$(MODULES) +DEBUG_BUILD_DIR := $(addprefix $(DEBUG_PATH)/hbase/,$(MODULES)) +RELEASE_BUILD_DIR := $(addprefix $(RELEASE_PATH)/hbase/,$(MODULES)) +INCLUDE_DIR := . $(BUILD_PATH)/src/hbase/if #flags to pass to the CPP compiler & linker CPPFLAGS_DEBUG := -D_GLIBCXX_USE_CXX11_ABI=0 -g -Wall -std=c++14 -pedantic -fPIC -MMD -MP @@ -33,8 +33,8 @@ CPPFLAGS_RELEASE := -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -O2 -Wall -std=c++14 -pe #define list of source files and object files SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cc)) -DEBUG_OBJ := $(patsubst %.cc,$(DEBUG_PATH)/%.o,$(SRC)) -RELEASE_OBJ := $(patsubst %.cc,$(RELEASE_PATH)/%.o,$(SRC)) +DEBUG_OBJ := $(patsubst $(SRC_DIR)/%.cc,$(DEBUG_PATH)/hbase/if/%.o,$(SRC)) +RELEASE_OBJ := $(patsubst $(SRC_DIR)/%.cc,$(RELEASE_PATH)/hbase/if/%.o,$(SRC)) INCLUDES := $(addprefix -I,$(INCLUDE_DIR)) all: $(DEBUG_BUILD_DIR) $(RELEASE_BUILD_DIR) $(DEBUG_OBJ) $(RELEASE_OBJ) http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/bin/copy-protobuf.sh ---------------------------------------------------------------------- diff --git a/hbase-native-client/bin/copy-protobuf.sh b/hbase-native-client/bin/copy-protobuf.sh index f727800..47544c8 100755 --- a/hbase-native-client/bin/copy-protobuf.sh +++ b/hbase-native-client/bin/copy-protobuf.sh @@ -20,5 +20,5 @@ IFS=$'\n\t' BIN_DIR=$(dirname "$0") PB_SOURCE_DIR="${BIN_DIR}/../../hbase-protocol/src/main/protobuf/" -PB_DEST_DIR="${BIN_DIR}/../if/" +PB_DEST_DIR="${BIN_DIR}/../src/hbase/if/" rsync -r --exclude BUCK ${PB_SOURCE_DIR} ${PB_DEST_DIR} http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/bin/copy-version.sh ---------------------------------------------------------------------- diff --git a/hbase-native-client/bin/copy-version.sh b/hbase-native-client/bin/copy-version.sh index b33db7a..e2b707f 100755 --- a/hbase-native-client/bin/copy-version.sh +++ b/hbase-native-client/bin/copy-version.sh @@ -21,5 +21,5 @@ IFS=$'\n\t' # Copy the version.h generated from hbase-common/src/saveVersion.sh script via the mvn build BIN_DIR=$(dirname "$0") VERSION_SOURCE_DIR="${BIN_DIR}/../../hbase-common/target/generated-sources/native/utils/" -VERSION_DEST_DIR="${BIN_DIR}/../utils/" +VERSION_DEST_DIR="${BIN_DIR}/../include/hbase/utils/" cp $VERSION_SOURCE_DIR/* $VERSION_DEST_DIR/ http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/bin/cpplint.sh ---------------------------------------------------------------------- diff --git a/hbase-native-client/bin/cpplint.sh b/hbase-native-client/bin/cpplint.sh index 3684c2e..7a27945 100755 --- a/hbase-native-client/bin/cpplint.sh +++ b/hbase-native-client/bin/cpplint.sh @@ -20,6 +20,8 @@ IFS=$'\n\t' CPPLINT_LOC=https://raw.githubusercontent.com/google/styleguide/gh-pages/cpplint/cpplint.py OUTPUT=build/cpplint.py +declare -a MODULES=( client connection exceptions security serde utils test-util ) + # Download if not already there wget -nc $CPPLINT_LOC -O $OUTPUT @@ -27,4 +29,11 @@ wget -nc $CPPLINT_LOC -O $OUTPUT # Exclude the following rules: build/header_guard (We use #pragma once instead) # readability/todo (TODOs are generic) # build/c++11 (We are building with c++14) -find core connection exceptions serde utils test-util security -name "*.h" -or -name "*.cc" | xargs -P8 python $OUTPUT --filter=-build/header_guard,-readability/todo,-build/c++11 --linelength=100 +for m in ${MODULES[@]}; do + if [ $m != "security" ]; then #These are empty + exec find src/hbase/$m -name "*.h" -or -name "*.cc" | xargs -P8 python $OUTPUT --filter=-build/header_guard,-readability/todo,-build/c++11 --linelength=100 + fi + if [ $m != "test-util" ]; then + exec find include/hbase/$m -name "*.h" -or -name "*.cc" | xargs -P8 python $OUTPUT --filter=-build/header_guard,-readability/todo,-build/c++11 --linelength=100 + fi +done http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/bin/format-code.sh ---------------------------------------------------------------------- diff --git a/hbase-native-client/bin/format-code.sh b/hbase-native-client/bin/format-code.sh index fe236d8..301167e 100755 --- a/hbase-native-client/bin/format-code.sh +++ b/hbase-native-client/bin/format-code.sh @@ -18,6 +18,11 @@ set -euo pipefail IFS=$'\n\t' +declare -a MODULES=( client connection exceptions security serde utils test-util ) -find core connection exceptions serde utils test-util security -name "*.h" -or -name "*.cc" | xargs -P8 clang-format -i --style='{BasedOnStyle: Google, ColumnLimit: 100}' -find core connection exceptions serde utils test-util third-party security -name "BUCK" | xargs -P8 yapf -i --style=google +for m in ${MODULES[@]}; do + find src/hbase/$m -name "*.h" -or -name "*.cc" | xargs -P8 clang-format -i --style='{BasedOnStyle: Google, ColumnLimit: 100}' + find src/hbase/$m -name "BUCK" | xargs -P8 yapf -i --style=google +done + +find third-party -name "BUCK" | xargs -P8 yapf -i --style=google http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/BUCK ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/BUCK b/hbase-native-client/connection/BUCK deleted file mode 100644 index a87d27a..0000000 --- a/hbase-native-client/connection/BUCK +++ /dev/null @@ -1,86 +0,0 @@ -## -# 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. - -# This is the library dealing with a single connection -# to a single server. -cxx_library( - name="connection", - exported_headers=[ - "client-dispatcher.h", - "client-handler.h", - "sasl-handler.h", - "connection-factory.h", - "connection-pool.h", - "connection-id.h", - "pipeline.h", - "request.h", - "rpc-connection.h", - "response.h", - "service.h", - "rpc-client.h", - "sasl-util.h", - "rpc-test-server.h", - "rpc-test-server-handler.h", - "rpc-fault-injector.h", - "rpc-fault-injector-inl.h", - ], - srcs=[ - "client-dispatcher.cc", - "client-handler.cc", - "connection-factory.cc", - "connection-pool.cc", - "pipeline.cc", - "request.cc", - "rpc-client.cc", - "sasl-handler.cc", - "sasl-util.cc", - "rpc-test-server.cc", - "rpc-test-server-handler.cc", - "rpc-fault-injector.cc", - ], - deps=[ - "//if:if", - "//utils:utils", - "//serde:serde", - "//security:security", - "//third-party:folly", - "//third-party:wangle", - "//exceptions:exceptions", - ], - compiler_flags=['-Weffc++'], - linker_flags=['-L/usr/local/lib', '-lsasl2', '-lkrb5'], - exported_linker_flags=['-L/usr/local/lib', '-lsasl2', '-lkrb5'], - visibility=[ - '//core/...', - ],) -cxx_test( - name="connection-pool-test", - srcs=[ - "connection-pool-test.cc", - ], - deps=[ - ":connection", - ],) -cxx_test( - name="rpc-test", - srcs=[ - "rpc-test.cc", - ], - deps=[ - ":connection", - ], - run_test_separately=True,) http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/client-dispatcher.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/client-dispatcher.cc b/hbase-native-client/connection/client-dispatcher.cc deleted file mode 100644 index fc8eb16..0000000 --- a/hbase-native-client/connection/client-dispatcher.cc +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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 "connection/client-dispatcher.h" - -#include <folly/ExceptionWrapper.h> -#include <folly/Format.h> -#include <folly/io/async/AsyncSocketException.h> -#include <utility> - -#include "connection/rpc-connection.h" -#include "exceptions/exception.h" - -using std::unique_ptr; - -namespace hbase { - -ClientDispatcher::ClientDispatcher(const std::string &server) - : current_call_id_(9), requests_(5000), server_(server), is_closed_(false) {} - -void ClientDispatcher::read(Context *ctx, unique_ptr<Response> in) { - VLOG(5) << "ClientDispatcher::read()"; - auto call_id = in->call_id(); - auto p = requests_.find_and_erase(call_id); - - VLOG(3) << folly::sformat("Read hbase::Response, call_id: {}, hasException: {}, what: {}", - in->call_id(), bool(in->exception()), in->exception().what()); - - if (in->exception()) { - p.setException(in->exception()); - } else { - p.setValue(std::move(in)); - } -} - -void ClientDispatcher::readException(Context *ctx, folly::exception_wrapper e) { - VLOG(5) << "ClientDispatcher::readException()"; - CloseAndCleanUpCalls(); -} - -void ClientDispatcher::readEOF(Context *ctx) { - VLOG(5) << "ClientDispatcher::readEOF()"; - CloseAndCleanUpCalls(); -} - -folly::Future<unique_ptr<Response>> ClientDispatcher::operator()(unique_ptr<Request> arg) { - VLOG(5) << "ClientDispatcher::operator()"; - std::lock_guard<std::recursive_mutex> lock(mutex_); - if (is_closed_) { - throw ConnectionException("Connection closed already"); - } - - auto call_id = current_call_id_++; - arg->set_call_id(call_id); - - // TODO: if the map is full (or we have more than hbase.client.perserver.requests.threshold) - // then throw ServerTooBusyException so that upper layers will retry. - auto &p = requests_[call_id]; - - auto f = p.getFuture(); - p.setInterruptHandler([call_id, this](const folly::exception_wrapper &e) { - LOG(ERROR) << "e = " << call_id; - this->requests_.erase(call_id); - // TODO: call Promise::SetException()? - }); - - try { - this->pipeline_->write(std::move(arg)); - } catch (const folly::AsyncSocketException &e) { - p.setException(folly::exception_wrapper{ConnectionException{folly::exception_wrapper{e}}}); - /* clear folly::Promise to avoid overflow. */ - requests_.erase(call_id); - } - - return f; -} - -void ClientDispatcher::CloseAndCleanUpCalls() { - VLOG(5) << "ClientDispatcher::CloseAndCleanUpCalls()"; - std::lock_guard<std::recursive_mutex> lock(mutex_); - if (is_closed_) { - return; - } - for (auto &pair : requests_) { - pair.second.setException(IOException{"Connection closed to server:" + server_}); - } - requests_.clear(); - is_closed_ = true; -} - -folly::Future<folly::Unit> ClientDispatcher::close() { - CloseAndCleanUpCalls(); - return ClientDispatcherBase::close(); -} - -folly::Future<folly::Unit> ClientDispatcher::close(Context *ctx) { - CloseAndCleanUpCalls(); - return ClientDispatcherBase::close(ctx); -} -} // namespace hbase http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/client-dispatcher.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/client-dispatcher.h b/hbase-native-client/connection/client-dispatcher.h deleted file mode 100644 index 7ef3759..0000000 --- a/hbase-native-client/connection/client-dispatcher.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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. - * - */ - -#pragma once - -#include <folly/Logging.h> -#include <wangle/service/ClientDispatcher.h> - -#include <atomic> -#include <map> -#include <memory> -#include <mutex> -#include <string> - -#include "connection/pipeline.h" -#include "connection/request.h" -#include "connection/response.h" -#include "utils/concurrent-map.h" - -namespace hbase { - -/** - * Dispatcher that assigns a call_id and then routes the response back to the - * future. - */ -class ClientDispatcher - : public wangle::ClientDispatcherBase<SerializePipeline, std::unique_ptr<Request>, - std::unique_ptr<Response>> { - public: - /** Create a new ClientDispatcher */ - explicit ClientDispatcher(const std::string &server); - /** Read a response off the pipeline. */ - void read(Context *ctx, std::unique_ptr<Response> in) override; - void readException(Context *ctx, folly::exception_wrapper e) override; - void readEOF(Context *ctx) override; - /** Take a request as a call and send it down the pipeline. */ - folly::Future<std::unique_ptr<Response>> operator()(std::unique_ptr<Request> arg) override; - /** Close the dispatcher and the associated pipeline. */ - folly::Future<folly::Unit> close(Context *ctx) override; - /** Close the dispatcher and the associated pipeline. */ - folly::Future<folly::Unit> close() override; - - private: - void CloseAndCleanUpCalls(); - - private: - std::recursive_mutex mutex_; - concurrent_map<uint32_t, folly::Promise<std::unique_ptr<Response>>> requests_; - // Start at some number way above what could - // be there for un-initialized call id counters. - // - // This makes it easier to make sure that the're are - // no access to un-initialized variables. - // - // uint32_t has a max of 4Billion so 10 more or less is - // not a big deal. - std::atomic<uint32_t> current_call_id_; - std::string server_; - bool is_closed_; -}; -} // namespace hbase http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/client-handler.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/client-handler.cc b/hbase-native-client/connection/client-handler.cc deleted file mode 100644 index 983a68c..0000000 --- a/hbase-native-client/connection/client-handler.cc +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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 "connection/client-handler.h" - -#include <folly/ExceptionWrapper.h> -#include <folly/Likely.h> -#include <folly/io/async/AsyncSocketException.h> -#include <glog/logging.h> -#include <string> - -#include "connection/request.h" -#include "connection/response.h" -#include "if/Client.pb.h" -#include "if/RPC.pb.h" - -using google::protobuf::Message; - -namespace hbase { - -ClientHandler::ClientHandler(std::string user_name, std::shared_ptr<Codec> codec, - std::shared_ptr<Configuration> conf, const std::string &server) - : user_name_(user_name), - serde_(codec), - conf_(conf), - server_(server), - once_flag_(std::make_unique<std::once_flag>()), - resp_msgs_( - std::make_unique<concurrent_map<uint32_t, std::shared_ptr<google::protobuf::Message>>>( - 5000)) {} - -void ClientHandler::read(Context *ctx, std::unique_ptr<folly::IOBuf> buf) { - if (LIKELY(buf != nullptr)) { - buf->coalesce(); - auto received = std::make_unique<Response>(); - pb::ResponseHeader header; - - int used_bytes = serde_.ParseDelimited(buf.get(), &header); - VLOG(3) << "Read RPC ResponseHeader size=" << used_bytes << " call_id=" << header.call_id() - << " has_exception=" << header.has_exception() << ", server: " << server_; - - auto resp_msg = resp_msgs_->find_and_erase(header.call_id()); - - // set the call_id. - // This will be used to by the dispatcher to match up - // the promise with the response. - received->set_call_id(header.call_id()); - - // If there was an exception then there's no - // data left on the wire. - if (header.has_exception() == false) { - buf->trimStart(used_bytes); - - int cell_block_length = 0; - used_bytes = serde_.ParseDelimited(buf.get(), resp_msg.get()); - if (header.has_cell_block_meta() && header.cell_block_meta().has_length()) { - cell_block_length = header.cell_block_meta().length(); - } - - VLOG(3) << "Read RPCResponse, buf length:" << buf->length() - << ", header PB length:" << used_bytes << ", cell_block length:" << cell_block_length - << ", server: " << server_; - - // Make sure that bytes were parsed. - CHECK((used_bytes + cell_block_length) == buf->length()); - - if (cell_block_length > 0) { - auto cell_scanner = serde_.CreateCellScanner(std::move(buf), used_bytes, cell_block_length); - received->set_cell_scanner(std::shared_ptr<CellScanner>{cell_scanner.release()}); - } - - received->set_resp_msg(resp_msg); - } else { - hbase::pb::ExceptionResponse exceptionResponse = header.exception(); - - std::string what; - std::string exception_class_name = exceptionResponse.has_exception_class_name() - ? exceptionResponse.exception_class_name() - : ""; - std::string stack_trace = - exceptionResponse.has_stack_trace() ? exceptionResponse.stack_trace() : ""; - what.append(stack_trace); - - auto remote_exception = std::make_unique<RemoteException>(what); - remote_exception->set_exception_class_name(exception_class_name) - ->set_stack_trace(stack_trace) - ->set_hostname(exceptionResponse.has_hostname() ? exceptionResponse.hostname() : "") - ->set_port(exceptionResponse.has_port() ? exceptionResponse.port() : 0); - if (exceptionResponse.has_do_not_retry()) { - remote_exception->set_do_not_retry(exceptionResponse.do_not_retry()); - } - - VLOG(3) << "Exception RPC ResponseHeader, call_id=" << header.call_id() - << " exception.what=" << remote_exception->what() - << ", do_not_retry=" << remote_exception->do_not_retry() << ", server: " << server_; - received->set_exception(folly::exception_wrapper{*remote_exception}); - } - ctx->fireRead(std::move(received)); - } -} - -folly::Future<folly::Unit> ClientHandler::write(Context *ctx, std::unique_ptr<Request> r) { - /* for RPC test, there's no need to send connection header */ - if (!conf_->GetBool(RpcSerde::HBASE_CLIENT_RPC_TEST_MODE, - RpcSerde::DEFAULT_HBASE_CLIENT_RPC_TEST_MODE)) { - // We need to send the header once. - // So use call_once to make sure that only one thread wins this. - std::call_once((*once_flag_), [ctx, this]() { - VLOG(3) << "Writing RPC Header to server: " << server_; - auto header = serde_.Header(user_name_); - ctx->fireWrite(std::move(header)); - }); - } - - VLOG(3) << "Writing RPC Request:" << r->DebugString() << ", server: " << server_; - - // Now store the call id to response. - resp_msgs_->insert(std::make_pair(r->call_id(), r->resp_msg())); - - try { - // Send the data down the pipeline. - return ctx->fireWrite(serde_.Request(r->call_id(), r->method(), r->req_msg().get())); - } catch (const folly::AsyncSocketException &e) { - /* clear protobuf::Message to avoid overflow. */ - resp_msgs_->erase(r->call_id()); - throw e; - } -} -} // namespace hbase http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/client-handler.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/client-handler.h b/hbase-native-client/connection/client-handler.h deleted file mode 100644 index b6f19a2..0000000 --- a/hbase-native-client/connection/client-handler.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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. - * - */ -#pragma once - -#include <wangle/channel/Handler.h> - -#include <atomic> -#include <memory> -#include <mutex> -#include <string> -#include <utility> - -#include "core/configuration.h" -#include "exceptions/exception.h" -#include "serde/codec.h" -#include "serde/rpc-serde.h" -#include "utils/concurrent-map.h" - -// Forward decs. -namespace hbase { -class Request; -class Response; -class HeaderInfo; -} -namespace google { -namespace protobuf { -class Message; -} -} - -namespace hbase { - -/** - * wangle::Handler implementation to convert hbase::Request to IOBuf and - * convert IOBuf to hbase::Response. - * - * This class deals with sending the connection header and preamble - * on first request. - */ -class ClientHandler - : public wangle::Handler<std::unique_ptr<folly::IOBuf>, std::unique_ptr<Response>, - std::unique_ptr<Request>, std::unique_ptr<folly::IOBuf>> { - public: - /** - * Create the handler - * @param user_name the user name of the user running this process. - */ - ClientHandler(std::string user_name, std::shared_ptr<Codec> codec, - std::shared_ptr<Configuration> conf, const std::string &server); - - /** - * Get bytes from the wire. - * This should be the full message as the length field decoder should be - * in the pipeline before this. - */ - void read(Context *ctx, std::unique_ptr<folly::IOBuf> msg) override; - - /** - * Write the data down the wire. - */ - folly::Future<folly::Unit> write(Context *ctx, std::unique_ptr<Request> r) override; - - private: - std::unique_ptr<std::once_flag> once_flag_; - std::string user_name_; - RpcSerde serde_; - std::string server_; // for logging - std::shared_ptr<Configuration> conf_; - - // in flight requests - std::unique_ptr<concurrent_map<uint32_t, std::shared_ptr<google::protobuf::Message>>> resp_msgs_; -}; -} // namespace hbase http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/connection-factory.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/connection-factory.cc b/hbase-native-client/connection/connection-factory.cc deleted file mode 100644 index 751073e..0000000 --- a/hbase-native-client/connection/connection-factory.cc +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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 <folly/Conv.h> -#include <glog/logging.h> -#include <wangle/channel/Handler.h> - -#include <chrono> - -#include <folly/ExceptionWrapper.h> -#include <folly/SocketAddress.h> -#include <folly/io/async/AsyncSocketException.h> - -#include "connection/client-dispatcher.h" -#include "connection/connection-factory.h" -#include "connection/pipeline.h" -#include "connection/sasl-handler.h" -#include "connection/service.h" -#include "exceptions/exception.h" - -using std::chrono::milliseconds; -using std::chrono::nanoseconds; - -namespace hbase { - -ConnectionFactory::ConnectionFactory(std::shared_ptr<wangle::IOThreadPoolExecutor> io_executor, - std::shared_ptr<wangle::CPUThreadPoolExecutor> cpu_executor, - std::shared_ptr<Codec> codec, - std::shared_ptr<Configuration> conf, - nanoseconds connect_timeout) - : connect_timeout_(connect_timeout), - io_executor_(io_executor), - cpu_executor_(cpu_executor), - conf_(conf), - pipeline_factory_(std::make_shared<RpcPipelineFactory>(codec, conf)) {} - -std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>> ConnectionFactory::MakeBootstrap() { - auto client = std::make_shared<wangle::ClientBootstrap<SerializePipeline>>(); - client->group(io_executor_); - client->pipelineFactory(pipeline_factory_); - - // TODO: Opened https://github.com/facebook/wangle/issues/85 in wangle so that we can set socket - // options like TCP_NODELAY, SO_KEEPALIVE, CONNECT_TIMEOUT_MILLIS, etc. - - return client; -} - -std::shared_ptr<HBaseService> ConnectionFactory::Connect( - std::shared_ptr<RpcConnection> rpc_connection, - std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>> client_bootstrap, - const std::string &hostname, uint16_t port) { - // connection should happen from an IO thread - try { - auto future = via(io_executor_.get()).then([=]() { - VLOG(1) << "Connecting to server: " << hostname << ":" << port; - return client_bootstrap->connect(folly::SocketAddress(hostname, port, true), - std::chrono::duration_cast<milliseconds>(connect_timeout_)); - }); - - // See about using shared promise for this. - auto pipeline = future.get(); - - VLOG(1) << "Connected to server: " << hostname << ":" << port; - auto dispatcher = - std::make_shared<ClientDispatcher>(hostname + ":" + folly::to<std::string>(port)); - dispatcher->setPipeline(pipeline); - return dispatcher; - } catch (const folly::AsyncSocketException &e) { - throw ConnectionException(folly::exception_wrapper{e}); - } -} -} // namespace hbase http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/connection-factory.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/connection-factory.h b/hbase-native-client/connection/connection-factory.h deleted file mode 100644 index c4e63c2..0000000 --- a/hbase-native-client/connection/connection-factory.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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. - * - */ -#pragma once - -#include <wangle/concurrent/CPUThreadPoolExecutor.h> -#include <wangle/concurrent/IOThreadPoolExecutor.h> -#include <wangle/service/Service.h> - -#include <chrono> -#include <memory> -#include <string> - -#include "connection/pipeline.h" -#include "connection/request.h" -#include "connection/response.h" -#include "connection/service.h" -#include "security/user.h" - -namespace hbase { - -class RpcConnection; - -/** - * Class to create a ClientBootstrap and turn it into a connected - * pipeline. - */ -class ConnectionFactory { - public: - /** - * Constructor. - * There should only be one ConnectionFactory per client. - */ - ConnectionFactory(std::shared_ptr<wangle::IOThreadPoolExecutor> io_executor, - std::shared_ptr<wangle::CPUThreadPoolExecutor> cpu_executor, - std::shared_ptr<Codec> codec, std::shared_ptr<Configuration> conf, - std::chrono::nanoseconds connect_timeout = std::chrono::nanoseconds(0)); - - /** Default Destructor */ - virtual ~ConnectionFactory() = default; - - /** - * Create a BootStrap from which a connection can be made. - */ - virtual std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>> MakeBootstrap(); - - /** - * Connect a ClientBootstrap to a server and return the pipeline. - * - * This is mostly visible so that mocks can override socket connections. - */ - virtual std::shared_ptr<HBaseService> Connect( - std::shared_ptr<RpcConnection> rpc_connection, - std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>> client_bootstrap, - const std::string &hostname, uint16_t port); - - std::shared_ptr<wangle::IOThreadPoolExecutor> io_executor() { return io_executor_; } - - std::shared_ptr<wangle::CPUThreadPoolExecutor> cpu_executor() { return cpu_executor_; } - - private: - std::chrono::nanoseconds connect_timeout_; - std::shared_ptr<Configuration> conf_; - std::shared_ptr<wangle::IOThreadPoolExecutor> io_executor_; - std::shared_ptr<wangle::CPUThreadPoolExecutor> cpu_executor_; - std::shared_ptr<RpcPipelineFactory> pipeline_factory_; -}; -} // namespace hbase http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/connection-id.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/connection-id.h b/hbase-native-client/connection/connection-id.h deleted file mode 100644 index 065b484..0000000 --- a/hbase-native-client/connection/connection-id.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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. - * - */ -#pragma once - -#include <boost/functional/hash.hpp> - -#include <memory> -#include <string> -#include <utility> - -#include "if/HBase.pb.h" -#include "security/user.h" - -namespace hbase { - -class ConnectionId { - public: - ConnectionId(const std::string &host, uint16_t port) - : ConnectionId(host, port, security::User::defaultUser(), "") {} - - ConnectionId(const std::string &host, uint16_t port, std::shared_ptr<security::User> user) - : ConnectionId(host, port, user, "") {} - - ConnectionId(const std::string &host, uint16_t port, std::shared_ptr<security::User> user, - const std::string &service_name) - : user_(user), service_name_(service_name), host_(host), port_(port) {} - - ConnectionId(const std::string &host, uint16_t port, const std::string &service_name) - : user_(security::User::defaultUser()), - service_name_(service_name), - host_(host), - port_(port) {} - - virtual ~ConnectionId() = default; - - std::shared_ptr<security::User> user() const { return user_; } - std::string service_name() const { return service_name_; } - std::string host() { return host_; } - uint16_t port() { return port_; } - - private: - std::shared_ptr<security::User> user_; - std::string service_name_; - std::string host_; - uint16_t port_; -}; - -/* Equals function for ConnectionId */ -struct ConnectionIdEquals { - /** equals */ - bool operator()(const std::shared_ptr<ConnectionId> &lhs, - const std::shared_ptr<ConnectionId> &rhs) const { - return userEquals(lhs->user(), rhs->user()) && lhs->host() == rhs->host() && - lhs->port() == rhs->port() && lhs->service_name() == rhs->service_name(); - } - - private: - bool userEquals(const std::shared_ptr<security::User> &lhs, - const std::shared_ptr<security::User> &rhs) const { - return lhs == nullptr ? rhs == nullptr - : (rhs == nullptr ? false : lhs->user_name() == rhs->user_name()); - } -}; - -/** Hash for ConnectionId. */ -struct ConnectionIdHash { - /** hash */ - std::size_t operator()(const std::shared_ptr<ConnectionId> &ci) const { - std::size_t h = 0; - boost::hash_combine(h, ci->user() == nullptr ? 0 : ci->user()->user_name()); - boost::hash_combine(h, ci->host()); - boost::hash_combine(h, ci->port()); - boost::hash_combine(h, ci->service_name()); - return h; - } -}; -} // namespace hbase http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/connection-pool-test.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/connection-pool-test.cc b/hbase-native-client/connection/connection-pool-test.cc deleted file mode 100644 index 0dc8e14..0000000 --- a/hbase-native-client/connection/connection-pool-test.cc +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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 <folly/Logging.h> -#include <gmock/gmock.h> - -#include "connection/connection-factory.h" -#include "connection/connection-id.h" -#include "connection/connection-pool.h" -#include "if/HBase.pb.h" -#include "serde/server-name.h" - -using hbase::pb::ServerName; -using ::testing::Return; -using ::testing::_; -using hbase::ConnectionFactory; -using hbase::ConnectionPool; -using hbase::ConnectionId; -using hbase::HBaseService; -using hbase::Request; -using hbase::Response; -using hbase::RpcConnection; -using hbase::SerializePipeline; - -class MockConnectionFactory : public ConnectionFactory { - public: - MockConnectionFactory() : ConnectionFactory(nullptr, nullptr, nullptr, nullptr) {} - MOCK_METHOD0(MakeBootstrap, std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>>()); - MOCK_METHOD4(Connect, std::shared_ptr<HBaseService>( - std::shared_ptr<RpcConnection> rpc_connection, - std::shared_ptr<wangle::ClientBootstrap<SerializePipeline>>, - const std::string &hostname, uint16_t port)); -}; - -class MockBootstrap : public wangle::ClientBootstrap<SerializePipeline> {}; - -class MockService : public HBaseService { - public: - folly::Future<std::unique_ptr<Response>> operator()(std::unique_ptr<Request> req) override { - return folly::makeFuture<std::unique_ptr<Response>>( - std::make_unique<Response>(do_operation(req.get()))); - } - MOCK_METHOD1(do_operation, Response(Request *)); -}; - -TEST(TestConnectionPool, TestOnlyCreateOnce) { - auto hostname = std::string{"hostname"}; - auto mock_boot = std::make_shared<MockBootstrap>(); - auto mock_service = std::make_shared<MockService>(); - auto mock_cf = std::make_shared<MockConnectionFactory>(); - 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_service), do_operation(_)).Times(1).WillRepeatedly(Return(Response{})); - ConnectionPool cp{mock_cf}; - - auto remote_id = std::make_shared<ConnectionId>(hostname, port); - auto result = cp.GetConnection(remote_id); - ASSERT_TRUE(result != nullptr); - result = cp.GetConnection(remote_id); - result->SendRequest(nullptr); -} - -TEST(TestConnectionPool, TestOnlyCreateMultipleDispose) { - std::string hostname_one{"hostname"}; - std::string hostname_two{"hostname_two"}; - uint32_t port{999}; - - auto mock_boot = std::make_shared<MockBootstrap>(); - auto mock_service = std::make_shared<MockService>(); - auto mock_cf = std::make_shared<MockConnectionFactory>(); - - 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_service), do_operation(_)).Times(4).WillRepeatedly(Return(Response{})); - ConnectionPool cp{mock_cf}; - - { - auto remote_id = std::make_shared<ConnectionId>(hostname_one, port); - auto result_one = cp.GetConnection(remote_id); - result_one->SendRequest(nullptr); - auto remote_id2 = std::make_shared<ConnectionId>(hostname_two, port); - auto result_two = cp.GetConnection(remote_id2); - result_two->SendRequest(nullptr); - } - auto remote_id = std::make_shared<ConnectionId>(hostname_one, port); - auto result_one = cp.GetConnection(remote_id); - result_one->SendRequest(nullptr); - auto remote_id2 = std::make_shared<ConnectionId>(hostname_two, port); - auto result_two = cp.GetConnection(remote_id2); - result_two->SendRequest(nullptr); -} - -TEST(TestConnectionPool, TestCreateOneConnectionForOneService) { - std::string hostname{"hostname"}; - uint32_t port{999}; - std::string service1{"service1"}; - std::string service2{"service2"}; - - auto mock_boot = std::make_shared<MockBootstrap>(); - auto mock_service = std::make_shared<MockService>(); - auto mock_cf = std::make_shared<MockConnectionFactory>(); - - 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_service), do_operation(_)).Times(4).WillRepeatedly(Return(Response{})); - ConnectionPool cp{mock_cf}; - - { - auto remote_id = std::make_shared<ConnectionId>(hostname, port, service1); - auto result_one = cp.GetConnection(remote_id); - result_one->SendRequest(nullptr); - auto remote_id2 = std::make_shared<ConnectionId>(hostname, port, service2); - auto result_two = cp.GetConnection(remote_id2); - result_two->SendRequest(nullptr); - } - auto remote_id = std::make_shared<ConnectionId>(hostname, port, service1); - auto result_one = cp.GetConnection(remote_id); - result_one->SendRequest(nullptr); - auto remote_id2 = std::make_shared<ConnectionId>(hostname, port, service2); - auto result_two = cp.GetConnection(remote_id2); - result_two->SendRequest(nullptr); -} http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/connection-pool.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/connection-pool.cc b/hbase-native-client/connection/connection-pool.cc deleted file mode 100644 index e1f6358..0000000 --- a/hbase-native-client/connection/connection-pool.cc +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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 "connection/connection-pool.h" - -#include <folly/Conv.h> -#include <folly/Logging.h> -#include <wangle/service/Service.h> - -#include <memory> -#include <string> -#include <utility> - -using std::chrono::nanoseconds; - -namespace hbase { - -ConnectionPool::ConnectionPool(std::shared_ptr<wangle::IOThreadPoolExecutor> io_executor, - std::shared_ptr<wangle::CPUThreadPoolExecutor> cpu_executor, - std::shared_ptr<Codec> codec, std::shared_ptr<Configuration> conf, - nanoseconds connect_timeout) - : cf_(std::make_shared<ConnectionFactory>(io_executor, cpu_executor, codec, conf, - connect_timeout)), - connections_(), - map_mutex_(), - conf_(conf) {} -ConnectionPool::ConnectionPool(std::shared_ptr<ConnectionFactory> cf) - : cf_(cf), connections_(), map_mutex_() {} - -ConnectionPool::~ConnectionPool() {} - -std::shared_ptr<RpcConnection> ConnectionPool::GetConnection( - std::shared_ptr<ConnectionId> remote_id) { - // Try and get th cached connection. - auto found_ptr = GetCachedConnection(remote_id); - - // If there's no connection then create it. - if (found_ptr == nullptr) { - found_ptr = GetNewConnection(remote_id); - } - return found_ptr; -} - -std::shared_ptr<RpcConnection> ConnectionPool::GetCachedConnection( - std::shared_ptr<ConnectionId> remote_id) { - folly::SharedMutexWritePriority::ReadHolder holder(map_mutex_); - auto found = connections_.find(remote_id); - if (found == connections_.end()) { - return nullptr; - } - return found->second; -} - -std::shared_ptr<RpcConnection> ConnectionPool::GetNewConnection( - std::shared_ptr<ConnectionId> remote_id) { - // Grab the upgrade lock. While we are double checking other readers can - // continue on - folly::SharedMutexWritePriority::UpgradeHolder u_holder{map_mutex_}; - - // Now check if someone else created the connection before we got the lock - // This is safe since we hold the upgrade lock. - // upgrade lock is more power than the reader lock. - auto found = connections_.find(remote_id); - if (found != connections_.end() && found->second != nullptr) { - return found->second; - } else { - // Yeah it looks a lot like there's no connection - folly::SharedMutexWritePriority::WriteHolder w_holder{std::move(u_holder)}; - - // Make double sure there are not stale connections hanging around. - connections_.erase(remote_id); - - /* create new connection */ - auto connection = std::make_shared<RpcConnection>(remote_id, cf_); - - connections_.insert(std::make_pair(remote_id, connection)); - - return connection; - } -} - -void ConnectionPool::Close(std::shared_ptr<ConnectionId> remote_id) { - folly::SharedMutexWritePriority::WriteHolder holder{map_mutex_}; - DLOG(INFO) << "Closing RPC Connection to host:" << remote_id->host() - << ", port:" << folly::to<std::string>(remote_id->port()); - - auto found = connections_.find(remote_id); - if (found == connections_.end() || found->second == nullptr) { - return; - } - found->second->Close(); - connections_.erase(found); -} - -void ConnectionPool::Close() { - folly::SharedMutexWritePriority::WriteHolder holder{map_mutex_}; - for (auto &item : connections_) { - auto &con = item.second; - con->Close(); - } - connections_.clear(); -} -} // namespace hbase http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/connection-pool.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/connection-pool.h b/hbase-native-client/connection/connection-pool.h deleted file mode 100644 index 9af1e7f..0000000 --- a/hbase-native-client/connection/connection-pool.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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. - * - */ -#pragma once - -#include <folly/SharedMutex.h> -#include <boost/functional/hash.hpp> -#include <chrono> -#include <memory> -#include <mutex> -#include <unordered_map> - -#include "connection/connection-factory.h" -#include "connection/connection-id.h" -#include "connection/rpc-connection.h" -#include "connection/service.h" -#include "if/HBase.pb.h" - -namespace hbase { - -/** - * @brief Connection pooling for HBase rpc connection. - * - * This is a thread safe connection pool. It allows getting - * a shared rpc connection to HBase servers by connection id. - */ -class ConnectionPool { - public: - /** Create connection pool wit default connection factory */ - ConnectionPool(std::shared_ptr<wangle::IOThreadPoolExecutor> io_executor, - std::shared_ptr<wangle::CPUThreadPoolExecutor> cpu_executor, - std::shared_ptr<Codec> codec, std::shared_ptr<Configuration> conf, - std::chrono::nanoseconds connect_timeout = std::chrono::nanoseconds(0)); - - /** - * Constructor that allows specifiying the connetion factory. - * This is useful for testing. - */ - explicit ConnectionPool(std::shared_ptr<ConnectionFactory> cf); - - /** - * Destructor. - * All connections will be close. - * All connections will be released - */ - ~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<RpcConnection> GetConnection(std::shared_ptr<ConnectionId> remote_id); - - /** - * Close/remove a connection. - */ - void Close(std::shared_ptr<ConnectionId> remote_id); - - /** - * Close the Connection Pool - */ - void Close(); - - private: - std::shared_ptr<RpcConnection> GetCachedConnection(std::shared_ptr<ConnectionId> remote_id); - std::shared_ptr<RpcConnection> GetNewConnection(std::shared_ptr<ConnectionId> remote_id); - std::unordered_map<std::shared_ptr<ConnectionId>, std::shared_ptr<RpcConnection>, - ConnectionIdHash, ConnectionIdEquals> - connections_; - folly::SharedMutexWritePriority map_mutex_; - std::shared_ptr<ConnectionFactory> cf_; - std::shared_ptr<Configuration> conf_; -}; - -} // namespace hbase http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/pipeline.cc ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/pipeline.cc b/hbase-native-client/connection/pipeline.cc deleted file mode 100644 index 9c790b6..0000000 --- a/hbase-native-client/connection/pipeline.cc +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 "connection/pipeline.h" - -#include <folly/Logging.h> -#include <wangle/channel/AsyncSocketHandler.h> -#include <wangle/channel/EventBaseHandler.h> -#include <wangle/channel/OutputBufferingHandler.h> -#include <wangle/codec/LengthFieldBasedFrameDecoder.h> - -#include "connection/client-handler.h" -#include "connection/sasl-handler.h" - -namespace hbase { - -RpcPipelineFactory::RpcPipelineFactory(std::shared_ptr<Codec> codec, - std::shared_ptr<Configuration> conf) - : user_util_(), codec_(codec), conf_(conf) {} -SerializePipeline::Ptr RpcPipelineFactory::newPipeline( - std::shared_ptr<folly::AsyncTransportWrapper> sock) { - folly::SocketAddress addr; // for logging - sock->getPeerAddress(&addr); - - auto pipeline = SerializePipeline::create(); - pipeline->addBack(wangle::AsyncSocketHandler{sock}); - pipeline->addBack(wangle::EventBaseHandler{}); - bool secure = false; - /* for RPC test, there's no need to setup Sasl */ - if (!conf_->GetBool(RpcSerde::HBASE_CLIENT_RPC_TEST_MODE, - RpcSerde::DEFAULT_HBASE_CLIENT_RPC_TEST_MODE)) { - secure = security::User::IsSecurityEnabled(*conf_); - pipeline->addBack(SaslHandler{user_util_.user_name(secure), conf_}); - } - pipeline->addBack(wangle::LengthFieldBasedFrameDecoder{}); - pipeline->addBack(ClientHandler{user_util_.user_name(secure), codec_, conf_, addr.describe()}); - pipeline->finalize(); - return pipeline; -} -} // namespace hbase http://git-wip-us.apache.org/repos/asf/hbase/blob/128fc306/hbase-native-client/connection/pipeline.h ---------------------------------------------------------------------- diff --git a/hbase-native-client/connection/pipeline.h b/hbase-native-client/connection/pipeline.h deleted file mode 100644 index add7fe5..0000000 --- a/hbase-native-client/connection/pipeline.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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. - * - */ -#pragma once - -#include <folly/io/IOBufQueue.h> -#include <wangle/service/Service.h> - -#include <memory> - -#include "connection/request.h" -#include "connection/response.h" -#include "core/configuration.h" -#include "serde/codec.h" -#include "utils/user-util.h" - -namespace hbase { - -/** Pipeline to turn IOBuf into requests */ -using SerializePipeline = wangle::Pipeline<folly::IOBufQueue &, std::unique_ptr<Request>>; - -/** - * Factory to create new pipelines for HBase RPC's. - */ -class RpcPipelineFactory : public wangle::PipelineFactory<SerializePipeline> { - public: - /** - * Constructor. This will create user util. - */ - explicit RpcPipelineFactory(std::shared_ptr<Codec> codec, std::shared_ptr<Configuration> conf); - - /** - * Create a new pipeline. - * The pipeline will be: - * - * - Async Socke Handler - * - Event Base Handler - * - Length Field Based Frame Decoder - * - Client Handler - */ - SerializePipeline::Ptr newPipeline(std::shared_ptr<folly::AsyncTransportWrapper> sock) override; - - private: - UserUtil user_util_; - std::shared_ptr<Codec> codec_; - std::shared_ptr<Configuration> conf_; -}; -} // namespace hbase