Skip to content

Ensure timestamp monotonicity within a series. - #889

Merged
beorn7 merged 3 commits into
masterfrom
monotonicity
Jul 16, 2015
Merged

beorn7 merged 3 commits into
masterfrom
monotonicity

Conversation

@juliusv

@juliusv juliusv commented Jul 12, 2015

Copy link
Copy Markdown
Member

Fixes #481

@juliusv

juliusv commented Jul 12, 2015

Copy link
Copy Markdown
Member Author

@beorn7

@juliusv
juliusv force-pushed the monotonicity branch 3 times, most recently from acdfc3e to e741a20 Compare July 12, 2015 15:02
Comment thread storage/local/persistence.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd opt for putting same types in the same row – but whatever you prefer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I actually prefer having them aligned under each other for legibility. Not strongly, but will keep it as is for now :)

@fabxc

fabxc commented Jul 12, 2015

Copy link
Copy Markdown
Contributor

I recently started prefixing commit messages with the name of the mainly affected subsystem/package. I think it improves searching for specific changes significantly if we did it consistently.

@fabxc

fabxc commented Jul 12, 2015

Copy link
Copy Markdown
Contributor

Looks good.

@juliusv

juliusv commented Jul 12, 2015

Copy link
Copy Markdown
Member Author

Changed the commit message. I feel like the prefixes are mostly good, but I'm ambivalent about making them mandatory. The one obvious downside is that adding them leaves even fewer characters before reaching the recommended 50-char limit for the first line (http://stackoverflow.com/questions/2290016/git-commit-messages-50-72-formatting). Like right now, I'm stepping over it already :)

@juliusv

juliusv commented Jul 12, 2015

Copy link
Copy Markdown
Member Author

Other question would be: what prefix (if any) to use for cross-cutting changes that touch all/multiple parts?

@matthiasr

matthiasr commented Jul 12, 2015 via email

Copy link
Copy Markdown
Contributor

Comment thread storage/local/doubledelta.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't capitalize error messages.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm, some other panics in this file are capitalized too, others not. Will lower-case them all.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Did that and also inserted another panic in delta.go where there was a similar comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Weird, I thought golint would catch capitalized panic messages.

Comment thread storage/local/storage.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a fairly expensive operation. It involves locking the timestamp and creation of a chunk iterator.
And this is the hottest spot in the code, i.e. almost all appends will go through this.
We need to remember the last append time in the series object (and probably want to include it in the checkpoint, too).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, good point. Append benchmarks show that this goes from 2us to 2.4us per op with this added, so it's definitely relevant.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Plus the allocation churn for the chunk iterator... up to 360,000 times per second... ;)

@beorn7

beorn7 commented Jul 13, 2015

Copy link
Copy Markdown
Contributor

We probably do not have to save the latest timestamp in the checkpoint, but we should have in in the series object and populate it upon load from the checkpointed head chunk (with the expensive operation currently in the normal code, this code path will then only executed once per time series upon startup).

Crash recovery needs updates, too, for that.

@juliusv

juliusv commented Jul 13, 2015

Copy link
Copy Markdown
Member Author

@beorn7 Changed this cache the last time in the series. That field is already reconstructed in memory when loading a checkpoint.

I haven't touched crash recovery yet, and probably there should also be a test for the new feature in the checkpoint loading. Feel free to push over this branch (and eventually merge) while I'm on vacation...

Comment thread storage/local/crashrecovery.go Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added clientmodel.Earliest here to make it compile for now - haven't checked yet what it really should be in this context.

@beorn7

beorn7 commented Jul 13, 2015

Copy link
Copy Markdown
Contributor

OK, I'm taking this over.

@beorn7
beorn7 force-pushed the monotonicity branch 4 times, most recently from 6147c72 to 6fa0862 Compare July 15, 2015 16:56
Fixes #481

While doing so, clean up and fix a few other things:

- Fix `go vet` warnings (@fabxc to blame ;).

- Fix a racey problem with unarchiving: Whenever we unarchive a
  series, we essentially want to do something with it. However, until
  we have done something with it, it appears like a series that is
  ready to be archived or even purged. So e.g. it would be ignored
  during checkpointing. With this fix, we always load the chunkDescs
  upon unarchiving. This is wasteful if we only want to add a new
  sample to an archived time series, but the (presumably more common)
  case where we access an archived time series in a query doesn't
  become more expensive.

- The change above streamlined the getOrCreateSeries ond
  newMemorySeries flow. Also, the modTime is now always set correctly.

- Fix the leveldb-backed implementation of KeyValueStore.Delete. It
  had the wrong behavior of still returning true, nil if a
  non-existing key has been passed in.
@beorn7

beorn7 commented Jul 15, 2015

Copy link
Copy Markdown
Contributor

@fabxc This is ready for review now. As @juliusv is on vacation, I delegate to you.

About the package prefix in commit messages: It breaks the common practice of starting a commit message with a verb in imperative form. Not that I would feel strongly personally. But it means our convention would fight a very established Git convention.

Comment thread storage/local/index/leveldb.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not Has(k, l.readOpts)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because I'm stupid... :)

@fabxc

fabxc commented Jul 16, 2015

Copy link
Copy Markdown
Contributor

Picking up the question of whether there can be two samples with the same timestamp:

In our current understanding of the world there is only one state at any given time (advanced physics put aside). The time series we collect are thus an approximation of a function over time.
Having multiple samples for the same timestamps requires us to apply an interpretation of this data to approximate a function. We now have to agree on a valid interpretation – do we average the samples? does the last added sample overwrite the previous one? It's hard to answer this question without knowing the reason for having multiple samples with the same timestamp.

The easiest solution is to simply not ingest a sample for a time at which we already have a sample.
Once we implement backfilling we can deal with cases where we want to overwrite samples.

@beorn7

beorn7 commented Jul 16, 2015

Copy link
Copy Markdown
Contributor

Yeah, overwriting is hard as we so far maintained append-only semantics...

If we enforce strict monotonicity, the bug I have found cannot happen anymore. (See #880 .) I still think my fix makes the code simpler and more robust, so we should keep it. Just my test doesn't work anymore, because it created samples with the same timestamp.

So I could remove my commit that allowed non-strict monotonicity and modify my test in #880 . Thought?

@fabxc

fabxc commented Jul 16, 2015

Copy link
Copy Markdown
Contributor

Sounds good.

Comment thread storage/local/storage_test.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we set the Value to i so down below it is clearer which sample was actually inserted?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Done.

@fabxc

fabxc commented Jul 16, 2015

Copy link
Copy Markdown
Contributor

👍

beorn7 added a commit that referenced this pull request Jul 16, 2015
Ensure timestamp monotonicity within a series.
@beorn7
beorn7 merged commit 82e2fd8 into master Jul 16, 2015
@beorn7
beorn7 deleted the monotonicity branch July 16, 2015 10:55
charleskorn pushed a commit to charleskorn/prometheus that referenced this pull request Jun 24, 2025
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