From 3b8ce04f55a36f58c2cff80a19149d769acbdba3 Mon Sep 17 00:00:00 2001 From: Xiaobing Zhou Date: Wed, 18 Jan 2017 13:43:38 -0800 Subject: [PATCH] HBASE-17465. [C++] implement request retry mechanism over RPC --- hbase-native-client/core/async-connection.cc | 25 +++++ hbase-native-client/core/async-connection.h | 35 +++++++ .../core/async-rpc-retrying-caller-factory.cc | 12 +++ .../core/async-rpc-retrying-caller-factory.h | 101 +++++++++++++++++++++ .../core/async-rpc-retrying-caller.cc | 12 +++ .../core/async-rpc-retrying-caller.h | 35 +++++++ hbase-native-client/core/hbase-rpc-controller.cc | 24 +++++ hbase-native-client/core/hbase-rpc-controller.h | 31 +++++++ hbase-native-client/core/hregion-location.cc | 24 +++++ hbase-native-client/core/hregion-location.h | 31 +++++++ 10 files changed, 330 insertions(+) create mode 100644 hbase-native-client/core/async-connection.cc create mode 100644 hbase-native-client/core/async-connection.h create mode 100644 hbase-native-client/core/async-rpc-retrying-caller-factory.cc create mode 100644 hbase-native-client/core/async-rpc-retrying-caller-factory.h create mode 100644 hbase-native-client/core/async-rpc-retrying-caller.cc create mode 100644 hbase-native-client/core/async-rpc-retrying-caller.h create mode 100644 hbase-native-client/core/hbase-rpc-controller.cc create mode 100644 hbase-native-client/core/hbase-rpc-controller.h create mode 100644 hbase-native-client/core/hregion-location.cc create mode 100644 hbase-native-client/core/hregion-location.h diff --git a/hbase-native-client/core/async-connection.cc b/hbase-native-client/core/async-connection.cc new file mode 100644 index 0000000..085e81f --- /dev/null +++ b/hbase-native-client/core/async-connection.cc @@ -0,0 +1,25 @@ +/* + * 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 "async-connection.h" + +namespace hbase { + +} // namespace hbase + diff --git a/hbase-native-client/core/async-connection.h b/hbase-native-client/core/async-connection.h new file mode 100644 index 0000000..1f7d3c6 --- /dev/null +++ b/hbase-native-client/core/async-connection.h @@ -0,0 +1,35 @@ +/* + * 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 + +namespace hbase { + +class AsyncConnection { +public: + AsyncConnection() {} + virtual ~AsyncConnection() = default; +}; + +class AsyncConnectionImpl { +public: + AsyncConnectionImpl() {} + virtual ~AsyncConnectionImpl() = default; +}; +} // namespace hbase diff --git a/hbase-native-client/core/async-rpc-retrying-caller-factory.cc b/hbase-native-client/core/async-rpc-retrying-caller-factory.cc new file mode 100644 index 0000000..0446616 --- /dev/null +++ b/hbase-native-client/core/async-rpc-retrying-caller-factory.cc @@ -0,0 +1,12 @@ +/* + * AsyncRpcRetryingCallerFactory.cpp + * + * Created on: Jan 16, 2017 + * Author: xzhou + */ + +#include "async-rpc-retrying-caller-factory.h" + +namespace hbase { + +} // namespace hbase diff --git a/hbase-native-client/core/async-rpc-retrying-caller-factory.h b/hbase-native-client/core/async-rpc-retrying-caller-factory.h new file mode 100644 index 0000000..62364ec --- /dev/null +++ b/hbase-native-client/core/async-rpc-retrying-caller-factory.h @@ -0,0 +1,101 @@ +/* + * 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 +#include +#include "if/HBase.pb.h" +#include "async-connection.h" + +using hbase::pb::TableName; + +namespace hbase { + +template +class SingleRequestCallerBuilder : public std::enable_shared_from_this< + SingleRequestCallerBuilder> { + +public: + SingleRequestCallerBuilder() : + table_name_(nullptr), + rpc_timeout_nanos_(0), + operation_timeout_nanos_(0), + row_(nullptr) {} + + virtual ~SingleRequestCallerBuilder() = default; + + typedef std::shared_ptr> SharedThisType; + + SharedThisType table( + std::shared_ptr table_name) { + table_name_ = table_name; + return shared_this(); + } + + SharedThisType rpcTimeout( + long rpc_timeout_nanos) { + rpc_timeout_nanos_ = rpc_timeout_nanos; + return shared_this(); + } + + SharedThisType operationTimeout( + long operation_timeout_nanos) { + operation_timeout_nanos_ = operation_timeout_nanos; + return shared_this(); + } + + SharedThisType row(std::unique_ptr row) { + row_ = std::move(row); + return shared_this(); + } + +private: + SharedThisType shared_this() { + return std::enable_shared_from_this< + SingleRequestCallerBuilder>::shared_from_this(); + } + +private: + std::shared_ptr table_name_; + long rpc_timeout_nanos_; + long operation_timeout_nanos_; + std::unique_ptr row_; + }; + +class AsyncRpcRetryingCallerFactory { +public: + AsyncRpcRetryingCallerFactory( + std::shared_ptr conn, + std::shared_ptr retry_timer) : + conn_(conn), retry_timer_(retry_timer) { + } + + virtual ~AsyncRpcRetryingCallerFactory() = default; + + template + std::shared_ptr> Single() { + return std::make_shared>(); + } + +private: + std::shared_ptr conn_; + std::shared_ptr retry_timer_; +}; + +} // namespace hbase diff --git a/hbase-native-client/core/async-rpc-retrying-caller.cc b/hbase-native-client/core/async-rpc-retrying-caller.cc new file mode 100644 index 0000000..83a1baa --- /dev/null +++ b/hbase-native-client/core/async-rpc-retrying-caller.cc @@ -0,0 +1,12 @@ +/* + * async-single-request-rpc-retrying-caller.cpp + * + * Created on: Jan 18, 2017 + * Author: xzhou + */ + +#include "async-rpc-retrying-caller.h" + +namespace hbase { + +} /* namespace hbase */ diff --git a/hbase-native-client/core/async-rpc-retrying-caller.h b/hbase-native-client/core/async-rpc-retrying-caller.h new file mode 100644 index 0000000..43ec373 --- /dev/null +++ b/hbase-native-client/core/async-rpc-retrying-caller.h @@ -0,0 +1,35 @@ +/* + * 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 "hbase-rpc-controller.h" +#include "hregion-location.h" +#include + +namespace hbase { + +class AsyncSingleRequestRpcRetryingCaller { +public: + AsyncSingleRequestRpcRetryingCaller() {} + virtual ~AsyncSingleRequestRpcRetryingCaller() = default; + +}; + +} /* namespace hbase */ + diff --git a/hbase-native-client/core/hbase-rpc-controller.cc b/hbase-native-client/core/hbase-rpc-controller.cc new file mode 100644 index 0000000..f5b5963 --- /dev/null +++ b/hbase-native-client/core/hbase-rpc-controller.cc @@ -0,0 +1,24 @@ +/* + * 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 "hbase-rpc-controller.h" + +namespace hbase { + +} /* namespace hbase */ diff --git a/hbase-native-client/core/hbase-rpc-controller.h b/hbase-native-client/core/hbase-rpc-controller.h new file mode 100644 index 0000000..af7c86b --- /dev/null +++ b/hbase-native-client/core/hbase-rpc-controller.h @@ -0,0 +1,31 @@ +/* + * 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 + +namespace hbase { + +class HBaseRpcController { +public: + HBaseRpcController() {} + virtual ~HBaseRpcController() = default; +}; + +} /* namespace hbase */ + + diff --git a/hbase-native-client/core/hregion-location.cc b/hbase-native-client/core/hregion-location.cc new file mode 100644 index 0000000..97202a4 --- /dev/null +++ b/hbase-native-client/core/hregion-location.cc @@ -0,0 +1,24 @@ +/* + * 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 "hregion-location.h" + +namespace hbase { + +} /* namespace hbase */ diff --git a/hbase-native-client/core/hregion-location.h b/hbase-native-client/core/hregion-location.h new file mode 100644 index 0000000..eb7d13f --- /dev/null +++ b/hbase-native-client/core/hregion-location.h @@ -0,0 +1,31 @@ +/* + * 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 + +namespace hbase { + +class HRegionLocation { +public: + HRegionLocation(); + virtual ~HRegionLocation(); +}; + +} /* namespace hbase */ + + -- 2.10.1 (Apple Git-78)