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

CFAPI: Handle cancelation of hydration requests #3010

Merged
merged 1 commit into from
Mar 18, 2021

Conversation

FlexW
Copy link

@FlexW FlexW commented Mar 16, 2021

Signed-off-by: Felix Weilbach felix.weilbach@nextcloud.com

Copy link
Member

@er-vin er-vin left a comment

Choose a reason for hiding this comment

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

Looks nice overall. Any way to make an automated test to simulate cancellation?

src/libsync/vfs/cfapi/cfapiwrapper.cpp Outdated Show resolved Hide resolved
src/libsync/vfs/cfapi/hydrationjob.cpp Outdated Show resolved Hide resolved
src/libsync/vfs/cfapi/vfs_cfapi.cpp Outdated Show resolved Hide resolved
src/libsync/vfs/cfapi/vfs_cfapi.cpp Outdated Show resolved Hide resolved

// Remove placeholder file because there might be already pumped
// some data into it
QFile::remove(folderPath + folderRelativePath);
Copy link
Member

Choose a reason for hiding this comment

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

This is surprising. Isn't the data committed on disk by cfapi only when the request completes? I'd be surprised they'd go through all the trouble to prevent the sync engine from writing directly in the file itself to then leave inconsistent data behind...

Copy link
Author

Choose a reason for hiding this comment

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

If you cancel a request and then look at the file size you can see that the file size is not zero bytes anymore. But I'm not sure if there is really already data pumped in. I thought it would be cleaner to just remove it and replace it with an empty placeholder.

Copy link
Member

Choose a reason for hiding this comment

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

If you cancel a request and then look at the file size you can see that the file size is not zero bytes anymore.

I think you're slightly confused here. It's already non-zero before the request. The placeholders expose the size of the file as reported by the server metadata even if the file isn't hydrated.

Please test again without that removal and db + placeholder mangling. I mean when the client has to do this kind of things sure, but if that's not required then it's better not too, it's always a risk of ending up with inconsistent data if something fails during the course of such actions.

Copy link
Contributor

Choose a reason for hiding this comment

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

@er-vin Actually, I have noticed what @FlexW mentioned. There is this field called "Size on disk" on every file in Windows if you open its properties dialog. It is growing as the hydration is progressing and its size is zero at the beginning. If one cancels the download in the Progress dialog, the "Size on disk" does not drop to zero.

Copy link
Member

Choose a reason for hiding this comment

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

Ah nice that there's a different field in the properties dialog. Didn't spot it the last time.

So yeah I guess it needs that kill + recreate placeholder then... shame on that API, just makes no sense to not let us write to the files directly then. :-)

@FlexW
Copy link
Author

FlexW commented Mar 16, 2021

Looks nice overall. Any way to make an automated test to simulate cancellation?

Thanks. I tried to find a way but did not have success so far. I'm open to ideas :)

@FlexW FlexW force-pushed the feature/cfapi-handle-cancelation branch from 699081b to 2366153 Compare March 17, 2021 09:22
@FlexW FlexW force-pushed the feature/cfapi-handle-cancelation branch from faf11fd to 2a75a81 Compare March 18, 2021 08:48
@FlexW FlexW force-pushed the feature/cfapi-handle-cancelation branch from 2a75a81 to 444b8b3 Compare March 18, 2021 10:19
@FlexW
Copy link
Author

FlexW commented Mar 18, 2021

/rebase

Signed-off-by: Felix Weilbach <felix.weilbach@nextcloud.com>
@github-actions github-actions bot force-pushed the feature/cfapi-handle-cancelation branch from 444b8b3 to 9bf5b5c Compare March 18, 2021 10:43
@nextcloud-desktop-bot
Copy link

AppImage file: Nextcloud-PR-3010-9bf5b5c7ba3ec59f86a7f51bca55bbd63d9f402a-x86_64.AppImage

To test this change/fix you can simply download above AppImage file and test it.

Please make sure to quit your existing Nextcloud app and backup your data.

@FlexW FlexW merged commit 278a6fd into master Mar 18, 2021
@FlexW FlexW deleted the feature/cfapi-handle-cancelation branch March 18, 2021 12:27
// Create a new placeholder file
SyncJournalFileRecord record;
params().journal->getFileRecord(folderRelativePath, &record);
const auto item = SyncFileItem::fromSyncJournalFileRecord(record);
Copy link
Member

Choose a reason for hiding this comment

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

If that's really required (see other comment above), then at least it should check the db read actually succeeded and the record is valid, otherwise you could have a malformed item here.

Copy link
Author

Choose a reason for hiding this comment

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

@er-vin Okay but how should we recover if the item is malformed? Or should we check if the record is valid before the removal of the placeholder and if the record is invalid then just return early from the function?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, probably best to do the db operation first. And leave the file in place if that fails. At least that'd avoid unwanted deletion on next sync.

Copy link
Author

Choose a reason for hiding this comment

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

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.

4 participants