Commit Graph

250 Commits

Author SHA1 Message Date
Kishan Mohanbhai Sagathiya
e4e1cbea6e Fix #481: Pin expiration
This adds a new PinOption: ExpireAt.

The StateSync ticker will check and unpin expired pins from the Cluster.

ipfs-cluster-ctl supports an "expire-in" which gives a duration.
2019-11-05 10:40:48 +01:00
Hector Sanjuan
ce20e86fdb
Merge pull request #907 from ipfs/feat/local-add
`--local` flag for `ctl add`
2019-09-23 13:13:59 -04:00
Hector Sanjuan
a98292bfa6
Merge pull request #893 from ipfs/feat/recover-all
Pin recover on all peers
2019-09-23 13:13:48 -04:00
Kishan Mohanbhai Sagathiya
6543c0c79b Addressed reviews 2019-09-10 20:05:38 +07:00
Kishan Mohanbhai Sagathiya
adc7c5b131 Merge branch 'master' of github.com:ipfs/ipfs-cluster into test2 2019-09-10 20:03:05 +07:00
Hector Sanjuan
18dad223b2
Merge pull request #912 from ipfs/fix/allocations
Fix: handling allocations
2019-09-09 10:22:14 +02:00
Kishan Mohanbhai Sagathiya
9cb1cdeaff Merge branch 'master' into feat/recover-all 2019-09-08 17:06:43 +07:00
Hector Sanjuan
96752e4e58 Fix: handling allocations
* pin() should not allocate if allocations are already provided
* pin() should not skip pinning if the exact same pin exists
  * Additionally this was unreliable as it allocated it before
    so the pin may have existed but the allocations may have been
    artificially changed.
* pin() re-uses existing pin when pin options are the same and thus
  avoids changing the allocations of a pin.

As a side effect, this fixes re-allocations which were broken: peers
called `shouldPeerRepinCid()` and instead of repinning that single
cid proceeded to repin the full state. For every pin.

Additionally tests have been adapted. It may be that some re-alloc tests
were very unreliable for the problems above.
2019-09-06 17:56:00 +02:00
Hector Sanjuan
81ea1e76bc Merge branch 'master' into feat/sort-responses 2019-09-06 15:13:54 +02:00
Hector Sanjuan
c2b28be6de
Merge pull request #901 from ipfs/fix/pin-queue-full
Error queue is full
2019-09-06 15:05:53 +02:00
Hector Sanjuan
d63a7fd641
Merge pull request #877 from ipfs/fix/ipfs-to-p2p
Use `p2p` protocol name over `ipfs` for multiaddr
2019-09-06 15:00:36 +02:00
Kishan Mohanbhai Sagathiya
c9e6cd25cd No need to use separate dag service for local add 2019-08-31 19:40:56 +05:30
Hector Sanjuan
a399d893b7 Remove mdns debug logging
Leftover
2019-08-28 12:09:04 +02:00
Hector Sanjuan
1b91303fe0 Do not allocate an unused item for the trackedPinsMap 2019-08-28 12:08:41 +02:00
Kishan Mohanbhai Sagathiya
4febf87d79 Rename local dagservice to single dagservice
Local dagservice is not really a local as it add to other peers as well.
It is a dagservice that does not perform sharding. Since we are going to
have a local dagservice(one that adds only to the local peer), renaming
this `single` dagservice
2019-08-28 15:20:55 +05:30
Kishan Mohanbhai Sagathiya
7cb13cb97d Abort on any error 2019-08-27 09:38:41 +05:30
Kishan Mohanbhai Sagathiya
c109a01343 Sort peers for crdt consensus.Peers 2019-08-26 18:27:17 +05:30
Kishan Mohanbhai Sagathiya
2d9e6c1de8 Error queue is full
- abort if a Track() calls fails due to queue being full
- increase max pin queue size to 1 million
- hind max_pin_queue_size from configuration
- use an elaborated error message

