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 multi process support #1091

Closed
bmunkholm opened this issue May 6, 2015 · 22 comments
Closed

Add multi process support #1091

bmunkholm opened this issue May 6, 2015 · 22 comments
Assignees

Comments

@bmunkholm
Copy link
Contributor

Currently Realm for Java only support multi threading but not multi process.

@cmelchior
Copy link
Contributor

Relevant Realm-Cocoa issue is here: realm/realm-swift#824

Main issues:

  • Make sure that schema validation/initialisation is happening inside a write transaction to prevent other processes from doing the same, ie. grab write transaction before querying on schema.
  • Interprocess notifications. What is required to make this work on Java?

@cmelchior
Copy link
Contributor

See realm/realm-swift#2877

We might want to consider waiting to implement this until we have ObjectStore support.

@bmunkholm bmunkholm added In Progress and removed P1 labels Jan 26, 2016
@cmelchior cmelchior added this to the 1.0.0-rc1 milestone Feb 10, 2016
@cmelchior cmelchior removed this from the 1.0.0-rc1 milestone Mar 31, 2016
@simc
Copy link

simc commented May 6, 2016

@cmelchior Any update on this? On iOS it is already working...

@beeender
Copy link
Contributor

@leisim We made a PR some months ago #1300
It is not merged since it would have more fundamental changes and more testing.

Can you please share your use case with us? It would be helpful for us to build more test cases. Thanks!!

@gnumilanix
Copy link

@leisim If you are considering this because you want to use SyncAdapter. I originally starred this issue because of it but, I instead changed my implementation with GCMNetworkManager (Uses JobScheduler for newer API level). It requires less boilerplate compared with SyncAdapter. Hope that helps you.

@simc
Copy link

simc commented May 15, 2016

@beeender I created multiple apps for my company which extend each other, but they can be installed in various combinations. (Every employee has different apps)
But they all rely on the same data and it would be really convenient if they could just use the same database...

Thanks for your hard work btw ;)

@kabbi
Copy link

kabbi commented May 31, 2016

@beeender I am using this with react-native. My project needs background android service, that runs some js and captures some data into realm. And there is also an activity with react-native ui, that should be able to display results from realm. I run the service and activity in different processes, as I've had some problems creating two react-native contexts in the same process.

@beeender
Copy link
Contributor

beeender commented Jun 1, 2016

@kabbi So you are using the Realm React Native as well?

@kabbi
Copy link

kabbi commented Jun 1, 2016

@beeender Yes. Forgot to mention this.

@beeender
Copy link
Contributor

beeender commented Jun 1, 2016

@alazier This would be an interesting and quite useful use case. User can use our notification system work across native android and react native.

@ghost
Copy link

ghost commented Sep 1, 2016

@beeender is there still progress on this feature?

I also would like to use the same realm files from a service.

@beeender
Copy link
Contributor

beeender commented Sep 1, 2016

@rimeissner After #3370 merged, our master branch actually supports inter-processes notifications. You can try it with the snapshot release.
There are some corner cases:

  1. The Realm.deleteRealm() doesn't check if the Realm is opened in another process right now.
  2. Migrations happens in another process might not be handled well.
    So you may have to take care of those if you are going to use it in multi-processes.

So before we solve above issues, there are risks to use it in multi processes.

Also

  1. master branch should support notification between realm-java/realm-dotnet/realm-reactvie , but we need more tests on them.
  2. encrypted Realm is still NOT supported in multi-processes.

@mariusboepple
Copy link

Is there any progress on this? We're using a remote service, too.

@beeender
Copy link
Contributor

beeender commented May 2, 2017

@mariusboepple Our current release is actually supporting notifications through multi-processes, but there are some limitations to use realm-java in multi-processes applications:

  • Encryption is not supported for multi-processes.
  • Realm.deleteRealm() is not multi-processes safe.
  • Migrations are not handled well. So you need to avoid migrating happens while there is Realm instance opened in the other process.

@cmelchior
Copy link
Contributor

If you have two two processes running and you can guarantee that the parent process has an active Realm realm instance (since that would run all required migrations), then Realm should be process safe right now, but as @beeender mentioned there are also other edges cases. This is the primary reason we don't claim to be interprocess safe just yet.

@Zhuinden
Copy link
Contributor

Zhuinden commented May 2, 2017

@cmelchior would object store schema integration fix cross-process migration?

@cmelchior
Copy link
Contributor

It would probably get us close enough that we choose to go the last mile. Encrypted Realms and using Realm.deleteRealm() will not be supported in the first iteration though.

@jpmcosta
Copy link

jpmcosta commented Jun 7, 2017

@beeender as you said:

Migrations are not handled well. So you need to avoid migrating happens while there is Realm instance opened in the other process.

I'm making use of a FileLock before getting instances of Realm to avoid having multiple Realminstances opened across processes while a RealmMigration is running.

However, I noticed that the RealmMigration always runs in the main application process, even if the Realm instance being created is from a different process. Is this something I should be worried about, or I'll be fine as long as I don't have multiple instances opened while migrating?

Thanks in advance!

@Zhuinden
Copy link
Contributor

Zhuinden commented Jun 7, 2017

This is definitely something I would worry about because I feel like that might be related to what would explain the IncompatibleLockFile exceptions?

Then again, soon the object store will handle table creation and all this will be solved.

@jpmcosta
Copy link

jpmcosta commented Jun 7, 2017

@Zhuinden I'm locking on a file other than the Realm database file. Do you think I could still have issues?

@beeender
Copy link
Contributor

beeender commented Jun 8, 2017

@jpmcosta

However, I noticed that the RealmMigration always runs in the main application process, even if the Realm instance being created is from a different process.

The migration will happen when the first process create the Realm instance. The migration itself is actually protected by our write locks among processes.

The risk is if your two processes have different schemas, that would be problematic.

@beeender
Copy link
Contributor

We do support officially support multi-processes since 4.2.0
https://realm.io/docs/java/latest/#multiprocess

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants