Commit Graph

500 Commits

Author SHA1 Message Date
Hector Sanjuan
f01612ca63 types: serialize pin types as string and not as a number
The pin type in json objects will not be understandable by humans
2022-04-07 14:44:04 +02:00
Hector Sanjuan
1d98538411 Adders: stream blocks to destinations
This commit fixes #810 and adds block streaming to the final destinations when
adding. This should add major performance gains when adding data to clusters.

Before, everytime cluster issued a block, it was broadcasted individually to
all destinations (new libp2p stream), where it was block/put to IPFS (a single
block/put http roundtrip per block).

Now, blocks are streamed all the way from the adder module to the ipfs daemon,
by making every block as it arrives a single part in a multipart block/put
request.

Before, block-broadcast needed to wait for all destinations to finish in order
to process the next block. Now, buffers allow some destinations to be faster
than others while sending and receiving blocks.

Before, if a block put request failed to be broadcasted everywhere, an error
would happen at that moment.

Now, we keep streaming until the end and only then report any errors. The
operation succeeds as long as at least one stream finished successfully.

Errors block/putting to IPFS will not abort streams. Instead, subsequent
blocks are retried with a new request, although the method will return an
error when the stream finishes if there were errors at any point.
2022-03-24 17:24:58 +01:00
Hector Sanjuan
eee53bfa4f Streaming Peers(): make Peers() a streaming call
This commit makes all the changes to make Peers() a streaming call.

While Peers is usually a non problematic call, for consistency, all calls
returning collections assembled through broadcast to cluster peers are now
streaming calls.
2022-03-23 01:27:57 +01:00
Hector Sanjuan
0d73d33ef5 Pintracker: streaming methods
This commit continues the work of taking advantage of the streaming
capabilities in go-libp2p-gorpc by improving the ipfsconnector and pintracker
components.

StatusAll and RecoverAll methods are now streaming methods, with the REST API
output changing accordingly to produce a stream of GlobalPinInfos rather than
a json array.

pin/ls request to the ipfs daemon now use ?stream=true and avoid having to
load the full pinset map on memory. StatusAllLocal and RecoverAllLocal
requests to the pin tracker stream all the way and no longer store the full
pinset, and the full PinInfo status slice before sending it out.

We have additionally switched to a pattern where streaming methods receive the
channel as an argument, allowing the caller to decide on whether to launch a
goroutine, do buffering etc.
2022-03-22 15:38:01 +01:00
Hector Sanjuan
055afbfafd api client: do not break if streaming endpoint returns 204 2022-03-19 12:26:15 +01:00
Hector Sanjuan
9b9d76f92d Pinset streaming and method type revamp
This commit introduces the new go-libp2p-gorpc streaming capabilities for
Cluster. The main aim is to work towards heavily reducing memory usage when
working with very large pinsets.

As a side-effect, it takes the chance to revampt all types for all public
methods so that pointers to static what should be static objects are not used
anymore. This should heavily reduce heap allocations and GC activity.

The main change is that state.List now returns a channel from which to read
the pins, rather than pins being all loaded into a huge slice.

Things reading pins have been all updated to iterate on the channel rather
than on the slice. The full pinset is no longer fully loaded onto memory for
things that run regularly like StateSync().

Additionally, the /allocations endpoint of the rest API no longer returns an
array of pins, but rather streams json-encoded pin objects directly. This
change has extended to the restapi client (which puts pins into a channel as
they arrive) and to ipfs-cluster-ctl.

There are still pending improvements like StatusAll() calls which should also
stream responses, and specially BlockPut calls which should stream blocks
directly into IPFS on a single call.

These are coming up in future commits.
2022-03-19 03:02:55 +01:00
Hector Sanjuan
759dd4802d Fix 1598: Include allocations in responses from /add
This adds a new allocations field to add response objects which
provides the cluster peers to which the content has been allocated.

