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

Add support for uploading and downloading changes with a timeout #6073

Merged
merged 9 commits into from
Nov 3, 2018

Conversation

cmelchior
Copy link
Contributor

@cmelchior cmelchior commented Jul 20, 2018

Closes #6247

This PR adds two convenience methods overrides for SyncSession.downloadAllServerChanges() and SyncSession.uploadAllLocalChanges() so they will now terminate if a timeout is hit. This will make it a lot easier to implement sync logic that is guaranteed to proceed after a given period without having to resort to external synchronization

This PR also add support for SyncConfiguration.waitForInitialRemoteData(timeout, unit) as it uses the above helper methods.

// session, including trying to stop it.
// In Java we cannot lock on the Session object either since it will prevent any attempt at modifying the
// lifecycle while it is in a waiting state. Thus we use a specialised mutex.
synchronized (waitForChangesMutex) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the lock is at the Java level only, then I question the usefulness of these overloads, since the m_state_mutex will still be acquired from the call to the OS's session->wait_for_download_completion, by returning you give the user the false impression that the underlying operation has been cancelled/timed out which is clearly not the case. Imagine this use case

SyncSession sync;
sync.downloadAllServerChanges(1, TimeUnit.MINUTES)
// do some commits 
sync.uploadAllServerChanges(1, TimeUnit.MINUTES);
// by returning here you have no guarantee that the actcual upload was triggered (at OS level), since we might still be holding the lock at the C++ level, from the downloadAll call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are using the asynchronous methods in the C++ layer, so no locks are actually being held. We are just using the Java lock to wait for the callback to happen. The reason for this that is that it is otherwise impossible to interrupt the Java thread at all, which would be highly undesirable.

IMO the semantics we have is that if downloadAllServerChanges completes, then changes have been downloaded. If it fails or times out, the behavior is undefined, i.e. it doesn't mean that downloading is canceled, it just means it didn't complete in time. I think that is acceptable. Behaving otherwise indicate a level of control over the syncing process that we don't offer (as everything happens more or less automatically).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the JavaDoc to indicate that downloading/uploading might still happen.

@cmelchior
Copy link
Contributor Author

Updated this PR as we had new use cases appear for it. It has been updated to support timeouts for downloading initial data and is ready for review.

@cmelchior cmelchior requested a review from kneth October 30, 2018 13:41
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
bgRealm.createObject(AllTypes.class);
}
})
.waitForInitialRemoteData(1, TimeUnit.MILLISECONDS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

NANOSECONDS? to be completely sure 🤓

@cmelchior cmelchior merged commit d8f6513 into master Nov 3, 2018
@cmelchior cmelchior deleted the cm/upload-download-with-timeout branch November 3, 2018 21:03
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants