Skip to content

Ingest samples older than 1h for block store - #3025

Closed
codesome wants to merge 17 commits into
cortexproject:masterfrom
codesome:ingest-ooold-v2
Closed

codesome wants to merge 17 commits into
cortexproject:masterfrom
codesome:ingest-ooold-v2

Conversation

@codesome

@codesome codesome commented Aug 12, 2020 •

Copy link
Copy Markdown
Contributor

What this PR does:

Supersedes #2819. I chose to open a new PR so that I can have the old one as reference for some parts.

This implements the updated design as described in #2366 (comment)

Which issue(s) this PR fixes:
Fixes #2366

  • Ingest samples older than 1h
  • Reload TSDBs on restart
  • Query samples from older TSDBs
  • Support query stream over old TSDBs
  • Automatically cleanup old TSDBs
  • Add metrics for counting backfill TSDBs open, errors in shipping/deleting, etc
  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

TODO in future PRs

  • Metrics from new TSDBs
  • Limits on the additional TSDB
  • Automatically cleanup stale TSDBs

Ganesh Vernekar added 3 commits August 11, 2020 19:28
@codesome
codesome marked this pull request as draft August 12, 2020 13:29
// and shipped and dbs[0] is moved to dbs[1]. During this process,
// there is only 1 TSDB ingesting old data, so there can be gaps till the compaction
// and shipping is going on.
// TODO(codesome): Avoid gaps by using a separate queue to compact and ship blocks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not for this PR

Ganesh Vernekar added 2 commits August 13, 2020 16:15
Signed-off-by: Ganesh Vernekar <[email protected]>
Signed-off-by: Ganesh Vernekar <[email protected]>
@codesome
codesome force-pushed the ingest-ooold-v2 branch 2 times, most recently from d67173e to 6d68cb6 Compare August 13, 2020 13:52
Ganesh Vernekar added 2 commits August 24, 2020 17:40

@pstibrany pstibrany left a 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.

This code is quite difficult to digest for me. I'm wondering what would help me to understand it better:

  • Avoid backward-dependancies from new types to ingester if possible. In general, if type A creates instances of type B, then B should not need to know about A: instead A needs to pass everything that B needs to it. I know ingester code doesn't always fit into this. :(

  • I think naming-wise, dbs[0] and dbs[1] can perhaps be improved (eg. "older", "newer"?)

  • repeated 1-hour check wasn't clear to me at first.

I need to spend more time with this PR to fully understand all the details. It seems like it would work, but it adds a lot of complexity too.

Comment thread pkg/ingester/ingester_v2.go Resolved
Comment thread pkg/ingester/ingester_v2.go Resolved
Comment thread pkg/ingester/ingester_v2.go Resolved
Comment thread pkg/ingester/ingester_v2.go Resolved
Comment thread pkg/ingester/ingester_v2_backfill.go Resolved
startTime := model.Time(start).Time().UTC()
endTime := model.Time(end).Time().UTC()

return fmt.Sprintf(

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.

"<start>-<end>" as unix timestamps may be easier to work with

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In case we have to debug, would it not be easier if the name told the exact hours without needing a manual translation? (thinking of the case where there might be multiple backfill TSDBs piled up due to various reasons).

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.

Yes, that's true, although there is a lot of precedent for unix timestamps at many places – eg. min/max time in meta.json of TSDB block, even block ID (ULID) has embedded timestamp in it. Your choice, this isn't a showstopper for me.

Comment thread pkg/ingester/ingester_v2_backfill.go Resolved
Comment thread pkg/ingester/ingester_v2_backfill.go Resolved
@codesome

Copy link
Copy Markdown
Contributor Author

I think naming-wise, dbs[0] and dbs[1] can perhaps be improved (eg. "older", "newer"?)

That was the first thing I tried. But it turned out to be a lot of duplicated code and maybe also makes it harder to approach the review. So I resorted to using an array and use the index to generalise the code. I will check again if explicit variable could be used after some simplifications now (and maybe more comments for context).

@codesome codesome changed the title WIP: Ingest samples older than 1h for block store Ingest samples older than 1h for block store Aug 25, 2020
@codesome
codesome marked this pull request as ready for review August 25, 2020 10:37
Signed-off-by: Ganesh Vernekar <[email protected]>
@codesome

Copy link
Copy Markdown
Contributor Author

Avoid backward-dependancies from new types to ingester if possible. In general, if type A creates instances of type B, then B should not need to know about A: instead A needs to pass everything that B needs to it. I know ingester code doesn't always fit into this. :(

Need the ingester in backfillAppender only for ingester.createNewTSDB and ingester.cfg.BlocksStorageConfig.TSDB.BackfillBlocksDir. We could potentially keep those methods with backfillTSDB and use it from there instead of keeping the ingester around.

Ganesh Vernekar added 2 commits August 25, 2020 20:50
Signed-off-by: Ganesh Vernekar <[email protected]>
Signed-off-by: Ganesh Vernekar <[email protected]>
Comment thread pkg/ingester/ingester_v2_backfill.go Resolved
Comment thread pkg/ingester/metrics.go Resolved
Comment thread pkg/ingester/metrics.go Resolved
Comment thread pkg/ingester/metrics.go Resolved
Comment thread pkg/ingester/metrics.go Resolved
Comment thread pkg/ingester/ingester_v2.go Resolved
Comment thread pkg/ingester/ingester_v2.go Resolved
Comment thread pkg/ingester/ingester_v2_backfill.go Resolved
Comment thread pkg/ingester/ingester_v2_backfill.go Outdated
}

