Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add api endpoint to remove retirevals #8525

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ type FullNode interface {
ClientRetrieve(ctx context.Context, params RetrievalOrder) (*RestrievalRes, error) //perm:admin
// ClientRetrieveWait waits for retrieval to be complete
ClientRetrieveWait(ctx context.Context, deal retrievalmarket.DealID) error //perm:admin
// ClientRemoveRetrieval removes retrieved data from the local retrieval store
ClientRemoveRetrieval(ctx context.Context, exportRef ExportRef) error
// ClientExport exports a file stored in the local filestore to a system file
ClientExport(ctx context.Context, exportRef ExportRef, fileRef FileRef) error //perm:admin
// ClientListRetrievals returns information about retrievals made by the local client
Expand Down
14 changes: 14 additions & 0 deletions api/mocks/mock_full.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
Binary file modified build/openrpc/worker.json.gz
Binary file not shown.
28 changes: 28 additions & 0 deletions documentation/en/api-v1-unstable-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
* [ClientMinerQueryOffer](#ClientMinerQueryOffer)
* [ClientQueryAsk](#ClientQueryAsk)
* [ClientRemoveImport](#ClientRemoveImport)
* [ClientRemoveRetrieval](#ClientRemoveRetrieval)
* [ClientRestartDataTransfer](#ClientRestartDataTransfer)
* [ClientRetrieve](#ClientRetrieve)
* [ClientRetrieveTryRestartInsufficientFunds](#ClientRetrieveTryRestartInsufficientFunds)
Expand Down Expand Up @@ -1929,6 +1930,33 @@ Inputs:

Response: `{}`

### ClientRemoveRetrieval
ClientRemoveRetrieval removes retrieved data from the local retrieval store


Perms:

Inputs:
```json
[
{
"Root": {
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
"DAGs": [
{
"DataSelector": "Links/21/Hash/Links/42/Hash",
"ExportMerkleProof": true
}
],
"FromLocalCAR": "string value",
"DealID": 5
}
]
```

Response: `{}`

### ClientRestartDataTransfer
ClientRestartDataTransfer attempts to restart a data transfer with the given transfer ID and other peer

Expand Down
47 changes: 37 additions & 10 deletions node/impl/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,39 +933,66 @@ func (ed *ExportDest) doWrite(cb func(io.Writer) error) error {
return f.Close()
}

func (a *API) ClientExport(ctx context.Context, exportRef api.ExportRef, ref api.FileRef) error {
return a.ClientExportInto(ctx, exportRef, ref.IsCAR, ExportDest{Path: ref.Path})
}
func (a *API) retrievalDagService(exportRef api.ExportRef) (
dserv format.DAGService,
retrieveIntoIPFS bool,
retrievalBs bstore.Blockstore,
carPath string,
err error) {

func (a *API) ClientExportInto(ctx context.Context, exportRef api.ExportRef, car bool, dest ExportDest) error {
proxyBss, retrieveIntoIPFS := a.RtvlBlockstoreAccessor.(*retrievaladapter.ProxyBlockstoreAccessor)
carBss, retrieveIntoCAR := a.RtvlBlockstoreAccessor.(*retrievaladapter.CARBlockstoreAccessor)
carPath := exportRef.FromLocalCAR
carPath = exportRef.FromLocalCAR

if carPath == "" {
if !retrieveIntoIPFS && !retrieveIntoCAR {
return xerrors.Errorf("unsupported retrieval blockstore accessor")
err = xerrors.Errorf("unsupported retrieval blockstore accessor")
return
}

if retrieveIntoCAR {
carPath = carBss.PathFor(exportRef.DealID)
}
}

var retrievalBs bstore.Blockstore
if retrieveIntoIPFS {
retrievalBs = proxyBss.Blockstore
} else {
cbs, err := stores.ReadOnlyFilestore(carPath)
var cbs stores.ClosableBlockstore
cbs, err = stores.ReadOnlyFilestore(carPath)
if err != nil {
return err
return
}
defer cbs.Close() //nolint:errcheck
retrievalBs = cbs
}

dserv := merkledag.NewDAGService(blockservice.New(retrievalBs, offline.Exchange(retrievalBs)))
dserv = merkledag.NewDAGService(blockservice.New(retrievalBs, offline.Exchange(retrievalBs)))
return
}

func (a *API) ClientRemoveRetrieval(ctx context.Context, exportRef api.ExportRef) error {
dserv, _, _, carPath, err := a.retrievalDagService(exportRef)
if err != nil {
return err
}
if carPath != "" {
os.Remove(carPath)
} else {
dserv.Remove(ctx, exportRef.Root)
}
return nil
}

func (a *API) ClientExport(ctx context.Context, exportRef api.ExportRef, ref api.FileRef) error {
return a.ClientExportInto(ctx, exportRef, ref.IsCAR, ExportDest{Path: ref.Path})
}

func (a *API) ClientExportInto(ctx context.Context, exportRef api.ExportRef, car bool, dest ExportDest) error {
dserv, retrieveIntoIPFS, retrievalBs, carPath, err := a.retrievalDagService(exportRef)
if err != nil {
return err
}
// Are we outputting a CAR?
if car {
// not IPFS and we do full selection - just extract the CARv1 from the CARv2 we stored the retrieval in
Expand Down