Skip to content

Commit

Permalink
fix: fix wrong max age transformation from seconds (#23684)
Browse files Browse the repository at this point in the history
* fix: fix wrong max age transformation from seconds

* refactor: clarify max age intent

* refactor: remove unnecessary duration
  • Loading branch information
ZuperZee authored Nov 16, 2022
1 parent 7ad8fba commit 666cabb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions replications/internal/queue_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
const (
scannerAdvanceInterval = 10 * time.Second
purgeInterval = 60 * time.Second
defaultMaxAge = 168 * time.Hour / time.Second
defaultMaxAge = 7 * 24 * time.Hour // 1 week
)

type remoteWriter interface {
Expand Down Expand Up @@ -72,7 +72,7 @@ func NewDurableQueueManager(log *zap.Logger, queuePath string, metrics *metrics.
}

// InitializeQueue creates and opens a new durable queue which is associated with a replication stream.
func (qm *durableQueueManager) InitializeQueue(replicationID platform.ID, maxQueueSizeBytes int64, orgID platform.ID, localBucketID platform.ID, maxAge int64) error {
func (qm *durableQueueManager) InitializeQueue(replicationID platform.ID, maxQueueSizeBytes int64, orgID platform.ID, localBucketID platform.ID, maxAgeSeconds int64) error {
qm.mutex.Lock()
defer qm.mutex.Unlock()

Expand Down Expand Up @@ -112,7 +112,7 @@ func (qm *durableQueueManager) InitializeQueue(replicationID platform.ID, maxQue
}

// Map new durable queue and scanner to its corresponding replication stream via replication ID
rq := qm.newReplicationQueue(replicationID, orgID, localBucketID, newQueue, maxAge)
rq := qm.newReplicationQueue(replicationID, orgID, localBucketID, newQueue, maxAgeSeconds)
qm.replicationQueues[replicationID] = rq
rq.Open()

Expand Down Expand Up @@ -439,15 +439,15 @@ func (qm *durableQueueManager) EnqueueData(replicationID platform.ID, data []byt
return nil
}

func (qm *durableQueueManager) newReplicationQueue(id platform.ID, orgID platform.ID, localBucketID platform.ID, queue *durablequeue.Queue, maxAge int64) *replicationQueue {
func (qm *durableQueueManager) newReplicationQueue(id platform.ID, orgID platform.ID, localBucketID platform.ID, queue *durablequeue.Queue, maxAgeSeconds int64) *replicationQueue {
logger := qm.logger.With(zap.String("replication_id", id.String()))
done := make(chan struct{})
// check for max age minimum
var maxAgeTime time.Duration
if maxAge < 0 {
if maxAgeSeconds < 0 {
maxAgeTime = defaultMaxAge
} else {
maxAgeTime = time.Duration(maxAge)
maxAgeTime = time.Duration(maxAgeSeconds) * time.Second
}

return &replicationQueue{
Expand Down

0 comments on commit 666cabb

Please sign in to comment.