Skip to content
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

Increase timeout and remove file size query #1508

Merged
merged 4 commits into from
Nov 14, 2024
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 @@ -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
Loading