You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/12/26 13:46:42 UTC

[GitHub] [dubbo-rust] yang20150702 commented on a diff in pull request #92: Support timeout after waiting RPC response for a maximum time. #47

yang20150702 commented on code in PR #92:
URL: https://github.com/apache/dubbo-rust/pull/92#discussion_r1057245299


##########
dubbo/src/filter/timeout.rs:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+use std::time::{SystemTime, UNIX_EPOCH};
+
+use crate::{
+    codegen::Request,
+    context::{Context, RpcContext},
+    status::{Code, Status},
+};
+
+use super::Filter;
+
+#[derive(Clone)]
+pub struct TimeoutFilter {}
+
+/// timeout count
+/// 1. ContextFilter 初始化 timeout 时间,初始化后将 tri-timeout-deadline-in-nanos 放入 context 中
+/// 2. TimeoutFilter read context tri-timeout-deadline-in-nanos
+/// 3. 响应时计算 tri-timeout-deadline-in-nanos - current_nanos <= 0
+///
+impl Filter for TimeoutFilter {
+    fn call(&mut self, req: Request<()>) -> Result<Request<()>, Status> {
+        if let Some(attachments) = RpcContext::get_attachments() {
+            let current_nanos = SystemTime::now()
+                .duration_since(UNIX_EPOCH)
+                .unwrap()
+                .as_nanos();
+
+            let attachments = attachments.lock().unwrap();
+            let tri_timeout_deadline_in_nanos =
+                attachments.get("tri-timeout-deadline-in-nanos").unwrap();

Review Comment:
   We can reuse this key by define const



##########
dubbo/src/filter/context.rs:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+use std::time::{SystemTime, UNIX_EPOCH};
+
+use serde_json::Value;
+
+use crate::{
+    codegen::Request,
+    context::{Context, RpcContext},
+    status::Status,
+};
+
+use super::Filter;
+
+#[derive(Clone)]
+pub struct ContextFilter {}

Review Comment:
   Suggest rename ContextFilter to TimeoutContextFilter.



-- 
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: notifications-unsubscribe@dubbo.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org