Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Awesome datastore #797

Merged
merged 1 commit into from
Mar 23, 2017
Merged

Awesome datastore #797

merged 1 commit into from
Mar 23, 2017

Conversation

dignifiedquire
Copy link
Member

@dignifiedquire dignifiedquire commented Mar 17, 2017

Closes #787
Closes #229

  • refactored cli to use a context ipfs daemon to ensure cleanup
  • update to new datastore dependencies
  • fix timeout issues and add two new events (init and ready) to handle the startup of a daemon more granularly (needs discussion probably)
  • upgrade to yargs@7

@dignifiedquire dignifiedquire changed the title [WIP] Awesome datastore Awesome datastore Mar 19, 2017
@dignifiedquire
Copy link
Member Author

I am afraid this is not ready yet. I've discovered that the new creation and startup api is the source of quite some race conditions, which are becoming more visible with this PR, as the locking of the repo and open and close are more enforced.

We need to think through this very carefully as the options init and start combined with methods for doing those actions are nice for the user but create quite the tricky state management in the background. If we decide to keep the api we need to integrate a proper finite state machine to ensure all transitions are valid and very explicit descriptions on how things work.

Tldr setTimeout usually means you have a race condition you are hiding..

@dignifiedquire dignifiedquire mentioned this pull request Mar 20, 2017
22 tasks
src/cli/bin.js Outdated
.strict()
.completion()
.argv
utils.getIPFS((err, ipfs, cleanup) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init and daemon don't use an ipfs instance to run, how does this cover those two cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add an exception to those, I didn't realise that until later

@daviddias
Copy link
Member

Note: We can add a init event to the set up, it should solve all of the issues you are seeing as the only issue was when a repo is init'ed by default and gets started 'later', this later is the source of trouble because there is no way to monitor when the init has finished.

The finite state machine approach is also interesting, probably even better to keep the simplicity. Wanna take a stab at it?

@daviddias
Copy link
Member

@daviddias
Copy link
Member

Saw now that you added more events.

  • init is part of master now
  • ready why the need for this one, exactly?

@dignifiedquire
Copy link
Member Author

ready why the need for this one, exactly?

to detect the finishing things like new IPFS({init: false, start: false} which are alway async now, due to the need to detect and open the repo

@daviddias
Copy link
Member

@dignifiedquire in that case, there are no actions happening asynchronously.

@dignifiedquire
Copy link
Member Author

@dignifiedquire in that case, there are no actions happening asynchronously.

but they are now, because repo checks are async

Copy link
Member

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lot's of cool stuff here, 👍 for the state machine approach!

Still needs some changes though.

start: false,
EXPERIMENTAL: {
pubsub: true
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why disabling PubSub?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not disabled, it is enabled in the httpserver as far as I understand

Copy link
Member

@daviddias daviddias Mar 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, true. Although it should be really just a config passed. Like @pgte is doing here #805

src/cli/bin.js Outdated
// Need to skip to avoid locking the daemon
if (args[0] === 'daemon' || args[0] === 'init') {
return cli.help().strict(false).completion().parse(args)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this more clear:

// commands that don't require a daemon/instance
// commands that require a daemon/instance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, use same indentation in both

}
cb(null, block)
})
], callback)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has changed the API, block needs to be able to:

» jsipfs block put --help
jsipfs block put [block]

Options:
  --help        Show help                                              [boolean]
  --format, -f  cid format for blocks to be created with.    [default: "dag-pb"]
  --mhtype      multihash hash function                    [default: "sha2-256"]
  --mhlen       multihash hash length

Before we passed that through CID, if you remove the CID from equation and always calculate the multihash of sha256, then you can't block put eth data anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand your concern, if you want to specify your own things you pass a regular ipfs block here which already defines the cid it wants, this way things are passed through as expected

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the hashing is just a fallback if only a buffer is passed in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. I see, you now expect everything in the block.

Can we also have the options object, we will need to support the hashAlg and format. But that can be a separate PR

bootstrap: config.Bootstrap
mdns: get(config, 'Discovery.MDNS.Enabled'),
webRTCStar: get(config, 'Discovery.webRTCStar.Enabled'),
bootstrap: get(config, 'Bootstrap')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requiring a dependency to pick one property of an object?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that undefined chains don't throw. This code explodes if you try to read a config from go-ipfs as it doesn't have a webRTCStar field in discovery.

@@ -31,7 +30,7 @@ module.exports = function preStart (self) {

if (!mafmt.IPFS.matches(ma)) {
ma = ma.encapsulate('/ipfs/' +
self._peerInfo.id.toB58String())
self._peerInfo.id.toB58String())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange identation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very strange

running: 'running',
stopping: 'stopping',
stopped: 'stopped'
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, in order to follow the sequence of booting a node, we need to open 4+ files.

Let's put this into the state.js.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked, this is just used to populate a var this._status once and that const is not used anymore. ???

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the rest from some experimentation, going to delete it

cb()
})
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this now? Breaking API change? If so, update README

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know this was in the readme, this is not needed anymore internally that's why I removed it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't find it in the readme, are you sure this was documented somewhere?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, not on the readme, people are using it though - #776

Wanna finish that PR and merge it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets get this merged and then I can do that PR, I don't want to put even more things into here than there are already

})
} catch (err) {
return cb(err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is throwing? Errors should come on the error event only.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can throw if someone screwed up in the implementation, resulting in silent fail of the tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let's add that comment, I want to avoid giving the idea that errors should be 'thrown' for contributors coming into the codebase.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,2 @@
=============== Mar 18, 2017 (CET) ===============
00:21:30.447664 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.gitignore this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1 @@
1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it really version 1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm no not sure why that says version 1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on disk it says 5 for me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, there were two

@daviddias
Copy link
Member

daviddias commented Mar 22, 2017

Seems that last thing is to rebase master onto this branch :)

@daviddias daviddias force-pushed the feat/datastore branch 3 times, most recently from f486cac to d59dc43 Compare March 22, 2017 16:52
@daviddias
Copy link
Member

image

I need to leave now for up to 3 hours, will come back online later.

@dignifiedquire, let me know if you can check this.

@dignifiedquire
Copy link
Member Author

last missing piece ipfs/js-ipfs-repo#128 (hopefully)

@daviddias daviddias merged commit 706ada2 into master Mar 23, 2017
@daviddias daviddias deleted the feat/datastore branch March 23, 2017 00:45
@daviddias daviddias removed the status/in-progress In progress label Mar 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Awesome Datastore Endeavour daemon leaves behind api file lock on error
2 participants