Skip to content

Delete committed connections #1540

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

Merged
merged 1 commit into from
Mar 18, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func GetAllocationChanges(ctx context.Context, connectionID, allocationID, clien
cc.ComputeProperties()
// Load connection Obj size from memory
cc.Size = GetConnectionObjSize(connectionID)
cc.Status = InProgressConnection
return cc, nil
}

Expand Down
12 changes: 7 additions & 5 deletions code/go/0chain.net/blobbercore/handler/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func cleanupTempFiles(ctx context.Context) {
then := now.Add(time.Duration(-config.Configuration.OpenConnectionWorkerTolerance) * time.Second)

var openConnectionsToDelete []allocation.AllocationChangeCollector
db.Table((&allocation.AllocationChangeCollector{}).TableName()).Where("updated_at < ? AND status IN (?,?)", then, allocation.NewConnection, allocation.InProgressConnection).Preload("Changes").Find(&openConnectionsToDelete)
db.Table((&allocation.AllocationChangeCollector{}).TableName()).Where("updated_at < ?", then).Preload("Changes").Find(&openConnectionsToDelete)

for i := 0; i < len(openConnectionsToDelete); i++ {
connection := &openConnectionsToDelete[i]
Expand All @@ -93,10 +93,12 @@ func cleanupTempFiles(ctx context.Context) {
nctx := datastore.GetStore().CreateTransaction(ctx)
ndb := datastore.GetStore().GetTransaction(nctx)
var errorOccurred bool
for _, changeProcessor := range connection.AllocationChanges {
if err := changeProcessor.DeleteTempFile(); err != nil {
errorOccurred = true
logging.Logger.Error("AllocationChangeProcessor_DeleteTempFile", zap.Error(err))
if connection.Status == allocation.InProgressConnection || connection.Status == allocation.NewConnection {
for _, changeProcessor := range connection.AllocationChanges {
if err := changeProcessor.DeleteTempFile(); err != nil {
errorOccurred = true
logging.Logger.Error("AllocationChangeProcessor_DeleteTempFile", zap.Error(err))
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions goose/migrations/1742282974_cleanup_connections.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- +goose Up
-- +goose StatementBegin

DELETE FROM allocation_connections WHERE status = 2 OR status = 3;

-- +goose StatementEnd
Loading