Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Properly initialize head time #339

Merged
merged 1 commit into from
Aug 2, 2018
Merged

Properly initialize head time #339

merged 1 commit into from
Aug 2, 2018

Conversation

fabxc
Copy link
Contributor

@fabxc fabxc commented May 29, 2018

This fixes various issues when initializing the head time range
under different starting conditions.

Depends on #332

@krasi-georgiev as promised
@jkohen FYI as it depends on the new WAL stuff, but probably not too interesting for you

Copy link
Contributor

@krasi-georgiev krasi-georgiev left a comment

Choose a reason for hiding this comment

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

LGTM with just few comments

if atomic.CompareAndSwapInt64(&h.minTime, lt, mint) {
break
}
}
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 these in a loops and not if else blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because CompareAndSwap can fail and we have to retry it then.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks! I always thought these are blocking until they succeed.

@@ -183,7 +183,7 @@ func NewHead(r prometheus.Registerer, l log.Logger, wal *wal.WAL, chunkRange int
wal: wal,
logger: l,
chunkRange: chunkRange,
minTime: math.MinInt64,
minTime: math.MaxInt64,
maxTime: math.MinInt64,
Copy link
Contributor

Choose a reason for hiding this comment

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

When I read the code later down I understand why minTime=MaxInt64 and maxTime=MinInt64 , but do you think some comments here might make it less confusing why these are reversed?

@@ -200,17 +200,17 @@ func NewHead(r prometheus.Registerer, l log.Logger, wal *wal.WAL, chunkRange int
// them on to other workers.
// Samples before the mint timestamp are discarded.
Copy link
Contributor

Choose a reason for hiding this comment

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

// Samples before the minValidTime timestamp are discarded.

@@ -462,10 +482,7 @@ func (h *Head) Truncate(mint int64) error {
// for a compltely fresh head with an empty WAL.
Copy link
Contributor

Choose a reason for hiding this comment

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

compltely -> completely

mint, maxt int64
head *Head
minValidTime int64 // No samples below this timestamp are allowed.
mint, maxt int64

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe some comments why we need separate mint and minValidTime ?

db_test.go Outdated
@@ -1011,3 +1013,109 @@ func TestOverlappingBlocksDetectsAllOverlaps(t *testing.T) {
{Min: 8, Max: 9}: {nc1[8], nc1[9]}, // 7-10, 8-9
}, OverlappingBlocks(nc1))
}

func TestInitializeHeadTimestamp(t *testing.T) {
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 test be in head_test.go?

Copy link
Contributor

Choose a reason for hiding this comment

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

actually there is already a head test where you can just add few lines similar to what I did in the other PR
https://github.com/prometheus/tsdb/pull/334/files#diff-0dc7b53c06c14aba584e5b4d6986fa07R96

Copy link
Contributor Author

@fabxc fabxc Jun 1, 2018

Choose a reason for hiding this comment

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

The test covers cases with existing blocks, which is beyond the scope of Head. DB has to startup correctly and make some calls of Head's methods in the right order and with the right arguments. That's nothing we can test with an isolated Head.

defer os.RemoveAll(dir)

db, err := Open(dir, nil, nil, nil)
testutil.Ok(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

can't we use the openTestDB helper?

Copy link
Contributor

Choose a reason for hiding this comment

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

looking it again it is the same number of lines so all the same.

This fixes various issues when initializing the head time range
under different starting conditions.

Signed-off-by: Fabian Reinartz <[email protected]>
@fabxc
Copy link
Contributor Author

fabxc commented Jul 19, 2018

Rebased and resolved conflicts.

@brian-brazil
Copy link
Contributor

👍

@fabxc fabxc merged commit a9a8fab into newwal Aug 2, 2018
@fabxc fabxc deleted the inittime branch August 2, 2018 21:54
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