Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[close #372] add circuit breaker and smart rawkv client - #358

Merged
zz-jason merged 18 commits into
tikv:masterfrom
marsishandsome:feature/support-CircuitBreaker
Dec 9, 2021
Merged

[close #372] add circuit breaker and smart rawkv client#358
zz-jason merged 18 commits into
tikv:masterfrom
marsishandsome:feature/support-CircuitBreaker

Conversation

@marsishandsome

@marsishandsome marsishandsome commented Dec 2, 2021

Copy link
Copy Markdown
Collaborator

Signed-off-by: marsishandsome [email protected]

add Circuit Breaker

@marsishandsome
marsishandsome force-pushed the feature/support-CircuitBreaker branch 27 times, most recently from 38145a4 to 3b62a5c Compare December 7, 2021 07:20
@marsishandsome

Copy link
Copy Markdown
Collaborator Author

/run-all-tests

this.listeners = new ArrayList<>();
this.currentMetrics = new AtomicReference<>(new SingleWindowMetrics());

scheduler =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this background task be managed by the circuit breaker instead of the circuit metrics?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a subtask belonging to the circuit breaker. For the metrics, it only needs to record the traffic statistics.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, we should not start this background thread when the circuit breaker is configured to be disabled.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 5fcf19b

Comment thread src/main/java/org/tikv/service/failsafe/CircuitBreakerMetricsImpl.java Outdated
Comment thread src/main/java/org/tikv/service/failsafe/HealthCounts.java
Comment thread src/main/java/org/tikv/service/failsafe/HealthCounts.java
Comment thread src/main/java/org/tikv/service/failsafe/CircuitBreakerImpl.java
Signed-off-by: marsishandsome <[email protected]>
@marsishandsome
marsishandsome force-pushed the feature/support-CircuitBreaker branch from f42b506 to 929f3db Compare December 8, 2021 09:30
Signed-off-by: marsishandsome <[email protected]>
@marsishandsome
marsishandsome force-pushed the feature/support-CircuitBreaker branch from 2eea8ad to 9932dab Compare December 8, 2021 09:48
Signed-off-by: marsishandsome <[email protected]>
Signed-off-by: marsishandsome <[email protected]>
Signed-off-by: marsishandsome <[email protected]>
this.listeners = new ArrayList<>();
this.currentMetrics = new AtomicReference<>(new SingleWindowMetrics());

scheduler =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a subtask belonging to the circuit breaker. For the metrics, it only needs to record the traffic statistics.

Comment thread src/main/java/org/tikv/raw/SmartRawKVClient.java
Comment thread src/main/java/org/tikv/raw/SmartRawKVClient.java
Comment thread src/main/java/org/tikv/service/failsafe/CircuitBreakerImpl.java
Comment thread src/main/java/org/tikv/service/failsafe/CircuitBreakerImpl.java
Comment thread src/main/java/org/tikv/service/failsafe/CircuitBreakerImpl.java
Comment on lines +43 to +46
private final AtomicLong circuitOpened = new AtomicLong(-1);
private final AtomicReference<Status> status = new AtomicReference<>(Status.CLOSED);
private final AtomicLong attemptCount = new AtomicLong(0);
private final AtomicLong attemptSuccessCount = new AtomicLong(0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. do we really need to set these variables as atomic variables? I can only see they are accessed within the current TiSession.

  2. we add the 'final' keyword to these fields but their values are changed during the execution time, seems a little counterintuitive.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two-time windows and their corresponding traffic stats:

  1. the first time window is to record normal traffic stats when the circuit breaker is closed or disabled in the background and triggers circuit breaker, which is limited to TiKV_CIRCUIT_BREAK_AVAILABILITY_WINDOW_IN_SECONDS and is called windowOfClosed.
  2. the second time window to record the attempt traffic stats when the circuit breaker is half-opened, which is called windowOfHalfOpened.

these two windows can be posited like this: windowOfClosed -> (circuit breaker opened) -> (after sleep, circuit breaker half-opened) -> windowOfHalfOpened

So can we:

  1. Define two traffic metrics for these two time windows like the following and remove the atomic variables for attempts:
private final CircuitBreakerMetrics metricsOfClosed;
private final CircuitBreakerMetrics metricsOfHalfOpened
  1. Make CircuitBreakerImpl be the owner of these two windows, don't start the background task to collect metricsOfClosed when the circuit breaker is disabled.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need to set these variables as atomic variables?

yes, in order to make CircuitBreakerImpl thread-safe.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we add the 'final' keyword to these fields but their values are changed during the execution time, seems a little counterintuitive.

yes, we should add final and the object reference does not change. The object content does change.

Comment thread src/main/java/org/tikv/service/failsafe/CircuitBreakerImpl.java
Comment thread src/main/java/org/tikv/service/failsafe/CircuitBreakerImpl.java
this.listeners = new ArrayList<>();
this.currentMetrics = new AtomicReference<>(new SingleWindowMetrics());

scheduler =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, we should not start this background thread when the circuit breaker is configured to be disabled.

@birdstorm birdstorm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zz-jason zz-jason left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zz-jason zz-jason changed the title add Circuit Breaker [close #372] add circuit breaker and smart rawkv client Dec 9, 2021
@zz-jason
zz-jason merged commit 48504bc into tikv:master Dec 9, 2021
ti-srebot pushed a commit to ti-srebot/client-java that referenced this pull request Dec 9, 2021
@ti-srebot

Copy link
Copy Markdown
Collaborator

cherry pick to release-3.1 in PR #373

marsishandsome added a commit to ti-srebot/client-java that referenced this pull request Dec 9, 2021
marsishandsome added a commit to ti-srebot/client-java that referenced this pull request Dec 9, 2021
Signed-off-by: ti-srebot <[email protected]>
Signed-off-by: marsishandsome <[email protected]>
marsishandsome added a commit to ti-srebot/client-java that referenced this pull request Dec 9, 2021
Signed-off-by: ti-srebot <[email protected]>
Signed-off-by: marsishandsome <[email protected]>
marsishandsome added a commit to ti-srebot/client-java that referenced this pull request Dec 9, 2021
Signed-off-by: ti-srebot <[email protected]>
Signed-off-by: marsishandsome <[email protected]>
marsishandsome added a commit to ti-srebot/client-java that referenced this pull request Dec 9, 2021
Signed-off-by: ti-srebot <[email protected]>
Signed-off-by: marsishandsome <[email protected]>
marsishandsome added a commit that referenced this pull request Dec 9, 2021
Signed-off-by: ti-srebot <[email protected]>
Signed-off-by: marsishandsome <[email protected]>

Co-authored-by: Liangliang Gu <[email protected]>
ankita25 pushed a commit to ankita25/client-java that referenced this pull request Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants