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

Multiple collections share sockets and peers when replicationWebrtc is used for synchronization #5926

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

croatialu
Copy link
Contributor

This PR contains:

  • A NEW FEATURE

Describe the problem you have without this PR

#5925

@croatialu
Copy link
Contributor Author

You can experience the difference between before and after modification at this link

https://stackblitz.com/~/github.com/croatialu/rxdb-replication-webrtc

@croatialu
Copy link
Contributor Author

Solution: Use closure to save data such as peers and sockets, and then each replicationWebrtc will try its best to reuse existing peers and sockets

How to use:

  const creator = getConnectionHandlerSimplePeer({})
  //                        ^ create a creator
  Object.keys(database.collections).map(async (key) => {
    return replicateWebRTC({
      collection:
        database.collections[key as keyof typeof database.collections],
      connectionHandlerCreator: creator,
      //                           ^ use the creator
      topic: dbName,
      pull: {},
      push: {},
    })
  })

@pubkey
Copy link
Owner

pubkey commented Apr 24, 2024

Hi @croatialu
Code changes look ok but this breaks the CI, please check.
Also we need at least one test to check the correctness of the new behavior.

@croatialu
Copy link
Contributor Author

Hi @croatialu Code changes look ok but this breaks the CI, please check. Also we need at least one test to check the correctness of the new behavior.

Okay, I'll take care of it right away. Thanks for the reminder!

@croatialu
Copy link
Contributor Author

const c1 = await humansCollection.create(1, 'aaa');
const c2 = await humansCollection.create(1, 'bbb');

I found that this piece of code for the unit test uses data synchronization between collections of different names in the same database. My idea is to synchronize collections of the same name from different databases.

My solution:

  1. When the collection of the database is changed, I will add a collectionName of the changed data to distinguish when sending data to other ends
  2. When the other end receives the data, according to the collectionName, the data is applied only when the collectionName is the same

The problem that the solution wants to solve is that the same collection data is synchronized on different ends.

So in an existing unit test, two different collectionnames cannot synchronize data.

Without modifying the unit tests, it didn't occur to me that different Collection synchronization schemes locally could also support the same Collection synchronization scheme between different ends

To pass the unit test, it will involve modifying the existing unit test method (changing to a different database with the same collectionName), which is likely to cause break change.

Do you have a better idea about that. @pubkey

translate by youdao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants