-
Notifications
You must be signed in to change notification settings - Fork 38
/
task_key.go
133 lines (112 loc) · 5.62 KB
/
task_key.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
package gfsptask
import (
"encoding/hex"
"fmt"
"strconv"
"github.com/bnb-chain/greenfield-storage-provider/core/task"
)
const (
Delimiter = "-"
KeyPrefixGfSpCreateBucketApprovalTask = "CreateBucketApproval"
KeyPrefixGfSpMigrateBucketApprovalTask = "MigrateBucketApproval"
KeyPrefixGfSpCreateObjectApprovalTask = "CreateObjectApproval"
KeyPrefixGfSpReplicatePieceApprovalTask = "ReplicatePieceApproval"
KeyPrefixGfSpDownloadObjectTask = "DownloadObject"
KeyPrefixGfSpDownloadPieceTask = "DownloadPiece"
KeyPrefixGfSpChallengeTask = "ChallengePiece"
KeyPrefixGfSpUploadObjectTask = "Uploading"
KeyPrefixGfSpReplicatePieceTask = "Uploading"
KeyPrefixGfSpSealObjectTask = "Uploading"
KeyPrefixGfSpResumableUploadObjectTask = "ResumableUploading"
KeyPrefixGfSpRecoverPieceTask = "Recovering"
KeyPrefixGfSpReceivePieceTask = "ReceivePiece"
KeyPrefixGfSpGCObjectTask = "GCObject"
KeyPrefixGfSpGCZombiePieceTask = "GCZombiePiece"
KeyPrefixGfSpGfSpGCMetaTask = "GCMeta"
KeyPrefixGfSpMigrateGVGTask = "MigrateGVG"
KeyPrefixGfSpMigratePieceTask = "MigratePiece"
)
func GfSpCreateBucketApprovalTaskKey(bucket string, account string, fingerprint []byte) task.TKey {
return task.TKey(KeyPrefixGfSpCreateBucketApprovalTask + CombineKey("bucket:"+bucket, "account:"+account,
"fingerprint:"+hex.EncodeToString(fingerprint)))
}
func GfSpCreateObjectApprovalTaskKey(bucket, object string, account string, fingerprint []byte) task.TKey {
return task.TKey(KeyPrefixGfSpCreateObjectApprovalTask +
CombineKey("bucket:"+bucket, "object:"+object, "account:"+account,
"fingerprint:"+hex.EncodeToString(fingerprint)))
}
func GfSpMigrateBucketApprovalTaskKey(bucket string, migrateBucketHash string) task.TKey {
return task.TKey(KeyPrefixGfSpMigrateBucketApprovalTask + CombineKey("bucket:"+bucket, "hash:"+migrateBucketHash))
}
func GfSpReplicatePieceApprovalTaskKey(bucket, object, id string) task.TKey {
return task.TKey(KeyPrefixGfSpReplicatePieceApprovalTask +
CombineKey("bucket:"+bucket, "object:"+object, "id:"+id))
}
func GfSpDownloadObjectTaskKey(bucket, object, id string, low, high int64) task.TKey {
return task.TKey(KeyPrefixGfSpDownloadObjectTask +
CombineKey("bucket:"+bucket, "object:"+object, "id:"+id,
"low:"+fmt.Sprint(low), "high:"+fmt.Sprint(high)))
}
func GfSpDownloadPieceTaskKey(bucket, object, pieceKey string, pieceOffset, pieceLength uint64) task.TKey {
return task.TKey(KeyPrefixGfSpDownloadPieceTask +
CombineKey("bucket:"+bucket, "object:"+object, "piece:"+pieceKey,
"offset:"+fmt.Sprint(pieceOffset), "length:"+fmt.Sprint(pieceLength)))
}
func GfSpChallengePieceTaskKey(bucket, object, id string, sIdx uint32, rIdx int32, user string) task.TKey {
return task.TKey(KeyPrefixGfSpChallengeTask +
CombineKey("bucket:"+bucket, "object:"+object, "id:"+id,
"sIdx:"+fmt.Sprint(sIdx), "rIdx:"+fmt.Sprint(rIdx), user))
}
func GfSpUploadObjectTaskKey(bucket, object, id string) task.TKey {
return task.TKey(KeyPrefixGfSpUploadObjectTask +
CombineKey("bucket:"+bucket, "object:"+object, "id:"+id))
}
func GfSpResumableUploadObjectTaskKey(bucket, object, id string, offset uint64) task.TKey {
return task.TKey(KeyPrefixGfSpResumableUploadObjectTask + CombineKey(bucket, object, id, strconv.FormatUint(offset, 10)))
}
func GfSpReplicatePieceTaskKey(bucket, object, id string) task.TKey {
return task.TKey(KeyPrefixGfSpReplicatePieceTask +
CombineKey("bucket:"+bucket, "object:"+object, "id:"+id))
}
func GfSpRecoverPieceTaskKey(bucket, object, id string, pIdx uint32, replicateIdx int32, time int64) task.TKey {
if replicateIdx >= 0 {
return task.TKey(KeyPrefixGfSpRecoverPieceTask +
CombineKey("bucket:"+bucket, "object:"+object, "id:"+id, "segIdx:"+fmt.Sprint(pIdx), "ecIdx:"+fmt.Sprint(replicateIdx), "time"+fmt.Sprint(time)))
}
return task.TKey(KeyPrefixGfSpRecoverPieceTask +
CombineKey("bucket:"+bucket, "object:"+object, "id:"+id, "segIdx:"+fmt.Sprint(pIdx), "time"+fmt.Sprint(time)))
}
func GfSpSealObjectTaskKey(bucket, object, id string) task.TKey {
return task.TKey(KeyPrefixGfSpSealObjectTask +
CombineKey("bucket:"+bucket, "object:"+object, "id:"+id))
}
func GfSpReceivePieceTaskKey(bucket, object, id string, rIdx uint32, pIdx int32) task.TKey {
return task.TKey(KeyPrefixGfSpReceivePieceTask +
CombineKey("bucket:"+bucket, "object:"+object, "id:"+id,
"segmentIdx:"+fmt.Sprint(rIdx), "redundancyIdx:"+fmt.Sprint(pIdx)))
}
func GfSpGCObjectTaskKey(start, end uint64, time int64) task.TKey {
return task.TKey(KeyPrefixGfSpGCObjectTask + CombineKey(
"start"+fmt.Sprint(start), "end"+fmt.Sprint(end), "time"+fmt.Sprint(time)))
}
func GfSpGCZombiePieceTaskKey(time int64) task.TKey {
return task.TKey(KeyPrefixGfSpGCZombiePieceTask + CombineKey("time"+fmt.Sprint(time)))
}
func GfSpGfSpGCMetaTaskKey(time int64) task.TKey {
return task.TKey(KeyPrefixGfSpGfSpGCMetaTask + CombineKey("time"+fmt.Sprint(time)))
}
func GfSpMigrateGVGTaskKey(oldGvgID uint32, bucketID uint64, redundancyIndex int32) task.TKey {
return task.TKey(KeyPrefixGfSpMigrateGVGTask + CombineKey(
"oldGvgID"+fmt.Sprint(oldGvgID), "bucketID"+fmt.Sprint(bucketID), "redundancyIndex"+fmt.Sprint(redundancyIndex)))
}
func GfSpMigratePieceTaskKey(object, id string, redundancyIdx uint32, ecIdx int32) task.TKey {
return task.TKey(KeyPrefixGfSpMigratePieceTask + CombineKey("object:"+object, "id:", id, "segIdx:",
fmt.Sprint(redundancyIdx), "redundancyIndex:", fmt.Sprint(ecIdx)))
}
func CombineKey(field ...string) string {
key := ""
for _, f := range field {
key = key + Delimiter + f
}
return key
}