In the case of sharded dags, it provides peers for the current shard.
2022-03-15 11:03:11 +01:00
Hector Sanjuan
e4b11b783b Pinsvcapi: address comments from review
- Add "Created" field to pinInfo.
- Support before/after filter
- 404 when something is unpinned or on a non-recognize state
2022-03-14 12:21:08 +01:00
Hector Sanjuan
0c556ef4fa tests: fix staticcheck/vet errors 2022-03-11 16:47:41 +01:00
Hector Sanjuan
3029972750 pinsvcapi: test GetPin and DeletePin endpoints 2022-03-11 16:41:48 +01:00
Hector Sanjuan
fbc69ee3c6 pinsvcapi: fix several API test failures 2022-03-11 16:18:08 +01:00
Hector Sanjuan
cd5f9c869d pinsvcapi: Test and fix bugs in Add Pin. Improve performance. 2022-03-11 14:01:15 +01:00
Hector Sanjuan
f8812b3af7 pinsvc: fixes and testing for List endpoint 2022-03-11 12:58:12 +01:00
Hector Sanjuan
ab33ec668c pinsvcapi: fix some basic bugs 2022-03-11 00:46:39 +01:00
Hector Sanjuan
5fed4a2c5e types: include IPFSAddresses in pinInfo objects.
pinsvcapi: do not cache peer information here as all the needed information is
in the status objects.

This adds ipfs_addresses as a field broadcasted with the ping metrics.
2022-03-10 23:49:01 +01:00
Hector Sanjuan
5b0d9d68e3 Merge branch 'master' into feat/pinning-api 2022-03-10 13:41:54 +01:00
Hector Sanjuan
00b7925e78 ipfs-cluster-ctl: support "status cid1 cid2 ..." 2022-03-01 13:25:07 +01:00
Hector Sanjuan
a1b6dabbb0 Add StatusCids() to Restapi client 2022-03-01 13:13:52 +01:00
Hector Sanjuan
00dffe23b8 Adder: Add "no-pin" option.
This does 3 things:

- Add a NoPin option to the adder. When set to true, the adding process does not
send a pin in the end.

- When user-allocations are set and local=true happens, we do not overwrite
  the allocations returned by the allocator to include the local peer
  anymore, as this could alter user-allocations.

- Some code improvement (remove pointers).
2022-02-28 20:10:12 +01:00
Hector Sanjuan
54a11d7277 Add bad test file (it does not work, just for tracking) 2022-02-02 00:52:39 +01:00
Hector Sanjuan
095fa8effe pinsvc: request_id -> requestid 2022-02-02 00:52:39 +01:00
Hector Sanjuan
a744ee5206 Pin CID must be a string and not a jsoned-cid ({"/":"cid"}) 2022-02-02 00:52:39 +01:00
Hector Sanjuan
b25b5e734b Adjust multiaddress types 2022-02-02 00:52:39 +01:00
Hector Sanjuan
583011c3a4 Fix panic in common api tests 2022-02-02 00:52:39 +01:00
Hector Sanjuan
524e2ecbc0 Wire in pinsvcapi to ipfs-cluster-service 2022-02-02 00:52:39 +01:00
Hector Sanjuan
40bdb795e8 pinsvcapi: extract types into their own module for better re-use later 2022-02-02 00:52:39 +01:00
Hector Sanjuan
9549e0c86e api: Add the Pinning Services API module
This fixes #1213. It adds partial support for the Pinning Services API with some caveats:

* RequestIDs == CIDs. This is a violation of the spec, as request IDs will not be unique etc.
* Pagination, name matching, metadata matching, ordering etc. are not supported in the List endpoint.
* The List endpoint only supports status filtering and cid query parameter.
* Created time property is not supported and always set to Now()

There is more work to do here: cleanup, extract useful types etc. and TESTS.
2022-02-02 00:52:39 +01:00
Hector Sanjuan
0787ffbe36 PinInfo type: include Allocations, Origins, Metadata
This will facilitate building outputs for the Pinning Services API, saving a
round trip to query the cluster State, since all the needed information
already comes from the PinTracker, which has already accessed the state.

Since the pintracker already included a state attribute (Name), we are simply
going down that path.
2022-02-02 00:52:38 +01:00
Hector Sanjuan
ea624d50e4 common api: automatically set NotFound errors 2022-02-02 00:44:27 +01:00
Hector Sanjuan
a5eb3f2db0 api: Support a custom error function for custom error messages 2022-02-02 00:43:00 +01:00
Hector Sanjuan
223b54cab6 Restapi: add "cids" query param to /pins
This allows to specifically request status for several CIDs as
provided in the "cids" query parameter, instead of request status for
all CIDs.

In this case, the filter is ignored.
2022-02-02 00:39:09 +01:00
Hector Sanjuan
5e89c0ba41 Pintracker: set Name in operation tracker. Fixes #1212. 2022-01-31 21:04:11 +01:00
Hector Sanjuan
809b7fbda5 Pintracker: add IPFS ID to Pin Information
Fixes #1554
Fixes: peer names unset for remote peers

This adds an IPFS field to pin status information (PinInfoShort).

