Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shard group creation #2610

Merged
merged 4 commits into from
May 19, 2015
Merged

Fix shard group creation #2610

merged 4 commits into from
May 19, 2015

Conversation

jwilder
Copy link
Contributor

@jwilder jwilder commented May 19, 2015

This PR fixes two issues with shard group creation.

The first is that a shard group create request was sent for every point which can cause large pauses when a new shard group needs to be created when sending large batches.

The second is that the shard group end time was being included in the point calculation which allows a point to be included in two shard group ranges if it matched the end time of a shard group.

@@ -390,7 +390,6 @@ func (s *Server) StartSelfMonitoring(database, retention string, interval time.D

// Shard-level stats.
tags["shardID"] = strconv.FormatUint(s.id, 10)
s.mu.RLock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing these locks? They are needed to avoid a race condition that was flagged on Circle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's odd. Not sure how those got removed. Will revet that.

@otoolep
Copy link
Contributor

otoolep commented May 19, 2015

The change makes sense, except for the removal of the locks.

@jwilder jwilder force-pushed the jw-shard-groups branch 2 times, most recently from be0d522 to 6941d5e Compare May 19, 2015 15:08
@jwilder
Copy link
Contributor Author

jwilder commented May 19, 2015

Removed the lock removal changes. Not supposed to be in this PR.

jwilder added 3 commits May 19, 2015 09:31
Shard groups were being created for each point causing a a lot of
excessive broadcasts for large batches.
End time was included in the check for a point.  This meant a
point that was truncated and landed on the end time could fall
in both the prior and next shard groups.  For example, a range
17:00-18:00 and 18:00-19:00 would both include a point that was
at 18:00.
@jwilder jwilder force-pushed the jw-shard-groups branch from c8e7ab0 to 8edb851 Compare May 19, 2015 15:31
@@ -1160,7 +1160,7 @@ func NewRetentionPolicy(name string) *RetentionPolicy {
// Returns nil group does not exist.
func (rp *RetentionPolicy) shardGroupByTimestamp(timestamp time.Time) *ShardGroup {
for _, g := range rp.shardGroups {
if timeBetweenInclusive(timestamp, g.StartTime, g.EndTime) {
if (g.StartTime.Before(timestamp) || g.StartTime.Equal(timestamp)) && g.EndTime.After(timestamp) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about !g.StartTime.After(timestamp) && g.EndTime.After(timestamp) or g.Contains(timestamp, timestamp) (which reads kind of awkwardly but uses the logic encapsulated in ShardGroup)?

@jwilder
Copy link
Contributor Author

jwilder commented May 19, 2015

@otoolep Updated PR to fix another place where shard group boundaries were calculated incorrectly.

// Overlaps return whether the shard group contains data for the time range between min and max
func (sg *ShardGroup) Overlaps(min, max time.Time) bool {
return min.Before(sg.StartTime) && (max.After(sg.StartTime) || max.Equal(sg.StartTime)) ||
sg.Contains(min) || sg.Contains(max)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this can be simplified

return !sg.StartTime.After(max) && sg.EndTime.After(min)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@neonstalwart
Copy link
Contributor

👏 for the ShardGroup API improvements. i couldn't find a way to justify touching that API with any of my other PRs but i was just waiting for the chance to find a reason to improve/simplify the logic around checking whether a shard contains an interval.

@corylanou
Copy link
Contributor

+1, great catch.

@jwilder jwilder force-pushed the jw-shard-groups branch from c130e35 to e1d6a87 Compare May 19, 2015 17:18
The logic in this function was wrong when used for shard group
bound calculations so remove it and use functions on shard group
instead.
@jwilder jwilder force-pushed the jw-shard-groups branch from e1d6a87 to 67a2317 Compare May 19, 2015 17:20
for _, p := range points {
times[p.Time.Truncate(rp.ShardGroupDuration)] = struct{}{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have a question to try and improve my own understanding of go. i've seen this pattern a couple of times in this codebase so i have to ask...

since you only care about the keys of this map, is it any more efficient (from the point of view of memory allocation) to make this a map[time.Time]* struct{}{} and use nil as the value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you - that's exactly the info i was wanting.

jwilder added a commit that referenced this pull request May 19, 2015
@jwilder jwilder merged commit 6f2052a into master May 19, 2015
@jwilder jwilder deleted the jw-shard-groups branch June 26, 2015 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants