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

check if current user still holds the write lock when upload changes #819

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

jiaruiz717
Copy link
Contributor

iTwin/itwinjs-backlog#1170

There is a possible scenario that two users try to upload local changes to the same cloud container:

  1. User1 grabs the write lock and sit there for a very long time. User1 does not release the write lock even after it has expired
  2. User2 grabs the write lock after User1's write lock expires, and upload something to the cloud container
  3. User1 then tries to upload changes, we should disable User1 from uploading his changes because the write lock has expired

However, if there are no other users grab the write lock after User1, we allow User1 to upload changes(and refresh the write lock) even if the write lock has expired.

Tests are added in itwinjs-core
itwinjs-core: iTwin/itwinjs-core#7000

@khanaffan
Copy link
Contributor

If CloudSqlite throws an exception and the operation fails (unable to upload changes), it is likely that iModelDb will execute abandonChanges(). However, the CloudSqlite local cache may still contain changed blocks.

If an exception is thrown and the application exits, then restarts with the same iModel, the local cache might still have dirty pages.

To abandon changes in the local cache when abandoning changes on the iModel, you would need to ensure that the local cache is also cleared or synchronized to reflect the abandonment of changes.

Is there a method on ClouldSqlite that i can call in SchemaSync to discard any changes after sync operation but before upload?

@jiaruiz717
Copy link
Contributor Author

If CloudSqlite throws an exception and the operation fails (unable to upload changes), it is likely that iModelDb will execute abandonChanges(). However, the CloudSqlite local cache may still contain changed blocks.

If an exception is thrown and the application exits, then restarts with the same iModel, the local cache might still have dirty pages.

To abandon changes in the local cache when abandoning changes on the iModel, you would need to ensure that the local cache is also cleared or synchronized to reflect the abandonment of changes.

Is there a method on ClouldSqlite that i can call in SchemaSync to discard any changes after sync operation but before upload?

Not sure if I understand this correctly, but there is another abandonChanges() in CloudContainer(JsCloudSqlite.cpp/IModelJsNative/JsCloudContainer/AbandonChanges()) which is used to abandon/revert all changes in the local cache. In SchemaSync we have nativeDb object so we can all nativeDb.cloudContainer?.abandonChanges() to discard all changes in local cache.

@khanaffan
Copy link
Contributor

Thanks for pointing me to that method. I will update schema import code to call it when schema import fails.

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.

3 participants