Skip to content

Commit

Permalink
Made startup timer explicitly linked to broadcast interval, fixed for…
Browse files Browse the repository at this point in the history
…ced quota renewal bug
  • Loading branch information
lonelycode committed Apr 27, 2017
1 parent 3372870 commit d2f3d58
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ func doAddOrUpdate(keyName string, newSession SessionState, dontReset bool) erro
QuotaHandler.TagDelete(keyName)
}
apiSpec.SessionManager.ResetQuota(keyName, newSession)

// Update the maximum
newSession.QuotaRemaining = newSession.QuotaMax
newSession.QuotaRenews = time.Now().Unix() + newSession.QuotaRenewalRate
}

Expand Down
3 changes: 3 additions & 0 deletions auth_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func (b *DefaultSessionManager) ResetQuota(keyName string, session SessionState)
// Fix the raw key
go b.Store.DeleteRawKey(rawKey)
//go b.Store.SetKey(rawKey, "0", session.QuotaRenewalRate)
if config.UseDistributedQuotaCounter {
QuotaHandler.TagDelete(keyName)
}
}

// UpdateSession updates the session state in the storage engine
Expand Down
7 changes: 4 additions & 3 deletions dq.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ func startDQ(statusFunc GetLeaderStatusFunc) {
}

QuotaHandler = dq.NewDQ(dqFlusher, dqErrorHandler, NodeID)
QuotaHandler.BroadcastWith(c1, time.Millisecond*100, getDQTopic())
broadcastTimer := time.Millisecond*100
QuotaHandler.BroadcastWith(c1, broadcastTimer, getDQTopic())

// We always need a leader because otherwise we can;t persist data
QuotaHandler.SetLeader(statusFunc())
Expand All @@ -160,8 +161,8 @@ func startDQ(statusFunc GetLeaderStatusFunc) {
log.Fatal(err)
}

// Give us time to catch up
time.Sleep(time.Millisecond * 100)
// Give us time to catch with the cluster
time.Sleep(broadcastTimer)
}

func (l SessionLimiter) IsDistributedQuotaExceeded(currentSession *SessionState, key string) bool {
Expand Down

0 comments on commit d2f3d58

Please sign in to comment.