This repository was archived by the owner on May 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
fix: prevent session to be actively closed when it gets response from server #85
Open
neverchanje
wants to merge
19
commits into
XiaoMi:master
Choose a base branch
from
neverchanje:fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2560184
fix: prevent session to be actively closed when it gets response from…
31ea60d
fix
d1c66d6
fix
15cb780
Merge branch 'thrift-0.11.0-inlined' into fix
2f536a0
Merge branch 'thrift-0.11.0-inlined' into fix
761a877
Merge branch 'thrift-0.11.0-inlined' into fix
f0e9dde
Update .travis.yml
43e992d
fix
dd4cc80
Merge branch 'master' of github.com:XiaoMi/pegasus-java-client into fix
neverchanje 3516b06
fix
neverchanje 9107419
Merge branch 'master' of github.com:XiaoMi/pegasus-java-client into fix
neverchanje 6832bc2
fix
neverchanje dfe1a6c
fix
neverchanje e0201cd
add license
d13bc51
fix
neverchanje 40c659d
Merge branch 'fix' of github.com:neverchanje/pegasus-java-client into…
neverchanje eac3eb1
Merge branch 'master' of github.com:XiaoMi/pegasus-java-client into fix
neverchanje 4fd1d30
format
neverchanje a213db4
Merge branch 'master' into fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/com/xiaomi/infra/pegasus/rpc/async/SessionFailureDetector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package com.xiaomi.infra.pegasus.rpc.async; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| /** | ||
| * SessionFailureDetector detects whether the session is half-closed by the remote host, in which | ||
| * case we need to actively close the session and reconnect. | ||
| */ | ||
| public class SessionFailureDetector { | ||
|
|
||
| // Timestamp of the first timed out rpc. | ||
| private AtomicLong firstRecentTimedOutMs; | ||
|
|
||
| // Session is marked failure if all the RPCs across | ||
| // `FAILURE_DETECT_WINDOW_MS` are timed out. | ||
| public static final long FAILURE_DETECT_WINDOW_MS = 10 * 1000; // 10s | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe 10s is too short? consider set it to 30s or 60s?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I keep it as it was in this refactoring. I will consider a larger window if it makes sense. |
||
|
|
||
| public SessionFailureDetector() { | ||
| this.firstRecentTimedOutMs = new AtomicLong(0); | ||
| } | ||
|
|
||
| /** @return true if session is confirmed to be failed. */ | ||
| public boolean markTimeout() { | ||
| // The error must be ERR_TIMEOUT or ERR_SESSION_RESET | ||
| long firstTs = firstRecentTimedOutMs.get(); | ||
| if (firstTs == 0) { | ||
| // it is the first timeout in the window. | ||
| firstRecentTimedOutMs.set(System.currentTimeMillis()); | ||
| } else if (System.currentTimeMillis() - firstTs >= FAILURE_DETECT_WINDOW_MS) { | ||
| // ensure that session will be closed only once. | ||
| return firstRecentTimedOutMs.compareAndSet(firstTs, 0); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** Mark this session to be healthy. */ | ||
| public void markOK() { | ||
| firstRecentTimedOutMs.set(0); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.