MCPcopy Create free account
hub / github.com/cortexproject/cortex / UpdateUserTimestamp

Method UpdateUserTimestamp

pkg/util/users/active_user.go:26–53  ·  view source on GitHub ↗
(userID string, ts int64)

Source from the content-addressed store, hash-verified

24}
25
26func (m *ActiveUsers) UpdateUserTimestamp(userID string, ts int64) {
27 m.mu.RLock()
28 u := m.timestamps[userID]
29 m.mu.RUnlock()
30
31 if u != nil {
32 u.Store(ts)
33 return
34 }
35
36 // Pre-allocate new atomic to avoid doing allocation with lock held.
37 newAtomic := atomic.NewInt64(ts)
38
39 // We need RW lock to create new entry.
40 m.mu.Lock()
41 u = m.timestamps[userID]
42
43 if u != nil {
44 // Unlock first to reduce contention.
45 m.mu.Unlock()
46
47 u.Store(ts)
48 return
49 }
50
51 m.timestamps[userID] = newAtomic
52 m.mu.Unlock()
53}
54
55// PurgeInactiveUsers removes users that were last active before given deadline, and returns removed users.
56func (m *ActiveUsers) PurgeInactiveUsers(deadline int64) []string {

Callers 11

TestActiveUserFunction · 0.95
enqueueRequestMethod · 0.45
reportQueryStatsMethod · 0.45
queueRequestMethod · 0.45
PushMethod · 0.45
NewQueryTripperwareFunction · 0.45
UpdateUserTimestampMethod · 0.45

Calls 1

StoreMethod · 0.65