field-manual icon indicating copy to clipboard operation
field-manual copied to clipboard

FAQ: Database replication is not working

Open haadcode opened this issue 5 years ago • 5 comments

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.

haadcode avatar Nov 20 '18 12:11 haadcode

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 avatar Nov 23 '18 16:11 christroutner

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.

christroutner avatar Dec 01 '18 17:12 christroutner

@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 avatar Apr 16 '19 20:04 aphelionz

Moving this to the Field Manual Repo

aphelionz avatar Sep 27 '19 16:09 aphelionz

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

melroy89 avatar Feb 29 '20 17:02 melroy89