Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 071d037

Browse files
committed
fix: queue: switch from using a time based counter to a monotonic one
1 parent f490131 commit 071d037

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

queue/queue.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package queue
33
import (
44
"context"
55
"fmt"
6-
"time"
7-
86
cid "github.com/ipfs/go-cid"
97
datastore "github.com/ipfs/go-datastore"
108
namespace "github.com/ipfs/go-datastore/namespace"
@@ -29,6 +27,8 @@ type Queue struct {
2927
enqueue chan cid.Cid
3028
close context.CancelFunc
3129
closed chan struct{}
30+
31+
counter int
3232
}
3333

3434
// NewQueue creates a queue for cids
@@ -117,7 +117,8 @@ func (q *Queue) work() {
117117

118118
select {
119119
case toQueue := <-q.enqueue:
120-
keyPath := fmt.Sprintf("%d/%s", time.Now().UnixNano(), c.String())
120+
keyPath := fmt.Sprintf("%063d/%s", q.counter, c.String())
121+
q.counter++
121122
nextKey := datastore.NewKey(keyPath)
122123

123124
if err := q.ds.Put(nextKey, toQueue.Bytes()); err != nil {

0 commit comments

Comments
 (0)