Skip to content

Commit 99a5da3

Browse files
authored
Merge pull request #1443 from 0chain/fix/alloc-size
update blobber size and add scheme to validator url if not present
2 parents e321878 + 824bee7 commit 99a5da3

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

code/go/0chain.net/blobbercore/allocation/protocol.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,22 @@ func FetchAllocationFromEventsDB(ctx context.Context, allocationID string, alloc
7777

7878
isExist = a.ID != ""
7979

80-
if !isExist {
81-
foundBlobber := false
82-
for _, blobberConnection := range sa.BlobberDetails {
83-
if blobberConnection.BlobberID != node.Self.ID {
84-
continue
85-
}
86-
foundBlobber = true
80+
foundBlobber := false
81+
for _, blobberConnection := range sa.BlobberDetails {
82+
if blobberConnection.BlobberID != node.Self.ID {
83+
continue
84+
}
85+
foundBlobber = true
86+
a.BlobberSize = int64(math.Ceil(float64(sa.Size) / float64(sa.DataShards)))
87+
if !isExist {
8788
a.AllocationRoot = ""
88-
a.BlobberSize = int64(math.Ceil(float64(sa.Size) / float64(sa.DataShards)))
8989
a.BlobberSizeUsed = 0
90-
break
91-
}
92-
if !foundBlobber {
93-
return nil, common.NewError("invalid_blobber",
94-
"Blobber is not part of the open connection transaction")
9590
}
91+
break
92+
}
93+
if !foundBlobber {
94+
return nil, common.NewError("invalid_blobber",
95+
"Blobber is not part of the open connection transaction")
9696
}
9797

9898
// set/update fields
@@ -151,6 +151,7 @@ func FetchAllocationFromEventsDB(ctx context.Context, allocationID string, alloc
151151
"time_unit": a.TimeUnit,
152152
"file_options": a.FileOptions,
153153
"start_time": a.StartTime,
154+
"blobber_size": a.BlobberSize,
154155
}
155156

156157
updateOption := func(alloc *Allocation) {
@@ -164,6 +165,7 @@ func FetchAllocationFromEventsDB(ctx context.Context, allocationID string, alloc
164165
alloc.TimeUnit = a.TimeUnit
165166
alloc.FileOptions = a.FileOptions
166167
alloc.StartTime = a.StartTime
168+
alloc.BlobberSize = a.BlobberSize
167169
}
168170
err = Repo.UpdateAllocation(ctx, a, updateMap, updateOption)
169171
}

code/go/0chain.net/blobbercore/handler/file_command_delete.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ func (cmd *DeleteFileCommand) IsValidated(ctx context.Context, req *http.Request
6363

6464
// UpdateChange add DeleteFileChange in db
6565
func (cmd *DeleteFileCommand) UpdateChange(ctx context.Context, connectionObj *allocation.AllocationChangeCollector) error {
66-
connectionObj.AddChange(cmd.allocationChange, cmd.changeProcessor)
67-
68-
return connectionObj.Save(ctx)
66+
err := cmd.AddChange(ctx)
67+
if err == gorm.ErrDuplicatedKey {
68+
return nil
69+
}
70+
return err
6971
}
7072

7173
func (cmd *DeleteFileCommand) AddChange(ctx context.Context) error {

code/go/0chain.net/core/util/http.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"io"
77
"net/http"
8+
"net/url"
89
"sync"
910
"time"
1011

@@ -41,19 +42,26 @@ func SendMultiPostRequest(urls []string, data []byte) {
4142
wg.Wait()
4243
}
4344

44-
func SendPostRequest(url string, data []byte, wg *sync.WaitGroup) (body []byte, err error) {
45+
func SendPostRequest(postURL string, data []byte, wg *sync.WaitGroup) (body []byte, err error) {
4546
if wg != nil {
4647
defer wg.Done()
4748
}
4849
var resp *http.Response
50+
u, err := url.Parse(postURL)
51+
if err != nil {
52+
return nil, err
53+
}
54+
if u.Scheme == "" {
55+
u.Scheme = "https"
56+
}
4957
for i := 0; i < MAX_RETRIES; i++ {
5058
var (
5159
req *http.Request
5260
ctx context.Context
5361
cncl context.CancelFunc
5462
)
5563

56-
req, ctx, cncl, err = NewHTTPRequest(http.MethodPost, url, data)
64+
req, ctx, cncl, err = NewHTTPRequest(http.MethodPost, u.String(), data)
5765
defer cncl()
5866

5967
resp, err = http.DefaultClient.Do(req.WithContext(ctx))
@@ -71,7 +79,7 @@ func SendPostRequest(url string, data []byte, wg *sync.WaitGroup) (body []byte,
7179
time.Sleep(SLEEP_BETWEEN_RETRIES * time.Second)
7280
}
7381
if resp == nil || err != nil {
74-
Logger.Error("Failed after multiple retries", zap.Any("url", url), zap.Int("retried", MAX_RETRIES), zap.Int("post_data_len", len(data)), zap.Error(err))
82+
Logger.Error("Failed after multiple retries", zap.Any("url", u.String()), zap.Int("retried", MAX_RETRIES), zap.Int("post_data_len", len(data)), zap.Error(err))
7583
return nil, err
7684
}
7785
if resp.Body == nil {

0 commit comments

Comments
 (0)