| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package coordinator | 5 package coordinator |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "sync" | 8 "sync" |
| 9 "time" | 9 "time" |
| 10 | 10 |
| 11 "github.com/luci/luci-go/common/clock" | 11 "github.com/luci/luci-go/common/clock" |
| 12 "github.com/luci/luci-go/common/config" | |
| 13 "github.com/luci/luci-go/common/data/caching/lru" | 12 "github.com/luci/luci-go/common/data/caching/lru" |
| 14 "github.com/luci/luci-go/common/errors" | 13 "github.com/luci/luci-go/common/errors" |
| 15 log "github.com/luci/luci-go/common/logging" | 14 log "github.com/luci/luci-go/common/logging" |
| 16 "github.com/luci/luci-go/common/sync/promise" | 15 "github.com/luci/luci-go/common/sync/promise" |
| 17 "github.com/luci/luci-go/common/tsmon/field" | 16 "github.com/luci/luci-go/common/tsmon/field" |
| 18 "github.com/luci/luci-go/common/tsmon/metric" | 17 "github.com/luci/luci-go/common/tsmon/metric" |
| 19 "github.com/luci/luci-go/logdog/common/types" | 18 "github.com/luci/luci-go/logdog/common/types" |
| 19 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 20 "golang.org/x/net/context" | 20 "golang.org/x/net/context" |
| 21 ) | 21 ) |
| 22 | 22 |
| 23 const ( | 23 const ( |
| 24 // DefaultSize is the default (maximum) size of the LRU cache. | 24 // DefaultSize is the default (maximum) size of the LRU cache. |
| 25 DefaultSize = 1024 * 1024 | 25 DefaultSize = 1024 * 1024 |
| 26 | 26 |
| 27 // DefaultExpiration is the default expiration value. | 27 // DefaultExpiration is the default expiration value. |
| 28 DefaultExpiration = 10 * time.Minute | 28 DefaultExpiration = 10 * time.Minute |
| 29 ) | 29 ) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 func (c *cache) TerminateStream(ctx context.Context, r *TerminateRequest) error
{ | 119 func (c *cache) TerminateStream(ctx context.Context, r *TerminateRequest) error
{ |
| 120 entry, _ := c.getCacheEntry(ctx, cacheEntryKey{ | 120 entry, _ := c.getCacheEntry(ctx, cacheEntryKey{ |
| 121 project: r.Project, | 121 project: r.Project, |
| 122 path: r.Path, | 122 path: r.Path, |
| 123 }) | 123 }) |
| 124 return entry.terminateStream(ctx, c.Coordinator, *r) | 124 return entry.terminateStream(ctx, c.Coordinator, *r) |
| 125 } | 125 } |
| 126 | 126 |
| 127 // cacheEntryKey is the LRU key for a cacheEntry. | 127 // cacheEntryKey is the LRU key for a cacheEntry. |
| 128 type cacheEntryKey struct { | 128 type cacheEntryKey struct { |
| 129 » project config.ProjectName | 129 » project cfgtypes.ProjectName |
| 130 path types.StreamPath | 130 path types.StreamPath |
| 131 } | 131 } |
| 132 | 132 |
| 133 // cacheEntry is a cached state for a specific log stream. | 133 // cacheEntry is a cached state for a specific log stream. |
| 134 // | 134 // |
| 135 // It contains promises for each singleton operation: one for stream | 135 // It contains promises for each singleton operation: one for stream |
| 136 // registration (registerP), and one for stream termination (terminateP). | 136 // registration (registerP), and one for stream termination (terminateP). |
| 137 // | 137 // |
| 138 // There are three states to promise evaluation: | 138 // There are three states to promise evaluation: |
| 139 // - If the promise is nil, it will be populated. Any concurrent requests | 139 // - If the promise is nil, it will be populated. Any concurrent requests |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 ce.terminalIndex = tidx | 295 ce.terminalIndex = tidx |
| 296 } | 296 } |
| 297 }) | 297 }) |
| 298 } | 298 } |
| 299 | 299 |
| 300 func (ce *cacheEntry) withLock(f func()) { | 300 func (ce *cacheEntry) withLock(f func()) { |
| 301 ce.Lock() | 301 ce.Lock() |
| 302 defer ce.Unlock() | 302 defer ce.Unlock() |
| 303 f() | 303 f() |
| 304 } | 304 } |
| OLD | NEW |