Skip to content

Commit

Permalink
Merge pull request #1508 from 0chain/hotfix/init-map
Browse files Browse the repository at this point in the history
Increase timeout and remove file size query
  • Loading branch information
dabasov authored Nov 14, 2024
2 parents 0af5d0c + 7abc794 commit 0af6dbd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion code/go/0chain.net/blobbercore/datastore/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 12 additions & 16 deletions code/go/0chain.net/blobbercore/filestore/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
5 changes: 0 additions & 5 deletions code/go/0chain.net/blobbercore/filestore/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

}
Expand Down

0 comments on commit 0af6dbd

Please sign in to comment.