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

Move addNetworkThreadCompletionHook to IClientApi. #340

Conversation

ajbeamon
Copy link
Contributor

@ajbeamon ajbeamon commented May 8, 2018

No description provided.

Copy link
Contributor

@alecgrieser alecgrieser left a comment

Choose a reason for hiding this comment

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

IIRC, there was a reason that this needed to be done that related to loading different versions of lifdb_c, but I don't recall off the top of my head what the reason was.

for( auto it : externalClients ) {
MutexHolder holder(lock);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this go outside of the loop to avoid creating a mutex holder in each iteration? I suppose if we expect the mode number of external clients to be zero and the next most common number to be one, then the answer is "no", it should stay in the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those in theory should be the most common cases, but I'm not opposed to moving it out, either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is no longer relevant with my most recent change.

@@ -355,6 +355,11 @@ ThreadFuture<Reference<ICluster>> DLApi::createCluster(const char *clusterFilePa
});
}

void DLApi::addNetworkThreadCompletionHook(void (*hook)(void*), void *hook_parameter) {
// All completion hooks are handled on the local client
throw unsupported_operation();
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that this is the weirdness that caused us to put addNetworkThreadCompletionHook in MultiVersionClientApi but not IClientApi in the first place. I think there was also some concern that it wouldn't work with older clients. It looks like this doesn't have the second issue, so I guess that's fine. I'm not sure how I feel about the first, but maybe it's the least evil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally, I think we'd just call straight through to the external library to handle completion hook, but as you say they may not support it.

However, it might be the case that we don't run the network on clients that don't support the specified API version, and this function shouldn't be called prior to whatever API version it was introduced in. So maybe we can actually get away with implementing it that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The above doesn't work because this function can be called even if using older API versions. I instead decided to change the implementation so that DLApi was responsible for managing callbacks at the external level.


auto hookPair = std::pair<void (*)(void*), void*>(hook, hook_parameter);

MutexHolder holder(lock); // We could use the network thread to protect this action, but then we can't guarantee upon return that the hook is set.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I totally understand this comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unless it's just saying that this won't necessarily happen on the network thread.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Running it on the network thread would allow us to skip the lock (and it's how we serialize most things in ThreadSafe), but it seemed more sensible to me that the hook be definitely set when this function returned. Running it on the network thread would instead have it be done at some point in the future.

Copy link
Contributor

@alecgrieser alecgrieser left a comment

Choose a reason for hiding this comment

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

I also noticed that the hook_parameter parameter was changed to hookParameter. Sneaky.

@@ -42,7 +42,8 @@ int g_api_version = 0;
#define CLUSTER(c) ((ICluster*)c)
#define TXN(t) ((ITransaction*)t)

#define API (MultiVersionApi::api)
#define API ((IClientApi*)MultiVersionApi::api)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I guess I should have noted this earlier, but it might be helpful if there were a comment here explaining why we are casting down (up?) to an IClientApi here. Also, was the extra whitespace intentional?

Copy link
Contributor

@alecgrieser alecgrieser left a comment

Choose a reason for hiding this comment

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

🌶

@alecgrieser alecgrieser merged commit b7f0e35 into apple:release-5.2 May 9, 2018
@ajbeamon ajbeamon deleted the move-thread-shutdown-hook-to-iclientapi branch November 27, 2018 17:57
sfc-gh-tclinkenbeard pushed a commit to sfc-gh-tclinkenbeard/foundationdb that referenced this pull request Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants