Skip to content
Open
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 @@ -96,11 +96,6 @@ func setupMockForFileManagerInit(mock sqlmock.Sqlmock) {
),
)

mock.ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "reference_objects" WHERE`)).
WillReturnRows(
sqlmock.NewRows([]string{"count"}).AddRow(1000),
)

mock.ExpectCommit()
}

Expand Down
26 changes: 4 additions & 22 deletions code/go/0chain.net/blobbercore/filestore/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,17 @@ func (fs *FileStore) initMap() error {
allocsMap := make(map[string]*allocation)

for _, dbAlloc := range dbAllocations {
if dbAlloc.CleanedUp || dbAlloc.Finalized {
continue
}
a := allocation{
allocatedSize: uint64(dbAlloc.BlobberSize),
mu: &sync.Mutex{},
tmpMU: &sync.Mutex{},
}

allocsMap[dbAlloc.ID] = &a
if dbAlloc.StorageVersion == 0 {
err := getStorageDetails(ctx, &a, dbAlloc.ID)
if err != nil {
return err
}
} else {
if dbAlloc.StorageVersion != 0 {
a.filesNumber = uint64(dbAlloc.NumObjects)
}
a.filesSize = uint64(dbAlloc.BlobberSizeUsed)
Expand Down Expand Up @@ -156,22 +154,6 @@ func (ref) TableName() string {
return "reference_objects"
}

func getStorageDetails(ctx context.Context, a *allocation, ID string) error {
db := datastore.GetStore().GetTransaction(ctx)
r := map[string]interface{}{
"allocation_id": ID,
"type": "f",
}
var totalFiles int64
if err := db.Model(&ref{}).Where(r).Count(&totalFiles).Error; err != nil {
return err
}
a.mu.Lock()
defer a.mu.Unlock()
a.filesNumber = uint64(totalFiles)
return nil
}

// UpdateAllocationMetaData only updates if allocation size has changed or new allocation is allocated. Must use allocationID.
// Use of allocation Tx might leak memory. allocation size must be of int64 type otherwise it won't be updated
func (fs *FileStore) UpdateAllocationMetaData(m map[string]interface{}) error {
Expand Down
8 changes: 0 additions & 8 deletions code/go/0chain.net/blobbercore/filestore/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,11 @@ func TestStore(t *testing.T) {
require.NotNil(t, alloc)

require.Equal(t, ip.allocatedSize, alloc.allocatedSize)
require.Equal(t, ip.totalRefs, alloc.filesNumber)
require.Equal(t, ip.usedSize, alloc.filesSize)

}

func setupMockForFileManagerInit(mock sqlmock.Sqlmock, ip initParams) {
aa := sqlmock.AnyArg()
mock.ExpectBegin()

mock.ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "allocations"`)).
Expand All @@ -153,12 +151,6 @@ func setupMockForFileManagerInit(mock sqlmock.Sqlmock, ip initParams) {
),
)

mock.ExpectQuery(regexp.QuoteMeta(`SELECT count(*) FROM "reference_objects" WHERE`)).
WithArgs(aa, aa).
WillReturnRows(
sqlmock.NewRows([]string{"count"}).AddRow(ip.totalRefs),
)

mock.ExpectCommit()

}
Expand Down
Loading