wwbmmm commented on code in PR #2273:
URL: https://github.com/apache/brpc/pull/2273#discussion_r1226052504


##########
src/brpc/retry_backoff_policy.h:
##########
@@ -0,0 +1,74 @@
+// 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.
+
+
+#ifndef BRPC_RETRY_BACKOFF_POLICY_H
+#define BRPC_RETRY_BACKOFF_POLICY_H
+
+#include "butil/fast_rand.h"
+
+namespace brpc {
+
+// Inherit this class to customize the RPC retry backoff policy.
+class RetryBackoffPolicy {
+public:
+    virtual ~RetryBackoffPolicy() = default;
+
+    // Returns the backoff time in milliseconds before every retry.
+    virtual int32_t get_backoff_time_ms(int nretry, int64_t 
reaming_rpc_time_ms) const = 0;

Review Comment:
   大写开关的驼峰命名



##########
src/brpc/retry_backoff_policy.h:
##########
@@ -0,0 +1,74 @@
+// 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.
+
+
+#ifndef BRPC_RETRY_BACKOFF_POLICY_H
+#define BRPC_RETRY_BACKOFF_POLICY_H
+
+#include "butil/fast_rand.h"
+
+namespace brpc {
+
+// Inherit this class to customize the RPC retry backoff policy.
+class RetryBackoffPolicy {
+public:
+    virtual ~RetryBackoffPolicy() = default;
+
+    // Returns the backoff time in milliseconds before every retry.
+    virtual int32_t get_backoff_time_ms(int nretry, int64_t 
reaming_rpc_time_ms) const = 0;
+    //                                                                         
    ^
+    //                                                              don't 
forget the const modifier
+};
+
+class FixedRetryBackoffPolicy : public RetryBackoffPolicy {
+public:
+    FixedRetryBackoffPolicy(int32_t backoff_time_ms, int32_t 
no_backoff_remaining_rpc_time_ms)
+        : _backoff_time_ms(backoff_time_ms)
+        , _no_backoff_remaining_rpc_time_ms(no_backoff_remaining_rpc_time_ms) 
{}
+
+    int32_t get_backoff_time_ms(int nretry, int64_t reaming_rpc_time_ms) const 
override;

Review Comment:
   reaming -> remaining?



##########
src/brpc/controller.cpp:
##########
@@ -1013,6 +1020,18 @@ void Controller::IssueRPC(int64_t start_realtime_us) {
         return;
     }
 
+    bthread::TaskGroup* g = bthread::tls_task_group;
+    // Only bthread task can retry with backoff.
+    if (g && !g->is_current_pthread_task() && _retry_backoff && 
_current_call.nretry > 0) {
+        int64_t remaining_rpc_time_us = _deadline_us - 
butil::gettimeofday_us();

Review Comment:
   backup request也会走到这里,为backup request进行backoff是不是不合适?
   把这段逻辑移到OnVersionedRPCReturned里可能更合适



##########
test/brpc_channel_unittest.cpp:
##########
@@ -1810,6 +1811,73 @@ class ChannelTest : public ::testing::Test{
         StopAndJoin();
     }
 
+    struct TetsRetryBackoff {

Review Comment:
   Tets -> Test?



##########
src/brpc/controller.cpp:
##########
@@ -1013,6 +1020,18 @@ void Controller::IssueRPC(int64_t start_realtime_us) {
         return;
     }
 
+    bthread::TaskGroup* g = bthread::tls_task_group;
+    // Only bthread task can retry with backoff.

Review Comment:
   如果检测到是pthread task,报个错?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to