Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dynamically setting multiple failpoints #38

Merged
merged 5 commits into from
Nov 25, 2022

Conversation

ahrtr
Copy link
Member

@ahrtr ahrtr commented Nov 22, 2022

Users can dynamically setting multiple failpoints using endpoint /failpoints, see example below,

$ curl http://127.0.0.1:22381/failpoints -X PUT -d'failpoint1=return("hello");failpoint2=sleep(10)'

Please review this PR commit by commit.

@spzala @serathius @ramil600

@ahrtr
Copy link
Member Author

ahrtr commented Nov 22, 2022

cc @ptabor as well

@ahrtr
Copy link
Member Author

ahrtr commented Nov 22, 2022

Related to #38

It isn't safe to lock each failpoint. The server might panic before
sending response back to client. For example, when a user set a
terms for failpoint A, but the server might be panicking due to
failpoint B. So it isn't safe to lock each single failpoint once
a time.

Instead, we should lock the global mutex. When each failpoint is
triggered, it just needs to acquire the read lock. But when a client
set terms for failpoints, they need to acquire the write lock, and
release the lock after the server(runtime) sends response back to
the client.

Signed-off-by: Benjamin Wang <wachao@vmware.com>
When the server(runtime) processes a http request, it acquires the
global write lock. This prevents all failpoints from being triggered.
It ensures the server(runtime) doesn't panic due to any failpoints
during processing the HTTP request.

It may be inefficient, but correctness is more important than
efficiency. Usually users will not enable too many failpoints at a
time, so it (the efficiency) isn't a problem.

Example:
endpoint: /failpoints
body: failpoint1=return("hello");failpoint2=sleep(10)

Signed-off-by: Benjamin Wang <wachao@vmware.com>
Signed-off-by: Benjamin Wang <wachao@vmware.com>
runtime/http.go Outdated Show resolved Hide resolved
runtime/runtime_test.go Outdated Show resolved Hide resolved
Signed-off-by: Benjamin Wang <wachao@vmware.com>
@ahrtr
Copy link
Member Author

ahrtr commented Nov 25, 2022

Thanks @serathius . Resolved all your comments. PTAL.

Comment on lines +54 to +57
if len(fps) == 0 {
return fpMap, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Note: Don't think this is needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we remove this, When users pass an empty string, then it will return error "bad failpoint xxx".

If we don't check the fps, then users are supposed to always pass a non-empty string. It seems like not a big deal, so let's keep it as it's for now.

runtime/http.go Outdated Show resolved Hide resolved
runtime/runtime.go Outdated Show resolved Hide resolved
Signed-off-by: Benjamin Wang <wachao@vmware.com>
@ahrtr ahrtr force-pushed the dynamical_multiple_failpoints_20221122 branch from 1998403 to d16d16d Compare November 25, 2022 11:32
@ahrtr ahrtr merged commit c1c2074 into etcd-io:master Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants