Skip to content

Commit d0e41b5

Browse files
authored
enhance: support syncpeers by service and optimize the merge logic (#3637)
* enhance: support syncpeers by service and optimize the merge logic Signed-off-by: cormick <cormick1080@gmail.com>
1 parent c220a60 commit d0e41b5

File tree

16 files changed

+543
-112
lines changed

16 files changed

+543
-112
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
- name: Golangci lint
2424
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8
2525
with:
26-
version: v1.54
27-
args: --verbose
26+
version: v1.62
27+
args: --verbose --timeout=10m
2828

2929
- name: Markdown lint
3030
uses: docker://avtodev/markdown-lint:v1@sha256:6aeedc2f49138ce7a1cd0adffc1b1c0321b841dc2102408967d9301c031949ee

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ linters:
2424
enable:
2525
- gci
2626
- gofmt
27-
- golint
2827
- misspell
2928
- govet
3029
- goconst
31-
- deadcode
3230
- gocyclo
3331
- staticcheck
3432
- errcheck

manager/config/config.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ type SyncPeersConfig struct {
338338

339339
// Timeout is the timeout for syncing peers information from the single scheduler.
340340
Timeout time.Duration `yaml:"timeout" mapstructure:"timeout"`
341+
342+
// BatchSize is the batch size when operating gorm.
343+
BatchSize int `yaml:"batchSize" mapstructure:"batchSize"`
341344
}
342345

343346
type PreheatTLSClientConfig struct {
@@ -447,8 +450,9 @@ func New() *Config {
447450
TLS: PreheatTLSClientConfig{},
448451
},
449452
SyncPeers: SyncPeersConfig{
450-
Interval: DefaultJobSyncPeersInterval,
451-
Timeout: DefaultJobSyncPeersTimeout,
453+
Interval: DefaultJobSyncPeersInterval,
454+
Timeout: DefaultJobSyncPeersTimeout,
455+
BatchSize: DefaultJobSyncPeersBatchSize,
452456
},
453457
},
454458
ObjectStorage: ObjectStorageConfig{

manager/config/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ const (
107107

108108
// DefaultClusterJobRateLimit is default rate limit(requests per second) for job Open API by cluster.
109109
DefaultClusterJobRateLimit = 10
110+
111+
// DefaultJobSyncPeersBatchSize is the default batch size for syncing all peers information from the scheduler.
112+
DefaultJobSyncPeersBatchSize = 500
110113
)
111114

112115
const (

manager/handlers/job.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ func (h *Handlers) CreateJob(ctx *gin.Context) {
6262
return
6363
}
6464

65+
ctx.JSON(http.StatusOK, job)
66+
case job.SyncPeersJob:
67+
var json types.CreateSyncPeersJobRequest
68+
if err := ctx.ShouldBindBodyWith(&json, binding.JSON); err != nil {
69+
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
70+
return
71+
}
72+
73+
job, err := h.service.CreateSyncPeersJob(ctx.Request.Context(), json)
74+
if err != nil {
75+
ctx.Error(err) // nolint: errcheck
76+
return
77+
}
78+
6579
ctx.JSON(http.StatusOK, job)
6680
case job.GetTaskJob:
6781
var json types.CreateGetTaskJobRequest

manager/job/mocks/sync_peers_mock.go

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)