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() } 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..69e7664ea 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 } 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() }