From 704f27a2bd0c7f7e4a7fd2435322209e56741d04 Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Thu, 14 Nov 2024 22:32:02 +0530 Subject: [PATCH 1/4] increase timeout and remove file size query --- .../blobbercore/datastore/postgres.go | 2 +- .../0chain.net/blobbercore/filestore/state.go | 28 ++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/code/go/0chain.net/blobbercore/datastore/postgres.go b/code/go/0chain.net/blobbercore/datastore/postgres.go index d30e549c7..cde3e919f 100644 --- a/code/go/0chain.net/blobbercore/datastore/postgres.go +++ b/code/go/0chain.net/blobbercore/datastore/postgres.go @@ -100,7 +100,7 @@ func (store *postgresStore) GetTransaction(ctx context.Context) *EnhancedDB { } func (store *postgresStore) WithNewTransaction(f func(ctx context.Context) error, opts ...*sql.TxOptions) error { - timeoutctx, cancel := context.WithTimeout(context.TODO(), 45*time.Second) + timeoutctx, cancel := context.WithTimeout(context.TODO(), 60*time.Second) defer cancel() ctx := store.CreateTransaction(timeoutctx, opts...) tx := store.GetTransaction(ctx) diff --git a/code/go/0chain.net/blobbercore/filestore/state.go b/code/go/0chain.net/blobbercore/filestore/state.go index b098a34c8..a74b7e8d0 100644 --- a/code/go/0chain.net/blobbercore/filestore/state.go +++ b/code/go/0chain.net/blobbercore/filestore/state.go @@ -72,12 +72,15 @@ func (fs *FileStore) initMap() error { } allocsMap[dbAlloc.ID] = &a - - err := getStorageDetails(ctx, &a, dbAlloc.ID) - - if err != nil { - return err + if dbAlloc.StorageVersion != 0 { + err := getStorageDetails(ctx, &a, dbAlloc.ID) + if err != nil { + return err + } + } else { + a.filesNumber = uint64(dbAlloc.NumObjects) } + a.filesSize = uint64(dbAlloc.BlobberSizeUsed) limitCh <- struct{}{} wg.Add(1) @@ -133,8 +136,10 @@ type dbAllocation struct { TimeUnit time.Duration `gorm:"column:time_unit"` // Ending and cleaning - CleanedUp bool `gorm:"column:cleaned_up"` - Finalized bool `gorm:"column:finalized"` + CleanedUp bool `gorm:"column:cleaned_up"` + Finalized bool `gorm:"column:finalized"` + StorageVersion uint8 `gorm:"column:storage_version"` + NumObjects int32 `gorm:"column:num_objects"` } func (dbAllocation) TableName() string { @@ -161,18 +166,9 @@ func getStorageDetails(ctx context.Context, a *allocation, ID string) error { if err := db.Model(&ref{}).Where(r).Count(&totalFiles).Error; err != nil { return err } - - var totalFileSize *int64 - if err := db.Model(&ref{}).Select("sum(size) as file_size").Where(r).Scan(&totalFileSize).Error; err != nil { - return err - } - a.mu.Lock() defer a.mu.Unlock() a.filesNumber = uint64(totalFiles) - if totalFileSize != nil { - a.filesSize = uint64(*totalFileSize) - } return nil } From 2906c477dbeaac5729831558ac55386fa997459b Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Thu, 14 Nov 2024 22:37:15 +0530 Subject: [PATCH 2/4] fix ut --- code/go/0chain.net/blobbercore/filestore/store_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/code/go/0chain.net/blobbercore/filestore/store_test.go b/code/go/0chain.net/blobbercore/filestore/store_test.go index 55a7f4adb..235b8ca22 100644 --- a/code/go/0chain.net/blobbercore/filestore/store_test.go +++ b/code/go/0chain.net/blobbercore/filestore/store_test.go @@ -159,11 +159,6 @@ func setupMockForFileManagerInit(mock sqlmock.Sqlmock, ip initParams) { sqlmock.NewRows([]string{"count"}).AddRow(ip.totalRefs), ) - mock.ExpectQuery(regexp.QuoteMeta(`SELECT sum(size) as file_size FROM "reference_objects" WHERE`)). - WillReturnRows( - sqlmock.NewRows([]string{"file_size"}).AddRow(ip.usedSize), - ) - mock.ExpectCommit() } From bb6acfb933ca09e56fa8c06e3b23d0efd8d7510f Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Thu, 14 Nov 2024 22:45:29 +0530 Subject: [PATCH 3/4] fix check --- code/go/0chain.net/blobbercore/filestore/state.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/go/0chain.net/blobbercore/filestore/state.go b/code/go/0chain.net/blobbercore/filestore/state.go index a74b7e8d0..69e7664ea 100644 --- a/code/go/0chain.net/blobbercore/filestore/state.go +++ b/code/go/0chain.net/blobbercore/filestore/state.go @@ -72,7 +72,7 @@ func (fs *FileStore) initMap() error { } allocsMap[dbAlloc.ID] = &a - if dbAlloc.StorageVersion != 0 { + if dbAlloc.StorageVersion == 0 { err := getStorageDetails(ctx, &a, dbAlloc.ID) if err != nil { return err From 7abc794689682f46e22963762602b6e86d016e35 Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Thu, 14 Nov 2024 23:05:58 +0530 Subject: [PATCH 4/4] fix renamechange test --- .../blobbercore/allocation/renamefilechange_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/code/go/0chain.net/blobbercore/allocation/renamefilechange_test.go b/code/go/0chain.net/blobbercore/allocation/renamefilechange_test.go index de2de2140..27edd9f20 100644 --- a/code/go/0chain.net/blobbercore/allocation/renamefilechange_test.go +++ b/code/go/0chain.net/blobbercore/allocation/renamefilechange_test.go @@ -105,10 +105,6 @@ func setupMockForFileManagerInit(mock sqlmock.Sqlmock) { sqlmock.NewRows([]string{"count"}).AddRow(1000), ) - mock.ExpectQuery(regexp.QuoteMeta(`SELECT sum(size) as file_size FROM "reference_objects" WHERE`)). - WillReturnRows( - sqlmock.NewRows([]string{"file_size"}).AddRow(6553600), - ) mock.ExpectCommit() }