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

Persistency not working or db not connecting/replicating #315

Closed
eusthace opened this issue Jan 28, 2018 · 6 comments · Fixed by #316
Closed

Persistency not working or db not connecting/replicating #315

eusthace opened this issue Jan 28, 2018 · 6 comments · Fixed by #316
Labels

Comments

@eusthace
Copy link

eusthace commented Jan 28, 2018

Hi Guys,

I've been trying to use orbit-db without success (angular 5 project), not sure why, but persistency is not working and db is not triggering replicateX events.

Here is my code:

import * as IPFS from 'ipfs';
import * as OrbitDB from 'orbit-db';
...

const ipfsOptions = {
start: true,
repo: './test',
EXPERIMENTAL: {
pubsub: true
},
config: {
Addresses: {
  Swarm: [
    '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
  ]
},
}
};
...
this.ipfs = new IPFS(ipfsOptions);
this.ipfs.on('error', (e) => console.error('IPFS - error', e) );
this.ipfs.on('ready', async () => {
  this.orbitdb = new OrbitDB(this.ipfs, './test');
  // console.log('orbit - public key', this.orbitdb.key.getPublic('hex') );

  const dbConfig = {
    replicate: true,
    create: true,
    sync: true,
    localOnly: false,
    // type: 'keyvalue',
    // Give write access to ourselves
    // admin: [this.orbitdb.key.getPublic('hex')],
    write: ['*'],
  };
  this.db = await this.orbitdb.keyvalue('test.user', dbConfig);
/* /////////////////////////////////////////////////// */

  // Listen for updates from peers
  this.db.events.on('ready', (res) => {
    console.log('db ready', res);
    console.log('orbitdb - keyvalue', this.db.address.toString(), this.db.get('user'), this.db.get('state') );
    this.orbitObserver.next( { dbLoaded: true } );
  });
  this.db.events.on('synced', (res) => {
    console.log('db synced', res);
  });
  this.db.events.on('load.progress', (address, hash, entry, progress, total) => {
    console.log('db - load.progress', progress, total);
  });
  this.db.events.on('replicated', (address) => {
    console.log( 'db - replicated - state', this.db.get('state'), address );
  });
  this.db.events.on('replicate', (address) => console.log('db - replicate', address ) );
  this.db.events.on('replicate.progress', (address) => console.log('db - replicate progress', address) );
  this.db.events.on('write', (res) => {
    const userValue = this.db.get('user');
    const tmpValue = this.db.get('state');
    console.log('db write', res, userValue, tmpValue);
  });
  await this.db.load();
});

The events triggering are ready and write, but the db is always empty after reload the page.

Any help, please?

Thanks, E

@cristiano-belloni
Copy link

Just came back and updated my npm dependencied, and that's what I'm experiencing too.

I can write to a db, and read the values I wrote to it. But if I reload the page and load the db again, all the values are gone.

Current dependencies are:

"orbit-db": "^0.19.3",
"ipfs": "^0.27.7",

@haadcode
Copy link
Member

Thanks for reporting the issue @eusthace! And welcome back @cristiano-belloni!

This sound weird and should work as expected. Can either of you share the full project where this is happening so that I could take a look? This happens in the browser, right?

Could you run the browser examples and see if you're able to reproduce the problem with that?

@thiagodelgado111
Copy link
Member

I'll still check browser examples but here's a repo with a repro of the problem – although I think I might be doing something wrong.

https://github.com/thiagodelgado111/orbitdb-persistency-reproduce

@thiagodelgado111
Copy link
Member

thiagodelgado111 commented Feb 1, 2018

Looking at the browser example, using docstore
If you create a db and let it write an entry, after a reload, when you open that, it lists no entries.

I guess it has something to do with caching / level.js?

@haadcode
Copy link
Member

haadcode commented Feb 1, 2018

Thank you everyone for looking into this! ❤️I found the bug 👍😄

It is indeed the case in the browsers that the persisted db doesn't load. This was due to an early return in the local cache module (due to API differences between browser leveldb and nodejs leveldb). The good news is, the db does get persisted (as expected), it just wasn't loaded correctly.

This will be fixed with #316 and once it's in, I'll publish a new version to npm. Will post here when it's published.

@haadcode
Copy link
Member

haadcode commented Feb 1, 2018

Published to npm as 0.19.4.

Let us know, and re-open the issue, if you're still experiencing problems!

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

Successfully merging a pull request may close this issue.

4 participants