@@ -21,7 +21,7 @@ type ResourceIndex struct {
21
21
// IssueIndex represents the issue index table
22
22
type IssueIndex ResourceIndex
23
23
24
- // the function will not return until it acquires the lock or receives an error.
24
+ // upsertResourceIndex the function will not return until it acquires the lock or receives an error.
25
25
func upsertResourceIndex (e Engine , tableName string , groupID int64 ) (err error ) {
26
26
// An atomic UPSERT operation (INSERT/UPDATE) is the only operation
27
27
// that ensures that the key is actually locked.
@@ -50,13 +50,19 @@ func upsertResourceIndex(e Engine, tableName string, groupID int64) (err error)
50
50
}
51
51
52
52
var (
53
- ErrResouceOutdated = errors .New ("resource outdated" )
53
+ // ErrResouceOutdated represents an error when request resource outdated
54
+ ErrResouceOutdated = errors .New ("resource outdated" )
55
+ // ErrGetResourceIndexFailed represents an error when resource index retries 3 times
54
56
ErrGetResourceIndexFailed = errors .New ("get resource index failed" )
55
57
)
56
58
59
+ const (
60
+ maxDupIndexAttempts = 3
61
+ )
62
+
57
63
// GetNextResourceIndex retried 3 times to generate a resource index
58
64
func GetNextResourceIndex (tableName string , groupID int64 ) (int64 , error ) {
59
- for i := 0 ; i < 3 ; i ++ {
65
+ for i := 0 ; i < maxDupIndexAttempts ; i ++ {
60
66
idx , err := getNextResourceIndex (tableName , groupID )
61
67
if err == ErrResouceOutdated {
62
68
continue
0 commit comments