Add function to return shard group by ID
If shard groups were stored in a map by ID, this lookup could be sped up.pull/1562/head
parent
20bbbe759b
commit
37647cc6a6
11
database.go
11
database.go
|
@ -795,6 +795,17 @@ func (rp *RetentionPolicy) shardGroupByTimestamp(timestamp time.Time) *ShardGrou
|
|||
return nil
|
||||
}
|
||||
|
||||
// shardGroupByID returns the group in the policy for the given ID.
|
||||
// Returns nil if group does not exist.
|
||||
func (rp *RetentionPolicy) shardGroupByID(shardID uint64) *ShardGroup {
|
||||
for _, g := range rp.shardGroups {
|
||||
if g.ID == shardID {
|
||||
return g
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON encodes a retention policy to a JSON-encoded byte slice.
|
||||
func (rp *RetentionPolicy) MarshalJSON() ([]byte, error) {
|
||||
var o retentionPolicyJSON
|
||||
|
|
28
server.go
28
server.go
|
@ -80,10 +80,11 @@ const (
|
|||
|
||||
// Server represents a collection of metadata and raw metric data.
|
||||
type Server struct {
|
||||
mu sync.RWMutex
|
||||
id uint64
|
||||
path string
|
||||
done chan struct{} // goroutine close notification
|
||||
mu sync.RWMutex
|
||||
id uint64
|
||||
path string
|
||||
done chan struct{} // goroutine close notification
|
||||
rpDone chan struct{} // retention policies goroutine close notification
|
||||
|
||||
client MessagingClient // broker client
|
||||
index uint64 // highest broadcast index seen
|
||||
|
@ -220,6 +221,10 @@ func (s *Server) Close() error {
|
|||
return ErrServerClosed
|
||||
}
|
||||
|
||||
if s.rpDone != nil {
|
||||
close(s.rpDone)
|
||||
}
|
||||
|
||||
// Remove path.
|
||||
s.path = ""
|
||||
|
||||
|
@ -294,9 +299,24 @@ func (s *Server) EnforceRetentionPolicies(checkInterval time.Duration) error {
|
|||
if checkInterval == 0 {
|
||||
return fmt.Errorf("retention policy check interval must be non-zero")
|
||||
}
|
||||
rpDone := make(chan struct{}, 0)
|
||||
s.rpDone = rpDone
|
||||
go s.retentionPoliciesLoop(checkInterval, rpDone)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) retentionPoliciesLoop(interval time.Duration, done chan struct{}) {
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
return
|
||||
case <-time.After(interval):
|
||||
}
|
||||
|
||||
log.Println("retention policy enforcement check commencing")
|
||||
}
|
||||
}
|
||||
|
||||
// Client retrieves the current messaging client.
|
||||
func (s *Server) Client() MessagingClient {
|
||||
s.mu.RLock()
|
||||
|
|
Loading…
Reference in New Issue