-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Go binding: add StopNetwork() #11393
base: main
Are you sure you want to change the base?
Conversation
Result of foundationdb-pr-clang-ide on Linux CentOS 7
|
Result of foundationdb-pr-cluster-tests on Linux CentOS 7
|
Result of foundationdb-pr-clang on Linux CentOS 7
|
Result of foundationdb-pr on Linux CentOS 7
|
0f04b8d
to
3565780
Compare
bindings/go/src/fdb/fdb.go
Outdated
func startNetwork() error { | ||
// ensureNetworkIsStarted ensures that the API version is set and then starts the internal network event loop, if not already done. | ||
// The provided function is guaranteed to be run while network thread is running. | ||
func ensureNetworkIsStarted(f func()) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func ensureNetworkIsStarted(f func()) error { | |
func executeWithRunningNetworkThread(f func()) error { |
I don't want to be nitpicking about the method name but executeWithRunningNetworkThread
might be a better name for what this method is doing now.
Should we add a check in this method if the network was stopped? And if so return an according error? Right now we would still execute f()
which would probably result in a panic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure; made some changes, please review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I could not use a FoundationDB error code for these, as they do not exist.
bindings/go/src/fdb/fdb.go
Outdated
// This function does nothing if the network has not yet started. | ||
// Once network is stopped it cannot be started again. | ||
// See also: https://github.com/apple/foundationdb/issues/3015 | ||
func StopNetwork() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func StopNetwork() { | |
func StopNetwork() error { |
We probably should return an error if the network was started and was already stopped? I'm not sure what will happen, but a user-friendly error like "network was already stopped" might be better than having the code panic or return nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but what about the case of network not yet started? Should it return an error or do nothing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it return an error also in such case.
4561886
to
970c54c
Compare
bindings/go/src/fdb/errors.go
Outdated
errNetworkNotSetup = Error{2008} | ||
errNetworkNotSetup = Error{2008} | ||
errNetworkAlreadySetup = Error{2009} | ||
errNetworkCannotBeRestarted = Error{2025} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are really not used in this PR; I could remove them, I thought to add them and leave them here for completeness.
…d is running All API calls which create a database are guaranteed to happen while the network thread is running; there is no performance penalty for calls happening after network thread has already been started. Notable change: if the call to run network thread fails, a panic will be generated instead of a logged error.
Add a method which allows to a safe explicit stop of the network thread. This method waits for the network thread to exit before returning to caller.
Specify which functions are safe to be called from multiple goroutines
970c54c
to
a89df68
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment, otherwise LGTM 👍
if networkStopped { | ||
networkMutex.RUnlock() | ||
|
||
return ErrNetworkIsStopped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if networkStopped { | |
networkMutex.RUnlock() | |
return ErrNetworkIsStopped | |
if networkStopped { | |
return ErrNetworkIsStopped |
In this case we have a write mutex and the defer
will already unlock it. Calling it again will result in a runtime error.
This PR contains the following notable changes:
fdb_run_network()
fails, instead of logging an error onlyStartNetwork()
, already deprecated, effectively becomes a no-opStopNetwork()
method which allows to follow spec for issues like Consider making shutting down without joining the network thread safe in the client #2978 and Not all binding implementations follow the requirements of fdb_stop_network #3015Any advice for test coverage?
Code-Reviewer Section
The general pull request guidelines can be found here.
Please check each of the following things and check all boxes before accepting a PR.
For Release-Branches
If this PR is made against a release-branch, please also check the following:
release-branch
ormain
if this is the youngest branch)