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

Remove file on storage termination #219

Merged
merged 2 commits into from
Jun 15, 2021
Merged
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
4 changes: 2 additions & 2 deletions integration_tests/01_storage_retrieval_ok.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ source "$my_dir/header.sh"

export DEALBOT_MINER_ADDRESS=t01000

dealbot storage-deal
dealbot storage-deal 2>&1 | tee dealbot.log

returnValue=$?
if [[ $returnValue -ne 0 ]]; then
echo "expected storage-deal to succeed, but it returned exit code != 0"
exit 1
fi

CID=$(lotus client local | tail -1 | awk '{print $2}')
CID=$(cat dealbot.log | grep datacid | sed 's/.*datacid": "//' | sed 's/"}//')

dealbot retrieval-deal --cid=$CID

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/02_controller_daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if ! grep -q 'INFO.*controller.*storage task.*"miner": "t01000",.*"size": 1024,.
exit 1
fi

CID=$(lotus client local | tail -1 | awk '{print $2}')
CID=$(cat dealbot-daemon.log | grep datacid | sed 's/.*datacid": "//' | sed 's/"}//')

# Also queue a retrieval task of the data we just stored.
curl --header "Content-Type: application/json" \
Expand Down
25 changes: 25 additions & 0 deletions tasks/storage_deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func MakeStorageDeal(ctx context.Context, config NodeConfig, node api.FullNode,
task: task,
}

defer func() {
_ = de.cleanupDeal()
}()

defaultTimeout := stageTimeouts[defaultStorageStageTimeoutName]
getStageCtx := func(stage string) (context.Context, context.CancelFunc) {
timeout, ok := stageTimeouts[stage]
Expand Down Expand Up @@ -251,6 +255,7 @@ func (de *storageDealExecutor) importFile(l logFunc) (err error) {
}

func (de *storageDealExecutor) executeAndMonitorDeal(ctx context.Context, updateStage UpdateStage, stageTimeouts map[string]time.Duration) error {

stage := "ProposeDeal"
dealStage := CommonStages[stage]()
err := updateStage(ctx, stage, dealStage)
Expand Down Expand Up @@ -379,6 +384,26 @@ func (de *storageDealExecutor) executeAndMonitorDeal(ctx context.Context, update
return nil
}

func (de *storageDealExecutor) cleanupDeal() error {
if de.importRes != nil {
// clear out the lotus import store for CIDs in this deal
err := de.node.ClientRemoveImport(de.ctx, de.importRes.ImportID)
if err != nil {
return err
}
de.importRes = nil
}
if de.fileName != "" {
// as a last step no matter what ended up happening with the deal, delete the generated file off to reclaim disk space
err := os.Remove(filepath.Join(de.config.DataDir, de.fileName))
if err != nil {
return err
}
de.fileName = ""
}
return nil
}

func mktime(t time.Time) _Time {
return _Time{x: t.UnixNano()}
}
Expand Down