Fixes #377
2019-08-26 13:23:02 +05:30
Hector Sanjuan
33f111c44d mDNS: attach mDNS inside the Cluster. Allow interval configuration.
Setting up mDNS outside the Cluster is dirtier and allows less configuration.

This adds MDNSInterval to the cluster config options and allow disabling it
when the option is set to 0.
2019-08-24 17:24:18 +02:00
Kishan Mohanbhai Sagathiya
512bf6a13b Pin recover on all peers
- recover works without `--local` flag as well (recovers all pins on all
peers)
- remove extra space from rpc policy

Fixes #763
2019-08-21 11:19:07 +05:30
Kishan Mohanbhai Sagathiya
e6d183fd70 Addressed reviews 2019-08-20 10:49:28 +05:30
Kishan Mohanbhai Sagathiya
eba6efd457 Merge branch 'master' of github.com:ipfs/ipfs-cluster into feat/sort-responses 2019-08-16 13:34:09 +05:30
Kishan Mohanbhai Sagathiya
6656b80a00 Some more occurences of /ipfs
and use  SwapToP2pMultiaddrs (very helpful since ipfs still send
addresses with `/ipfs` tag)
2019-08-16 11:56:09 +05:30
Kishan Mohanbhai Sagathiya
ee6a35d9b5 Sort addresses in /id
and thus in GET `/peers` as well
2019-08-11 21:15:43 +05:30
Hector Sanjuan
1eade4ae58 Fix #732: Introduce native pin/update
This introduces a pin/update operation which allows to Pin a new item to
cluster indicating that said pin is an update to an already-existing pin.

When this is the case, all the configuration for the existing pin is copied to
the new one (including allocations). The IPFS connector will then trigger
pin/update directly in IPFS, allowing an efficient pinning based on
DAG-differences. Since the allocations where the same for both pins,
the pin/update can proceed.

PinUpdate does not unpin the previous pin (it is not possible to do this
atomically in cluster like it happens in IPFS). The user can manually do it
after the pin/update is done.

Internally, after a lot of deliberations on what the optimal way for this is,
I opted for adding a `PinUpdate` option to the `PinOptions` type (carries the
CID to update from). In order to carry this option from the REST API to the
IPFS Connector, it is serialized in the Protobuf (and stored in the
datastore). There is no other way to do this in a simple fashion since the Pin
object is piece of information that is sent around.

Additionally, making it a PinOption plays well with the Pin/PinPath APIs which
need little changes. Effectively, you are pinning a new thing. You are just
indicating that it should be configured from an existing one.

Fixes #732
2019-08-09 16:11:52 +02:00
Hector Sanjuan
1dfb396402
Update cluster.go
Co-Authored-By: Kishan Sagathiya <kishansagathiya@gmail.com>
2019-08-07 10:12:46 +02:00
Hector Sanjuan
084e763468 Fix #803: Add "follower_mode" to the config
Peers configured with follower_mode = true fail to add/pin/unpin.

Additionally they do not contact other peers when doing Status, Sync or
Recover and report on themselves.

They still contact other peers when doing "peers ls", as this is an OpenRPC
endpoint.

This is merely improving user interaction with a cluster peer and avoids
getting into confusing places:

* pin/unpin seems to work even no one trusts them
* status will query all peers in the peerset only to get auth errors and
ignore them, becoming way slower than it could be

This is not a security feature.
2019-07-30 19:59:59 +02:00
Kishan Sagathiya
e7b731e0e4 Fix #835: service: init --peers
* Init should take a list of peers

This commit adds `--peers` option to `ipfs-cluster-service init`

`ipfs-cluster-service init --peers <multiaddress,multiaddress>`

