Skip to content

Commit 55fd1bf

Browse files
committed
fix state for v1 allocation
1 parent c3197e3 commit 55fd1bf

File tree

1 file changed

+4
-22
lines changed
  • code/go/0chain.net/blobbercore/filestore

1 file changed

+4
-22
lines changed

code/go/0chain.net/blobbercore/filestore/state.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,17 @@ func (fs *FileStore) initMap() error {
6565
allocsMap := make(map[string]*allocation)
6666

6767
for _, dbAlloc := range dbAllocations {
68+
if dbAlloc.CleanedUp || dbAlloc.Finalized {
69+
continue
70+
}
6871
a := allocation{
6972
allocatedSize: uint64(dbAlloc.BlobberSize),
7073
mu: &sync.Mutex{},
7174
tmpMU: &sync.Mutex{},
7275
}
7376

7477
allocsMap[dbAlloc.ID] = &a
75-
if dbAlloc.StorageVersion == 0 {
76-
err := getStorageDetails(ctx, &a, dbAlloc.ID)
77-
if err != nil {
78-
return err
79-
}
80-
} else {
78+
if dbAlloc.StorageVersion != 0 {
8179
a.filesNumber = uint64(dbAlloc.NumObjects)
8280
}
8381
a.filesSize = uint64(dbAlloc.BlobberSizeUsed)
@@ -156,22 +154,6 @@ func (ref) TableName() string {
156154
return "reference_objects"
157155
}
158156

159-
func getStorageDetails(ctx context.Context, a *allocation, ID string) error {
160-
db := datastore.GetStore().GetTransaction(ctx)
161-
r := map[string]interface{}{
162-
"allocation_id": ID,
163-
"type": "f",
164-
}
165-
var totalFiles int64
166-
if err := db.Model(&ref{}).Where(r).Count(&totalFiles).Error; err != nil {
167-
return err
168-
}
169-
a.mu.Lock()
170-
defer a.mu.Unlock()
171-
a.filesNumber = uint64(totalFiles)
172-
return nil
173-
}
174-
175157
// UpdateAllocationMetaData only updates if allocation size has changed or new allocation is allocated. Must use allocationID.
176158
// Use of allocation Tx might leak memory. allocation size must be of int64 type otherwise it won't be updated
177159
func (fs *FileStore) UpdateAllocationMetaData(m map[string]interface{}) error {

0 commit comments

Comments
 (0)