// Fast path to not take the lock.
if a.newerAppender != nil && s.TimestampMs >= a.newerAppender.start && s.TimestampMs < a.newerAppender.end {

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.

Is it safe to access a.newerAppender and a.olderAppender, given their references may be replaced any time (and when they're replaced, a lock is used)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's safe. Note that it is 1 appender per v2Push call and not shared across multiple push. The idea here is that the goroutine which is getting the appender will use it sequentially (which is the case in v2Push, each sample is iterated sequentially). So, while the DBs can be started in parallel which is protected by the lock, it is safe to access newerAppender and olderAppender without lock as they are the part of the appender and not the backfillTSDB.

Comment thread pkg/ingester/ingester_v2_backfill.go Resolved
}
startAppend := time.Now()

cachedRef, cachedRefExists := db.refCache.Ref(startAppend, client.FromLabelAdaptersToLabels(la))

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.

To my understanding, db.refCache is shared across all TSDBs (main + 2 backfill) but is it safe to be shared?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The backfill TSDBs themselves are userTSDB and have their own refCache (each backfill TSDB getting one). They don't have any access to the main TSDB.

Signed-off-by: Ganesh Vernekar <[email protected]>
Signed-off-by: Ganesh Vernekar <[email protected]>
Comment thread pkg/ingester/ingester_v2_backfill.go Outdated

// We could use RLock here to check the TSDBs, but because we create new TSDB if none exists,
// it's easier and cleaner to handle races by taking the write lock.
// TODO(codesome): IMPORTANT: fix the issue where the compaction moves the TSDB around between 2 appends to avoid using wrong appenders in older and newer spots.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Regarding this // TODO(codesome): IMPORTANT: fix the issue where the compaction moves the TSDB around between 2 appends to avoid using wrong appenders in older and newer spots., I think this is fine with a check for the appender being nil to not overwrite it and lose data.

Reasons:

  1. If the older TSDB moved (i.e. outside of backfill age), that means the sample is not eligible anyway for ingestion as it went out of backfill age. So it is fine to fail the append.
  2. If the newer TSDB moved to the older spot, the new appender will be for the same TSDB as before and wont be an issue ingesting to it if the sample falls in that TSDB.
  3. If the newer TSDB moved to the older spot and the new sample incoming belongs to the newer TSDB to be created, then we fail that append here which will be retried later.

So, no data loss because of the re-try of Prometheus remote-write. This is a tradeoff for a whole lot complexity it would bring to handle moving appenders with TSDBs. If it turns out to be a problem, we can iterate on it later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will update the comment (with TODO) explaining the case and that it is fine.

Signed-off-by: Ganesh Vernekar <[email protected]>
@stale

stale Bot commented Nov 7, 2020

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had any activity in the past 60 days. It will be closed in 15 days if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label Nov 7, 2020
@pracucci

pracucci commented Nov 9, 2020

Copy link
Copy Markdown
Contributor

Still super valid. Offline discussions are on-going.

@stale

stale Bot commented Jan 8, 2021

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had any activity in the past 60 days. It will be closed in 15 days if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label Jan 8, 2021
@codesome

Copy link
Copy Markdown
Contributor Author

Nope nope, still valid

@stale stale Bot removed the stale label Jan 18, 2021
@pracucci

Copy link
Copy Markdown
Contributor

Closing for now, since we're currently considering a different solution.

@pracucci pracucci closed this Feb 25, 2021
@dilipkk-foyernet

dilipkk-foyernet commented Aug 11, 2021 •

Copy link
Copy Markdown

@pracucci can you please share any information about the new solution for backfilling the data which older than 1h into the cortex?
I was wondering if this will work or not. Please let me know your opinion on it.

Thanks,
Dilip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blocks storage unable to ingest samples older than 1h after an outage

4 participants