From 22b234e4c513916a0fafd8b7a8d5cdc3f7d407ef Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Tue, 18 Mar 2025 13:10:52 +0530 Subject: [PATCH] delete committed connections --- .../blobbercore/allocation/allocationchange.go | 1 - code/go/0chain.net/blobbercore/handler/worker.go | 12 +++++++----- goose/migrations/1742282974_cleanup_connections.sql | 6 ++++++ 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 goose/migrations/1742282974_cleanup_connections.sql diff --git a/code/go/0chain.net/blobbercore/allocation/allocationchange.go b/code/go/0chain.net/blobbercore/allocation/allocationchange.go index 3fcb7b10b..59d355729 100644 --- a/code/go/0chain.net/blobbercore/allocation/allocationchange.go +++ b/code/go/0chain.net/blobbercore/allocation/allocationchange.go @@ -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 } diff --git a/code/go/0chain.net/blobbercore/handler/worker.go b/code/go/0chain.net/blobbercore/handler/worker.go index eafbab7da..04f495804 100644 --- a/code/go/0chain.net/blobbercore/handler/worker.go +++ b/code/go/0chain.net/blobbercore/handler/worker.go @@ -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] @@ -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)) + } } } diff --git a/goose/migrations/1742282974_cleanup_connections.sql b/goose/migrations/1742282974_cleanup_connections.sql new file mode 100644 index 000000000..07ce8ed39 --- /dev/null +++ b/goose/migrations/1742282974_cleanup_connections.sql @@ -0,0 +1,6 @@ +-- +goose Up +-- +goose StatementBegin + +DELETE FROM allocation_connections WHERE status = 2 OR status = 3; + +-- +goose StatementEnd \ No newline at end of file