Skip to content

Commit 5c8b456

Browse files
committed
Some fixes and improvements
1 parent 3e61b1d commit 5c8b456

38 files changed

Lines changed: 181 additions & 114 deletions

cmd/batch-handlers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,22 +1771,22 @@ func (a adminAPIHandlers) StartBatchJob(w http.ResponseWriter, r *http.Request)
17711771
// Fill with default values
17721772
if job.Replicate != nil {
17731773
if job.Replicate.Source.Snowball.Disable == nil {
1774-
job.Replicate.Source.Snowball.Disable = ptr(false)
1774+
job.Replicate.Source.Snowball.Disable = new(false)
17751775
}
17761776
if job.Replicate.Source.Snowball.Batch == nil {
1777-
job.Replicate.Source.Snowball.Batch = ptr(100)
1777+
job.Replicate.Source.Snowball.Batch = new(100)
17781778
}
17791779
if job.Replicate.Source.Snowball.InMemory == nil {
1780-
job.Replicate.Source.Snowball.InMemory = ptr(true)
1780+
job.Replicate.Source.Snowball.InMemory = new(true)
17811781
}
17821782
if job.Replicate.Source.Snowball.Compress == nil {
1783-
job.Replicate.Source.Snowball.Compress = ptr(false)
1783+
job.Replicate.Source.Snowball.Compress = new(false)
17841784
}
17851785
if job.Replicate.Source.Snowball.SmallerThan == nil {
1786-
job.Replicate.Source.Snowball.SmallerThan = ptr("5MiB")
1786+
job.Replicate.Source.Snowball.SmallerThan = new("5MiB")
17871787
}
17881788
if job.Replicate.Source.Snowball.SkipErrs == nil {
1789-
job.Replicate.Source.Snowball.SkipErrs = ptr(true)
1789+
job.Replicate.Source.Snowball.SkipErrs = new(true)
17901790
}
17911791
}
17921792

cmd/batchjobmetric_string.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/data-usage-cache.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,12 @@ func (d *dataUsageCache) forceCompact(limit int) {
635635
// StringAll returns a detailed string representation of all entries in the cache.
636636
func (d *dataUsageCache) StringAll() string {
637637
// Remove bloom filter from print.
638-
s := fmt.Sprintf("info:%+v\n", d.Info)
638+
var s strings.Builder
639+
s.WriteString(fmt.Sprintf("info:%+v\n", d.Info))
639640
for k, v := range d.Cache {
640-
s += fmt.Sprintf("\t%v: %+v\n", k, v)
641+
s.WriteString(fmt.Sprintf("\t%v: %+v\n", k, v))
641642
}
642-
return strings.TrimSpace(s)
643+
return strings.TrimSpace(s.String())
643644
}
644645

645646
// String returns a human readable representation of the string.

cmd/decommetric_string.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dynamic-timeouts.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,10 @@ func (dt *dynamicTimeout) adjust(entries [dynamicTimeoutLogSize]time.Duration) {
129129

130130
if failPct > dynamicTimeoutIncreaseThresholdPct {
131131
// We are hitting the timeout too often, so increase the timeout by 25%
132-
timeout := min(
132+
timeout := max(
133133
// Set upper cap.
134-
atomic.LoadInt64(&dt.timeout)*125/100, int64(maxDynamicTimeout))
135-
// Safety, shouldn't happen
136-
if timeout < dt.minimum {
137-
timeout = dt.minimum
138-
}
134+
min(atomic.LoadInt64(&dt.timeout)*125/100, int64(maxDynamicTimeout)),
135+
dt.minimum)
139136
atomic.StoreInt64(&dt.timeout, timeout)
140137
} else if failPct < dynamicTimeoutDecreaseThresholdPct {
141138
// We are hitting the timeout relatively few times,

cmd/erasure-common.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@ import (
2626

2727
func (er erasureObjects) getOnlineDisks() (newDisks []StorageAPI) {
2828
disks := er.getDisks()
29+
2930
var wg sync.WaitGroup
3031
var mu sync.Mutex
32+
newDisks = make([]StorageAPI, 0, len(disks))
33+
3134
r := rand.New(rand.NewSource(time.Now().UnixNano()))
35+
3236
for _, i := range r.Perm(len(disks)) {
33-
wg.Add(1)
34-
go func() {
35-
defer wg.Done()
36-
if disks[i] == nil {
37-
return
38-
}
39-
di, err := disks[i].DiskInfo(context.Background(), DiskInfoOptions{})
37+
disk := disks[i] // avoids repeated indexing
38+
if disk == nil {
39+
// avoids spawning goroutines that immediately return
40+
continue
41+
}
42+
wg.Go(func() {
43+
di, err := disk.DiskInfo(context.Background(), DiskInfoOptions{})
4044
if err != nil || di.Healing {
4145
// - Do not consume disks which are not reachable
4246
// unformatted or simply not accessible for some reason.
@@ -48,10 +52,11 @@ func (er erasureObjects) getOnlineDisks() (newDisks []StorageAPI) {
4852
}
4953

5054
mu.Lock()
51-
newDisks = append(newDisks, disks[i])
55+
newDisks = append(newDisks, disk)
5256
mu.Unlock()
53-
}()
57+
})
5458
}
59+
5560
wg.Wait()
5661
return newDisks
5762
}

cmd/erasure.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,24 +285,23 @@ func (er erasureObjects) getOnlineDisksWithHealingAndInfo(inclHealing bool) (new
285285
infos := make([]DiskInfo, len(disks))
286286
r := rand.New(rand.NewSource(time.Now().UnixNano()))
287287
for _, i := range r.Perm(len(disks)) {
288-
wg.Add(1)
289-
go func() {
290-
defer wg.Done()
288+
disk := disks[i]
289+
if disk == nil {
290+
infos[i].Error = errDiskNotFound.Error()
291+
continue
292+
}
291293

292-
disk := disks[i]
293-
if disk == nil {
294-
infos[i].Error = errDiskNotFound.Error()
295-
return
296-
}
294+
i, disk := i, disk
297295

296+
wg.Go(func() {
298297
di, err := disk.DiskInfo(context.Background(), DiskInfoOptions{})
299298
infos[i] = di
300299
if err != nil {
301300
// - Do not consume disks which are not reachable
302301
// unformatted or simply not accessible for some reason.
303302
infos[i].Error = err.Error()
304303
}
305-
}()
304+
})
306305
}
307306
wg.Wait()
308307

cmd/healingmetric_string.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/iam-object-store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ func (iamOS *IAMObjectStore) loadAllFromObjStore(ctx context.Context, cache *iam
576576
if took := time.Since(listStartTime); took > maxIAMLoadOpTime {
577577
var s strings.Builder
578578
for k, v := range listedConfigItems {
579-
fmt.Fprintf(&s, " %s: %d items\n", k, len(v))
579+
s.WriteString(fmt.Sprintf(" %s: %d items\n", k, len(v)))
580580
}
581581
logger.Info("listAllIAMConfigItems took %.2fs with contents:\n%s", took.Seconds(), s.String())
582582
}

cmd/lceventsrc_string.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)