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

Don't precreate shard groups entirely in past #3931

Merged
merged 2 commits into from
Sep 4, 2015
Merged

Conversation

otoolep
Copy link
Contributor

@otoolep otoolep commented Sep 1, 2015

If a shard group is completely in the past, don't precreate its successor. Before this fix, this could happen if someone wrote a single point into the past, which means a shard group was created for that point, and then precreation would create the entire successor series of groups.

Fixes issue #3722

@otoolep
Copy link
Contributor Author

otoolep commented Sep 1, 2015

@corylanou

@corylanou
Copy link
Contributor

Nice! Good optimization. +1 on green.

@otoolep otoolep force-pushed the no_past_shards branch 2 times, most recently from 1b42576 to e32d871 Compare September 1, 2015 19:07
@pauldix
Copy link
Member

pauldix commented Sep 1, 2015

The PrecreateShardGroups function looks more complex to me than it should be. The ShardGroups in any retention policy should always be sorted in time ascending order. That means you should only look at the last shard group for each RP.

Also, cutoff time doesn't make sense to me. I think it's easier to understand if it something like this inside the loop of the replication policies.

mostRecentShard := rp.ShardGroups[len(rp.ShardGroups)-1]
nearFuture := time.Now.Add(2 * time.Hour).Unix()
if nearFuture > mostRecentShard.EndTime.Unix() {
  // create the shard group
}

@otoolep
Copy link
Contributor Author

otoolep commented Sep 1, 2015

@pauldix -- cutoff time is nearFuture in your version, the logic is the same. We might make it easier to follow, but the core logic remains the same. Also, the choice to push the various times into the function is about making testing easier and cleaner.

Let me see if I can simplify it by looking at only the last shard group in the RP.

@otoolep
Copy link
Contributor Author

otoolep commented Sep 1, 2015

Shard groups are not stored in a sorted manner, that I can see.

https://github.com/influxdb/influxdb/blob/master/meta/data.go#L353

and the function which returns ShardGroups on an RPI, doesn't seem to sort them either:

https://github.com/influxdb/influxdb/blob/master/meta/data.go#L241

We might need some more changes here, such that the Precreate function can be simplified. I can do that in a separate PR.

@pauldix
Copy link
Member

pauldix commented Sep 1, 2015

Yeah, since shard groups are rarely created, and they almost always need to
be queried in sorted order, they should be kept sorted. That way we don't
need to sort them every time before querying.

On Tue, Sep 1, 2015 at 3:37 PM, otoolep notifications@github.com wrote:

Shard groups are not stored in a sorted manner, that I can see.

https://github.com/influxdb/influxdb/blob/master/meta/data.go#L353

and the function which returns ShardGroups on an RPI, doesn't seem to sort
them either:

https://github.com/influxdb/influxdb/blob/master/meta/data.go#L241

We might need some more changes here, such that the Precreate function can
be simplified. I can do that in a separate PR.


Reply to this email directly or view it on GitHub
#3931 (comment).

@otoolep
Copy link
Contributor Author

otoolep commented Sep 1, 2015

Agreed @pauldix -- the case for storing these sorted makes sense to me. Let me see what I can do.

@otoolep otoolep force-pushed the no_past_shards branch 2 times, most recently from 569fee6 to ca6460f Compare September 1, 2015 20:47
@otoolep
Copy link
Contributor Author

otoolep commented Sep 1, 2015

@pauldix @corylanou

Logic updated now that shard groups are sorted by time. Removes one for loop and if check, which is good. I also renamed cutoff to future. I am open to other names.

s.Logger.Printf("new shard group %d successfully created for database %s, retention policy %s",
newGroup.ID, di.Name, rp.Name)
}
if len(rp.ShardGroups) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

A comment here would be useful. When would len(rp.ShardGroups) == 0? Is this basically checking to make sure that the retention policy has been written to at least once before pre-creating shard groups?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly. Or all shard groups have been expired out.

@jwilder
Copy link
Contributor

jwilder commented Sep 4, 2015

Two small smalls things but otherwise 👍

@otoolep
Copy link
Contributor Author

otoolep commented Sep 4, 2015

Thanks @jwilder -- will merge on green.

otoolep added a commit that referenced this pull request Sep 4, 2015
Don't precreate shard groups entirely in past
@otoolep otoolep merged commit 3a8b02a into master Sep 4, 2015
@otoolep otoolep deleted the no_past_shards branch September 4, 2015 15:38
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.

None yet

4 participants