It has not been easy to add this, given that the IPFS ID is something that
comes from outside of cluster (unlike the peer name). After several tries I
have settled in the following things:

- Use the ping metric to send out peer names and IPFS IDs to the peers in the
  cluster.
- Cache the latest known IPFS ID (if IPFS dies we should still be setting
  the ID).
- Provide an RPC method for the Pintracker to obtain IPFS ID from the cache.
- Given we now know information for peernames and IPFS IDs from other peers,
  we can use that information even if the requests to them error or we are not
  contacting (i.e. peers allocated as remote are not queried for status). We can
  use the information from the last received ping metric.
- This means we should keep metrics around even if peers go away, at least for
  a while rather than deleting them as soon as we detect that they have expired.

Puting it all together we now have a system to gossip peer information around on top
of the ping metrics.
2022-01-31 17:53:09 +01:00
Hector Sanjuan
a93886aeee
Merge pull request #1540 from ipfs/dependency-upgrades
Dependency upgrades
2022-01-11 17:11:13 +01:00
Hector Sanjuan
862f4b515f Update protobuf compiler and generated files 2022-01-11 16:47:45 +01:00
Hector Sanjuan
c71e42f5ad API: update basic-auth tests to allow OPTIONS 2021-12-22 14:06:29 +01:00
Hector Sanjuan
bba410af32 API: OPTIONS requests should bypass authentication
They need to be handled directly by the CORS handler.

Fixes #1512
2021-12-22 13:26:03 +01:00
Hector Sanjuan
7e85d90bae misc: re-order some imports 2021-12-17 11:47:50 +01:00
Hector Sanjuan
93e2cca49b Fix state deserialization
The pin objects now include an Origin field which was set to
multiaddr.Multiaddr.

This type is an interface and has no idea how to deserialize itself. As a
result, an state json export cannot be deseralized.

We had already added a wrapper Multiaddr type to handle these issues. I
believe this fix does not affect anything else other than fixing
UnmarshalJSON. PB types are deserialized by hand and it should not make a
difference.
2021-12-13 17:31:18 +01:00
Hector Sanjuan
0d21896883
Merge pull request #1490 from ipfs/fix/1469-pin-prio
Pintracker: support prioritary pinning for recent pins with small number of retries
2021-11-30 20:55:42 +01:00
Hector Sanjuan
db93c50c2d Fix rest client tests: do not use QUIC 2021-11-30 07:05:35 +01:00
Hector Sanjuan
4739ed9210 Changes pertaining to go-libp2p v0.16.0 2021-11-30 06:25:15 +01:00
Hector Sanjuan
fdc3abcb23 api: use default transports for the libp2p host. 2021-11-30 06:06:10 +01:00
Hector Sanjuan
7cf40de354 pintracker: Fix attempt count not increasing. Expose priority queueing.
"RetryCount" has been renamed to "AttemptCount", because it counts attempts.
2021-11-30 04:20:35 +01:00
Hector Sanjuan
29c277b67f Pintracker: add and track retry counts in the operation manager.
Report retry count in the PinStatus
2021-11-30 04:20:35 +01:00
Hector Sanjuan
3ddda1fb59 Merge branch 'master' into dependency-upgrades 2021-10-27 15:55:34 +02:00
Hector Sanjuan
32386d853a Dependency upgrades 2021-10-20 16:56:24 +02:00
Hector Sanjuan
e9857652f2 Add a timestamp to Pins
This adds a Timestamp field to the pin objects. This allows to track when they were pinned.

This:

* Allows the pin-tracker to actually show accurate information on when the pin
  entered the system for pins that are not part of ongoing operations
  (currently it shows time.Now())
* Adds support for reporting timestamp on a pinning services api.
2021-10-20 16:55:57 +02:00
Hector Sanjuan
96db605c50
Merge pull request #1468 from ipfs/fix/159-improved-allocators
Add tags informer and enable partition-based peer allocations for intelligent distribution
2021-10-06 14:35:16 +02:00
Hector Sanjuan
db00d651bf Balanced allocator: weight-based ordering of partitions
This fixes the issue about partitions not being picked based
on the amount of freespace available in them.

It additionally removes the metrics registry and carries information directly
in the metric.

Metrics have two additional fields: Weight and Partitionable.

Informers have been updated to make use of these fields. Partitions have
weights that equals to the weight of the metrics under them.

Older cluster versions will not set these fields. Partitionable is false by
default and weight has a GetWeight() function to convert value->weight when
unset. This provides backwards compatibility for the freespace metric.
2021-10-06 14:10:06 +02:00