Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

simplify store month calculations #1148

Merged
merged 4 commits into from
Dec 28, 2018
Merged

Conversation

Dieterbe
Copy link
Contributor

@Dieterbe Dieterbe commented Nov 23, 2018

small simplification of code. should be 100% equivalent to what it was before, by leveraging the fact that integer divisions are always rounded down.

@Dieterbe Dieterbe force-pushed the simplify-month-calculations branch from 74f01c9 to aae24d0 Compare December 27, 2018 16:00
@Dieterbe Dieterbe changed the base branch from mt-store-cat-improvements to master December 27, 2018 16:01
@Dieterbe Dieterbe changed the title WIP simplify month calculations simplify store month calculations Dec 27, 2018
@@ -433,17 +433,14 @@ func (c *CassandraStore) SearchTable(ctx context.Context, key schema.AMKey, tabl

pre := time.Now()

start_month := start - (start % Month_sec) // starting row has to be at, or before, requested start
end_month := (end - 1) - ((end - 1) % Month_sec) // ending row has to include the last point we might need (end-1)

// unfortunately in the database we only have the t0's of all chunks.
// this means we can easily make sure to include the correct last chunk (just query for a t0 < end, the last chunk will contain the last needed data)
// but it becomes hard to find which should be the first chunk to include. we can't just query for start <= t0 because than we will miss some data at
// the beginning. We can't assume we know the chunkSpan so we can't just calculate the t0 >= (start - <some-predefined-number>) because chunkSpans
// may change over time.
// we effectively need all chunks with a t0 > start, as well as the last chunk with a t0 <= start.
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be as well as the last chunk with a t0 <= end instead of start

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no

@@ -433,17 +433,14 @@ func (c *CassandraStore) SearchTable(ctx context.Context, key schema.AMKey, tabl

pre := time.Now()

start_month := start - (start % Month_sec) // starting row has to be at, or before, requested start
end_month := (end - 1) - ((end - 1) % Month_sec) // ending row has to include the last point we might need (end-1)

// unfortunately in the database we only have the t0's of all chunks.
// this means we can easily make sure to include the correct last chunk (just query for a t0 < end, the last chunk will contain the last needed data)
// but it becomes hard to find which should be the first chunk to include. we can't just query for start <= t0 because than we will miss some data at
Copy link
Contributor

Choose a reason for hiding this comment

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

then instead of than

for month := start_month; month <= end_month; month += cassandra.Month_sec {
row_key := fmt.Sprintf("%s_%d", metric.AMKey.String(), month/cassandra.Month_sec)
for num := startMonth; num <= endMonth; num += 1 {
row_key := fmt.Sprintf("%s_%d", metric.AMKey.String(), num)
Copy link
Contributor

Choose a reason for hiding this comment

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

is .String() necessary? I thought it calls that automatically

Copy link
Contributor

Choose a reason for hiding this comment

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

https://golang.org/pkg/fmt/#hdr-Printing basically says that if it implements Error and String that Error will be called first, so we should probably make it a habit to explicitly call String(). I haven't read the entire thing yet so if I find any other information I'll re-post it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

an Error() method only makes sense on types that represent errors or are tightly bound to an error (e.g. iterator api's sometimes have a method to retrieve an error, if any).

but for our key types, this clearly doesn't apply, so i'm following replay's suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we voted on slack it's better to always be explicit for every type.
see #1188

Copy link
Contributor

@replay replay left a comment

Choose a reason for hiding this comment

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

LGTM
I can see no errors, just some minor stuff to improve

@Dieterbe Dieterbe merged commit 5c9701f into master Dec 28, 2018
@Dieterbe Dieterbe added this to the vnext milestone Feb 11, 2019
@Dieterbe Dieterbe deleted the simplify-month-calculations branch March 27, 2019 21:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants