-
Notifications
You must be signed in to change notification settings - Fork 38
/
task_options.go
364 lines (357 loc) · 12.4 KB
/
task_options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
package gfspapp
import (
coretask "github.com/bnb-chain/greenfield-storage-provider/core/task"
"github.com/bnb-chain/greenfield-storage-provider/util"
)
const (
// MiB defines the MB size
MiB = 1024 * 1024
// MinSpeed defines the min speed for data transfer
MinSpeed = 10 * MiB
// NotUseTimeout defines the default task timeout.
NotUseTimeout int64 = 0
// MinUploadTime defines the min timeout to upload object.
MinUploadTime int64 = 2
// MaxUploadTime defines the max timeout to upload object.
MaxUploadTime int64 = 300
// MinReplicateTime defines the min timeout to replicate object.
MinReplicateTime int64 = 90
// MaxReplicateTime defines the max timeout to replicate object.
MaxReplicateTime int64 = 500
// MinReceiveTime defines the min timeout to confirm the received piece whether is sealed on greenfield.
MinReceiveTime int64 = 90
// MaxReceiveTime defines the max timeout to confirm the received piece whether is sealed on greenfield.
MaxReceiveTime int64 = 300
// MinSealObjectTime defines the min timeout to seal object to greenfield.
MinSealObjectTime int64 = 90
// MaxSealObjectTime defines the max timeout to seal object to greenfield.
MaxSealObjectTime int64 = 300
// MinDownloadTime defines the min timeout to download object.
MinDownloadTime int64 = 2
// MaxDownloadTime defines the max timeout to download object.
MaxDownloadTime int64 = 300
// MinGCObjectTime defines the min timeout to gc object.
MinGCObjectTime int64 = 300
// MaxGCObjectTime defines the max timeout to gc object.
MaxGCObjectTime int64 = 600
// MinGCZombieTime defines the min timeout to gc zombie piece.
MinGCZombieTime int64 = 300
// MaxGCZombieTime defines the max timeout to gc zombie piece.
MaxGCZombieTime int64 = 600
// MinGCMetaTime defines the min timeout to gc meta.
MinGCMetaTime int64 = 300
// MaxGCMetaTime defines the max timeout to gc meta.
MaxGCMetaTime int64 = 600
// MinRecoveryTime defines the min timeout to recovery object.
MinRecoveryTime int64 = 10
// MaxRecoveryTime defines the max timeout to replicate object.
MaxRecoveryTime int64 = 50
// MinMigrateGVGTime defines the min timeout to migrate gvg.
MinMigrateGVGTime int64 = 1800 // 0.5 hour
// MaxMigrateGVGTime defines the max timeout to migrate gvg.
MaxMigrateGVGTime int64 = 3600 // 1 hour
// MinGCBucketMigrationTime defines the min timeout to gc bucket migration.
MinGCBucketMigrationTime int64 = 1800 // 0.5 hour
// MaxGCBucketMigrationTime defines the max timeout to gc bucket migration.
MaxGCBucketMigrationTime int64 = 3600 // 1 hour
// MinGCStaleVersionObjectTime defines the min timeout to gc stale version object.
MinGCStaleVersionObjectTime int64 = 300
// MaxGCStaleVersionObjectTime defines the max timeout to gc stale version object.
MaxGCStaleVersionObjectTime int64 = 600
// NotUseRetry defines the default task max retry.
NotUseRetry int64 = 0
// MinReplicateRetry defines the min retry number to replicate object.
MinReplicateRetry = 3
// MaxReplicateRetry defines the max retry number to replicate object.
MaxReplicateRetry = 6
// MinReceiveConfirmRetry defines the min retry number to confirm received piece is sealed on greenfield.
MinReceiveConfirmRetry = 1
// MaxReceiveConfirmRetry defines the max retry number to confirm received piece is sealed on greenfield.
MaxReceiveConfirmRetry = 3
// MinSealObjectRetry defines the min retry number to seal object.
MinSealObjectRetry = 3
// MaxSealObjectRetry defines the max retry number to seal object.
MaxSealObjectRetry = 10
// MinGCObjectRetry defines the min retry number to gc object.
MinGCObjectRetry = 3
// MaxGCObjectRetry defines the min retry number to gc object.
MaxGCObjectRetry = 5
// MinRecoveryRetry defines the min retry number to recovery piece.
MinRecoveryRetry = 2
// MaxRecoveryRetry defines the max retry number to recovery piece.
MaxRecoveryRetry = 3
// MinMigrateGVGRetry defines the min retry number to migrate gvg.
MinMigrateGVGRetry = 2
// MaxMigrateGVGRetry defines the max retry number to migrate gvg.
MaxMigrateGVGRetry = 3
// MinGCBucketMigrationRetry defines the min retry number to gc bucket migration.
MinGCBucketMigrationRetry = 3
// MaxGCBucketMigrationRetry defines the max retry number to gc bucket migration.
MaxGCBucketMigrationRetry = 5
)
// TaskTimeout returns the task timeout by task type and some task need payload size
// to compute, example: upload, download, etc.
func (g *GfSpBaseApp) TaskTimeout(task coretask.Task, size uint64) int64 {
switch task.Type() {
case coretask.TypeTaskCreateBucketApproval:
return NotUseTimeout
case coretask.TypeTaskCreateObjectApproval:
return NotUseTimeout
case coretask.TypeTaskReplicatePieceApproval:
return NotUseTimeout
case coretask.TypeTaskUpload:
timeout := size / uint64(g.uploadSpeed+1) / (MinSpeed)
if timeout < uint64(MinUploadTime) {
return MinUploadTime
}
if timeout > uint64(MaxUploadTime) {
return MaxUploadTime
}
return util.Uint64ToInt64(timeout)
case coretask.TypeTaskReplicatePiece:
timeout := size / (uint64(g.replicateSpeed) + 1) / (MinSpeed)
if timeout < uint64(MinReplicateTime) {
return MinReplicateTime
}
if timeout > uint64(MaxReplicateTime) {
return MaxReplicateTime
}
return util.Uint64ToInt64(timeout)
case coretask.TypeTaskReceivePiece:
timeout := size / (uint64(g.replicateSpeed) + 1) / (MinSpeed)
if timeout < uint64(MinReceiveTime) {
return MinReceiveTime
}
if timeout > uint64(MaxReceiveTime) {
return MaxReceiveTime
}
return util.Uint64ToInt64(timeout)
case coretask.TypeTaskSealObject:
if g.sealObjectTimeout < MinSealObjectTime {
return MinSealObjectTime
}
if g.sealObjectTimeout > MaxSealObjectTime {
return MaxSealObjectTime
}
return g.sealObjectTimeout
case coretask.TypeTaskDownloadObject:
timeout := size / (uint64(g.downloadSpeed) + 1) / (MinSpeed)
if timeout < uint64(MinDownloadTime) {
return MinDownloadTime
}
if timeout > uint64(MaxDownloadTime) {
return MaxDownloadTime
}
return util.Uint64ToInt64(timeout)
case coretask.TypeTaskChallengePiece:
timeout := size / (uint64(g.downloadSpeed) + 1) / (MinSpeed)
if timeout < uint64(MinDownloadTime) {
return MinDownloadTime
}
if timeout > uint64(MaxDownloadTime) {
return MaxDownloadTime
}
return util.Uint64ToInt64(timeout)
case coretask.TypeTaskGCObject:
if g.gcObjectTimeout < MinGCObjectTime {
return MinGCObjectTime
}
if g.gcObjectTimeout > MaxGCObjectTime {
return MaxGCObjectTime
}
return g.gcObjectTimeout
case coretask.TypeTaskGCZombiePiece:
if g.gcZombieTimeout < MinGCZombieTime {
return MinGCZombieTime
}
if g.gcZombieTimeout > MaxGCZombieTime {
return MaxGCZombieTime
}
return g.gcZombieTimeout
case coretask.TypeTaskGCMeta:
if g.gcMetaTimeout < MinGCMetaTime {
return MinGCMetaTime
}
if g.gcMetaTimeout > MaxGCMetaTime {
return MaxGCMetaTime
}
return g.gcMetaTimeout
case coretask.TypeTaskRecoverPiece:
timeout := size/(uint64(g.replicateSpeed)+1)/(MinSpeed) + 1
if timeout < uint64(MinRecoveryTime) {
return MinRecoveryTime
}
if timeout > uint64(MaxRecoveryTime) {
return MaxRecoveryTime
}
return util.Uint64ToInt64(timeout)
case coretask.TypeTaskMigrateGVG:
if g.migrateGVGTimeout < MinMigrateGVGTime {
return MinMigrateGVGTime
}
if g.migrateGVGTimeout > MaxMigrateGVGTime {
return MaxMigrateGVGTime
}
return g.migrateGVGTimeout
case coretask.TypeTaskGCBucketMigration:
if g.gcBucketMigrationTimeout < MinGCBucketMigrationTime {
return MinGCBucketMigrationTime
}
if g.gcBucketMigrationTimeout > MaxGCBucketMigrationTime {
return MaxGCBucketMigrationTime
}
return g.gcBucketMigrationTimeout
case coretask.TypeTaskGCStaleVersionObject:
if g.gcStaleVersionObjectTimeout < MinGCStaleVersionObjectTime {
return MinGCStaleVersionObjectTime
}
if g.gcStaleVersionObjectTimeout > MaxGCStaleVersionObjectTime {
return MaxGCStaleVersionObjectTime
}
return g.gcStaleVersionObjectTimeout
}
return NotUseTimeout
}
// TaskMaxRetry returns the task max retry by task type.
func (g *GfSpBaseApp) TaskMaxRetry(task coretask.Task) int64 {
switch task.Type() {
case coretask.TypeTaskCreateBucketApproval:
return NotUseRetry
case coretask.TypeTaskCreateObjectApproval:
return NotUseRetry
case coretask.TypeTaskReplicatePieceApproval:
return NotUseRetry
case coretask.TypeTaskUpload:
return NotUseRetry
case coretask.TypeTaskReplicatePiece:
if g.replicateRetry < MinReplicateRetry {
return MinReplicateRetry
}
if g.replicateRetry > MaxReplicateRetry {
return MaxReplicateRetry
}
return g.replicateRetry
case coretask.TypeTaskReceivePiece:
if g.receiveConfirmRetry < MinReceiveConfirmRetry {
return MinReceiveConfirmRetry
}
if g.receiveConfirmRetry > MaxReceiveConfirmRetry {
return MaxReceiveConfirmRetry
}
return g.receiveConfirmRetry
case coretask.TypeTaskSealObject:
if g.sealObjectRetry < MinSealObjectRetry {
return MinSealObjectRetry
}
if g.sealObjectRetry > MaxSealObjectRetry {
return MaxSealObjectRetry
}
return g.sealObjectRetry
case coretask.TypeTaskDownloadObject:
return NotUseRetry
case coretask.TypeTaskChallengePiece:
return NotUseRetry
case coretask.TypeTaskGCObject:
if g.gcObjectRetry < MinGCObjectRetry {
return MinGCObjectRetry
}
if g.gcObjectRetry > MaxGCObjectRetry {
return MaxGCObjectRetry
}
return g.gcObjectRetry
case coretask.TypeTaskGCZombiePiece:
if g.gcZombieRetry < MinGCObjectRetry {
return MinGCObjectRetry
}
if g.gcZombieRetry > MaxGCObjectRetry {
return MaxGCObjectRetry
}
return g.gcZombieRetry
case coretask.TypeTaskGCMeta:
if g.gcMetaRetry < MinGCObjectRetry {
return MinGCObjectRetry
}
if g.gcMetaRetry > MaxGCObjectRetry {
return MaxGCObjectRetry
}
return g.gcMetaRetry
case coretask.TypeTaskRecoverPiece:
if g.recoveryRetry < MinRecoveryRetry {
return MinRecoveryRetry
}
if g.recoveryRetry > MaxRecoveryRetry {
return MaxRecoveryRetry
}
return g.recoveryRetry
case coretask.TypeTaskMigrateGVG:
if g.migrateGVGRetry < MinMigrateGVGRetry {
return MinMigrateGVGRetry
}
if g.migrateGVGRetry > MaxMigrateGVGRetry {
return MaxMigrateGVGRetry
}
return g.migrateGVGRetry
case coretask.TypeTaskGCBucketMigration:
if g.gcBucketMigrationRetry < MinGCBucketMigrationRetry {
return MinGCBucketMigrationRetry
}
if g.gcBucketMigrationRetry > MaxGCBucketMigrationRetry {
return MaxGCBucketMigrationRetry
}
return g.gcBucketMigrationRetry
default:
return NotUseRetry
}
}
// TaskPriority returns the task priority by task type, it is the default options.
// the task priority support self define and dynamic settings.
func (g *GfSpBaseApp) TaskPriority(task coretask.Task) coretask.TPriority {
switch task.Type() {
case coretask.TypeTaskCreateBucketApproval:
return coretask.UnSchedulingPriority
case coretask.TypeTaskMigrateBucketApproval:
return coretask.UnSchedulingPriority
case coretask.TypeTaskCreateObjectApproval:
return coretask.UnSchedulingPriority
case coretask.TypeTaskReplicatePieceApproval:
return coretask.UnSchedulingPriority
case coretask.TypeTaskUpload:
return coretask.UnSchedulingPriority
case coretask.TypeTaskReplicatePiece:
return coretask.MaxTaskPriority
case coretask.TypeTaskReceivePiece:
return coretask.DefaultSmallerPriority / 4
case coretask.TypeTaskSealObject:
return coretask.DefaultSmallerPriority
case coretask.TypeTaskDownloadObject:
return coretask.UnSchedulingPriority
case coretask.TypeTaskChallengePiece:
return coretask.UnSchedulingPriority
case coretask.TypeTaskGCObject:
return coretask.DefaultSmallerPriority / 4
case coretask.TypeTaskGCZombiePiece:
return coretask.DefaultSmallerPriority / 4
case coretask.TypeTaskGCMeta:
return coretask.DefaultSmallerPriority / 4
case coretask.TypeTaskGCBucketMigration:
return coretask.DefaultSmallerPriority / 4
case coretask.TypeTaskGCStaleVersionObject:
return coretask.DefaultSmallerPriority / 4
case coretask.TypeTaskRecoverPiece:
return coretask.DefaultSmallerPriority / 4
case coretask.TypeTaskMigrateGVG:
return coretask.DefaultSmallerPriority
default:
return coretask.UnKnownTaskPriority
}
}
// TaskPriorityLevel returns the task priority level, it is computed by task priority.
func (g *GfSpBaseApp) TaskPriorityLevel(task coretask.Task) coretask.TPriorityLevel {
if task.GetPriority() <= coretask.DefaultSmallerPriority {
return coretask.TLowPriorityLevel
}
if task.GetPriority() > coretask.DefaultLargerTaskPriority {
return coretask.THighPriorityLevel
}
return coretask.TMediumPriorityLevel
}