Skip to content

Commit 050f611

Browse files
Merge pull request #1212 from 0chain/sprint-july-4
Sprint july 4
2 parents 3109e16 + cb1f9c2 commit 050f611

File tree

80 files changed

+1280
-942
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1280
-942
lines changed

.github/workflows/build-&-publish-docker-image.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242

4343
- name: Clone blobber
4444
uses: actions/checkout@v3
45+
with:
46+
fetch-depth: 0
4547

4648
- name: Set up Docker Buildx
4749
run: |
@@ -113,7 +115,9 @@ jobs:
113115
go-version: ^1.20 # The Go version to download (if necessary) and use.
114116

115117
- name: Clone blobber
116-
uses: actions/checkout@v1
118+
uses: actions/checkout@v3
119+
with:
120+
fetch-depth: 0
117121

118122
- name: Set up Docker Buildx
119123
run: |
@@ -243,4 +247,4 @@ jobs:
243247
repository: ${{ github.repository }}
244248
status_name: "0Chain System Tests"
245249
target_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
246-
github_token: ${{ github.token }}
250+
github_token: ${{ github.token }}

.github/workflows/tests.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ concurrency:
66

77
on:
88
push:
9-
branches:
10-
- master
11-
- staging
12-
tags:
9+
branches: [ master, staging, sprint* ]
1310
pull_request:
1411

1512
jobs:

code/go/0chain.net/blobber/config.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,30 @@ func setupConfig(configDir string, deploymentMode int) {
105105
func reloadConfig() error {
106106
fmt.Print("> reload config")
107107

108-
db := datastore.GetStore().GetDB()
108+
return datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
109+
s, ok := config.Get(ctx, datastore.GetStore().GetDB())
110+
if ok {
111+
if err := s.CopyTo(&config.Configuration); err != nil {
112+
return err
113+
}
114+
fmt.Print(" [OK]\n")
115+
return nil
116+
}
117+
118+
config.Configuration.Capacity = viper.GetInt64("capacity")
119+
120+
config.Configuration.MinLockDemand = viper.GetFloat64("min_lock_demand")
121+
config.Configuration.NumDelegates = viper.GetInt("num_delegates")
122+
config.Configuration.ReadPrice = viper.GetFloat64("read_price")
123+
config.Configuration.ServiceCharge = viper.GetFloat64("service_charge")
124+
config.Configuration.WritePrice = viper.GetFloat64("write_price")
109125

110-
s, ok := config.Get(context.TODO(), db)
111-
if ok {
112-
if err := s.CopyTo(&config.Configuration); err != nil {
126+
if err := config.Update(ctx, datastore.GetStore().GetDB()); err != nil {
113127
return err
114128
}
129+
115130
fmt.Print(" [OK]\n")
116131
return nil
117-
}
118132

119-
config.Configuration.Capacity = viper.GetInt64("capacity")
120-
121-
config.Configuration.MinLockDemand = viper.GetFloat64("min_lock_demand")
122-
config.Configuration.NumDelegates = viper.GetInt("num_delegates")
123-
config.Configuration.ReadPrice = viper.GetFloat64("read_price")
124-
config.Configuration.ServiceCharge = viper.GetFloat64("service_charge")
125-
config.Configuration.WritePrice = viper.GetFloat64("write_price")
126-
127-
if err := config.Update(context.TODO(), db); err != nil {
128-
return err
129-
}
130-
131-
fmt.Print(" [OK]\n")
132-
return nil
133+
})
133134
}

code/go/0chain.net/blobber/http.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"net/http"
6+
"net/http/pprof"
67
"runtime"
78
"strconv"
89
"sync"
@@ -53,19 +54,38 @@ func startServer(wg *sync.WaitGroup, r *mux.Router, mode string, port int, isTls
5354
//address := publicIP + ":" + portString
5455
address := ":" + strconv.Itoa(port)
5556
var server *http.Server
57+
var profServer *http.Server
5658

5759
if config.Development() {
5860
// No WriteTimeout setup to enable pprof
5961
server = &http.Server{
6062
Addr: address,
6163
ReadHeaderTimeout: 30 * time.Second,
64+
ReadTimeout: 30 * time.Second,
65+
WriteTimeout: 30 * time.Second,
66+
IdleTimeout: 30 * time.Second,
6267
MaxHeaderBytes: 1 << 20,
6368
Handler: r,
6469
}
70+
71+
pprofMux := http.NewServeMux()
72+
profServer = &http.Server{
73+
Addr: fmt.Sprintf(":%d", port-1000),
74+
ReadTimeout: 30 * time.Second,
75+
MaxHeaderBytes: 1 << 20,
76+
Handler: pprofMux,
77+
}
78+
initProfHandlers(pprofMux)
79+
go func() {
80+
err2 := profServer.ListenAndServe()
81+
logging.Logger.Error("Http server shut down", zap.Error(err2))
82+
}()
83+
6584
} else {
6685
server = &http.Server{
6786
Addr: address,
6887
ReadHeaderTimeout: 30 * time.Second,
88+
ReadTimeout: 30 * time.Second,
6989
WriteTimeout: 30 * time.Second,
7090
IdleTimeout: 30 * time.Second,
7191
MaxHeaderBytes: 1 << 20,
@@ -91,3 +111,11 @@ func initHandlers(r *mux.Router) {
91111
handler.SetupSwagger()
92112
common.SetAdminCredentials()
93113
}
114+
115+
func initProfHandlers(mux *http.ServeMux) {
116+
mux.HandleFunc("/debug/pprof/", handler.RateLimitByGeneralRL(pprof.Index))
117+
mux.HandleFunc("/debug/pprof/cmdline", handler.RateLimitByGeneralRL(pprof.Cmdline))
118+
mux.HandleFunc("/debug/pprof/profile", handler.RateLimitByGeneralRL(pprof.Profile))
119+
mux.HandleFunc("/debug/pprof/symbol", handler.RateLimitByGeneralRL(pprof.Symbol))
120+
mux.HandleFunc("/debug/pprof/trace", handler.RateLimitByGeneralRL(pprof.Trace))
121+
}

code/go/0chain.net/blobber/worker.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/handler"
1212
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/readmarker"
1313
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/writemarker"
14-
"github.com/0chain/blobber/code/go/0chain.net/core/common"
1514
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
1615

1716
"go.uber.org/zap"
@@ -30,13 +29,15 @@ func setupWorkers(ctx context.Context) {
3029
// startRefreshSettings sync settings from blockchain
3130
func startRefreshSettings(ctx context.Context) {
3231
const REPEAT_DELAY = 60 * 3 // 3 minutes
33-
var err error
3432
for {
3533
select {
3634
case <-ctx.Done():
3735
return
3836
case <-time.After(REPEAT_DELAY * time.Second):
39-
_, err = config.ReloadFromChain(common.GetRootContext(), datastore.GetStore().GetDB())
37+
err := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
38+
_, e := config.ReloadFromChain(ctx, datastore.GetStore().GetDB())
39+
return e
40+
})
4041
if err != nil {
4142
logging.Logger.Warn("failed to refresh blobber settings from chain", zap.Error(err))
4243
continue

0 commit comments

Comments
 (0)