orbitdb / field-manual

The Offical User's Guide to OrbitDB
208 stars 43 forks source link

FAQ: Database replication is not working #64

Open haadcode opened 5 years ago

haadcode commented 5 years ago

This is probably the most frequently asked question and it needs canonical answer as well as detailed "troubleshooting" steps as the reasons seem to vary. However, there are two major ones that I seen constantly popping up: using orbitdb in app code (eg. calling load() or listening for replicated event) and IPFS problems (which can be due to many reasons).

Leaving this open to collect all the relevant issues and answers as I'm pretty sure this has been answered in the past by multiple people to multiple questions around the topic.

Would love comments and contributions to link to the issues or a PR to gather the information to a document directly.

Possibly related issues orbitdb/orbit-db#264, orbitdb/orbit-db#349, orbitdb/orbit-db#315 and orbitdb/orbit-db#442. There may be others.

christroutner commented 5 years ago

I ran into this same problem, trying to get a DB to replicate across IPFS nodes running the node.js implementation of js-IPFS and Orbit-DB. I was trying to get a locally running node.js app (Node A) to talk with another peer running in a Virtual Machine (VM) (Node B). They did not appear to be communicating and the DB was not getting replicated. Here is how I went about debugging.

I started by adding an console.log alert whenever the replication event fired:

db.events.on('replicated', () => {
  console.log(`replication event fired`)
})

Running the software again, I could see that the replication event never fired.

I set up a third node on a Digital Ocean Droplet cloud server (Node C). After running the software I could also see the replication event was not firing. I copied the multiaddr for Node C and added it to the first two nodes with this code:

ipfs.bootstrap.add('/ip4/162.243.158.213/tcp/4002/ipfs/QmQLcCWKuxsMkRt5DJkcSw361iNLikjEBMEj6ovR6pwAb5')

I was able to ensure that Node C was in the bootstrap list with this command:

const list = await ipfs.bootstrap.list()
console.log(`list: ${util.inspect(list)}`)

As soon as I added the bootstrap.add code to the other two nodes and started them all, the replication event immediately started firing and the DB started getting replicated across the nodes.

christroutner commented 5 years ago

To help myself understand the intricacies of libp2p and orbit-db replication, I created this db-replication directory in a repo I created for such things: https://github.com/christroutner/orbit-tests/tree/master/db-replication

Check out the README in that folder. It describes the various network configurations. The code is currently replicating the example database across firewalled peers.

aphelionz commented 5 years ago

@christroutner That is super cool - do you want to add that repo to the https://github.com/orbitdb/awesome-orbitdb repo in the Tools section?

aphelionz commented 4 years ago

Moving this to the Field Manual Repo

melroy89 commented 4 years ago

Can the answer be updated already on https://github.com/orbitdb/orbit-db/blob/master/FAQ.md#database-replication-is-not-working-why?