- Adds and writes the given peers to the peerstore file
- For raft config section, adds the peer IDs to the `init_peerset`
- For crdt config section, add the peer IDs to the `trusted_peers`
2019-07-25 10:47:44 +02:00
Hector Sanjuan
7c636061bd
Improve pin/unpin method signatures (#843)
* Improve pin/unpin method signatures:

These changes the following Cluster Go API methods:

* -> Cluster.Pin(ctx, cid, options) (pin, error)
* -> Cluster.Unpin(ctx, cid) (pin, error)
* -> Cluster.PinPath(ctx, path, opts) (pin,error)

Pin and Unpin now return the pinned object.

The signature of the methods now matches that of the API Client, is clearer as
to what options the user can set and is aligned with PinPath, UnpinPath, which
returned pin methods.

The REST API now returns the Pinned/Unpinned object rather than 204-Accepted.

This was necessary for a cleaner pin/update approach, which I'm working on in
another branch.

Most of the changes here are updating tests to the new signatures

* Adapt load-balancing client to new Pin/Unpin signatures

* cluster.go: Fix typo

Co-Authored-By: Kishan Sagathiya <kishansagathiya@gmail.com>

* cluster.go: Fix typo

Co-Authored-By: Kishan Sagathiya <kishansagathiya@gmail.com>
2019-07-22 15:39:11 +02:00
Hector Sanjuan
997208a82f Feat: regularly trigger "recover" automatically
Interval controlled by a pin_recover_interval option in the config.
2019-07-08 16:55:05 +02:00
Hector Sanjuan
b804e61ef0 Update deps along with go-libp2p-core refactor
Lots of rewrites in imports...
2019-06-14 13:10:45 +02:00
Hector Sanjuan
2d5b31ad6a Fix #787: reBoostrap reguarly
This should fix a problem pointed out in #787 about a peer not
being able to recover in CRDT mode after a router re-start (when we lose
all connections to all peers). We attempt to re-open connections to
boostrap peers regularly.
2019-06-09 15:12:19 +02:00
Hector Sanjuan
e665704962 cluster.go: collect active goroutines on shutdown
It seems we did not add any c.wg.Add(1) goroutines so shutdown
did not wait for anything to finish.
2019-06-09 15:12:19 +02:00
Hector Sanjuan
ef2ec2f5b0 Fix #805: Make bootstrapped peers appear as part of the pinset right away 2019-06-09 15:12:19 +02:00
Hector Sanjuan
196aa23f34 Fix #787: Connectivity fixes
Currently, unless doing Join() (--bootstrap), we do not connect to any peers on startup.

We however loaded up the peerstore file and Raft will automatically connect
older peers to figure out who is the leader etc. DHT bootstrap, after Raft
was working, did the rest.

For CRDTs we need to connect to people on a normal boot as otherwise, unless
bootstrapping, this does not happen, even if the peerstore contains known peers.

This introduces a number of changes:

* Move peerstore file management back inside the Cluster component, which was
already in charge of saving the peerstore file.
* We keep saving all "known addresses" but we load them with a non permanent
TTL, so that there will be clean up of peers we're not connected to for long.
* "Bootstrap" (connect) to a small number of peers during Cluster component creation.
* Bootstrap the DHT asap after this, so that other cluster components can
initialize with a working peer discovery mechanism.
* CRDT Trust() method will now:
  * Protect the trusted Peer ID in the conn manager
  * Give top priority in the PeerManager to that Peer (see below)
  * Mark addresses as permanent in the Peerstore

The PeerManager now attaches priorities to peers when importing them and is
able to order them according to that priority. The result is that peers with
high priority are saved first in the peerstore file. When we load the peerstore
file, the first entries in it are given the highest priority.

This means that during startup we will connect to "trusted peers" first
(because they have been tagged with priority in the previous run and saved at
the top of the list). Once connected to a small number of peers, we let the
DHT bootstrap process in the background do the rest and discover the network.

All this makes the peerstore file a "bootstrap" list for CRDTs and we will attempt
to connect to peers on that list until some of those connections succeed.
2019-05-27 14:27:23 +02:00
Hector Sanjuan
96edbc1ea6 Daemon: handle host and DHT lifecycle outside Cluster
The Host and DHT are created outside of cluster and should be
shutdown outside of it, not inside.
2019-05-25 00:23:46 +02:00
Hector Sanjuan
8e6eefb714 Tests: multiple fixes
This fixes multiple issues in and around tests while
increasing ttls and delays in 100ms. Multiple issues, including
races, tests not running with consensus-crdt missing log messages
and better initialization have been fixed.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
2019-05-20 23:45:04 +02:00
Hector Sanjuan
d51c2a0377 Merge branch 'master' into feat/monitor-ring 2019-05-16 15:46:30 +02:00
Hector Sanjuan
a86c7cae2b rpc auth: handle some auth errors gracefully
particuarly we will ignore authorization errors for some broadcasts and somply
not include those responses in the assembled one.
2019-05-09 21:23:49 +02:00
Hector Sanjuan
2ed48b6ac4 RPC auth: Rework PeerAdd and Join
PeerAdd called RPC endpoints for `LogMetric` and `ConnectSwarms`
remotely. However, I think similar effect can be achieved by calling
these from the Join() function locally.

In particular, ConnectSwarms was called when maybe the joining peer did not
even know about the other peers in the Cluster. Now this is delayed until some
ping metrics have come through.
2019-05-09 14:19:07 +02:00
Hector Sanjuan
3d49ac26a5 Feat: Split components into RPC Services
I had thought of this for a very long time but there were no compelling
reasons to do it. Specifying RPC endpoint permissions becomes however
significantly nicer if each Component is a different RPC Service. This also
fixes some naming issues like having to prefix methods with the component name
to separate them from methods named in the same way in some other component
(Pin and IPFSPin).
2019-05-04 21:36:10 +01:00
Hector Sanjuan
2144f4bd42 Types: make UserAllocations []peer.ID instead of string
It seems we forgot to convert this after peer.IDs became serializable. This
fixes it.
2019-04-29 16:24:38 +02:00
Adrian Lanzafame
42693eb06d
fix passing ctx from daemon to pubsub
License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
2019-04-29 17:58:28 +10:00
Adrian Lanzafame
6d593799ba
access state via consensus
License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
2019-04-18 17:41:32 +10:00
Adrian Lanzafame
eae4329cb3
address pr feedback
License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
2019-04-18 16:18:19 +10:00
Adrian Lanzafame
31af640e33
use allocations list to choose peer to repin
License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
2019-04-18 16:16:40 +10:00
Adrian Lanzafame
638cf73f5f
fix pointer
License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
2019-04-18 16:16:40 +10:00
Adrian Lanzafame
0041f5cb8f
add todo comment
License: MIT
Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
2019-04-18 16:16:40 +10:00
Hector Sanjuan
acbd7fda60 Consensus: add new "crdt" consensus component
This adds a new "crdt" consensus component using go-ds-crdt.

This implies several refactors to fully make cluster consensus-component
independent:

* Delete mapstate and fully adopt dsstate (after people have migrated).
* Return errors from state methods rather than ignoring them.
* Add a new "datastore" modules so that we can configure datastores in the
   main configuration like other components.
* Let the consensus components fully define the "state.State". Thus, they do
not receive the state, they receive the storage where we put the state (a
go-datastore).
* Allow to customize how the monitor component obtains Peers() (the current
  peerset), including avoiding using the current peerset. At the moment the
  crdt consensus uses the monitoring component to define the current peerset.
  Therefore the monitor component cannot rely on the consensus component to
  produce a peerset.
* Re-factor/re-implementation of "ipfs-cluster-service state"
  operations. Includes the dissapearance of the "migrate" one.

The CRDT consensus component defines creates a crdt-datastore (with ipfs-lite)
and uses it to intitialize a dssate. Thus the crdt-store is elegantly
wrapped. Any modifications to the state get automatically replicated to other
peers. We store all the CRDT DAG blocks in the local datastore.

The consensus components only expose a ReadOnly state, as any modifications to
the shared state should happen through them.

DHT and PubSub facilities must now be created outside of Cluster and passed in
so they can be re-used by different components.
2019-04-17 19:14:26 +02:00
Kishan Mohanbhai Sagathiya
226953dd26 Make IPFSID pointer
Make IPFSID pointer so that it can be made nil when empty
2019-03-18 18:24:56 +05:30