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

cloud_storage: use remote index in cloud timequery #13011

Merged

Conversation

VladLazar
Copy link
Contributor

@VladLazar VladLazar commented Aug 25, 2023

This PR updates the timequery read path to skip up to the first
index entry with a timestamp smaller than the searched one. The result
is that timequeries will hydrate/materialize a maximum of two chunks
(two because the chunk boundaries don't always line up with the entries
in the index).

If the index is not present, or was originally created in v1, the search
starts from the first chunk as it did previously.

Fixes #11801

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.2.x
  • v23.1.x
  • v22.3.x

Release Notes

Improvements

  • Timequeries (i.e ListOffsets requests) that land in the cloud log now use an index to speed up the search
    and reduce the number of hydrated bytes required to serve the query. On average, a time query will have to download 4 times less data (if using the default segment and chunk size)

A lookup by timestamp is added to the remote index. It has the same
semantics as the other lookup methods. If the index does not include the
time index (i.e. it was created with serde version 1), the search comes
up empty.
@VladLazar VladLazar requested review from abhijat and Lazin August 25, 2023 12:15
@VladLazar VladLazar force-pushed the use-index-in-cloud-timequery branch from ea3677a to 78454bf Compare August 25, 2023 12:17
Lazin
Lazin previously approved these changes Aug 25, 2023
Copy link
Contributor

@Lazin Lazin left a comment

Choose a reason for hiding this comment

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

LGTM if CI is happy

@VladLazar
Copy link
Contributor Author

Changes in force-push:

  • fix TimeQueryKafkaTest

@VladLazar VladLazar requested a review from Lazin August 25, 2023 15:46
Copy link
Member

@dotnwat dotnwat left a comment

Choose a reason for hiding this comment

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

🔥 🚒

@@ -184,6 +184,58 @@ offset_index::find_kaf_offset(kafka::offset upper_bound) {
return res;
}

std::optional<offset_index::find_result>
offset_index::find_timestamp(model::timestamp upper_bound) {
if (_initial_time == model::timestamp::missing()) {
Copy link
Member

Choose a reason for hiding this comment

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

it's a bummer that -1 is used to indicate missing timestamp. That -1 carries so much additional baggage in Kafka for example by indicating something specific in time queries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's not ideal. Not much we can do about it now though. The -1 is already encoded in a released Serde version.

src/v/cloud_storage/remote_segment_index.cc Outdated Show resolved Hide resolved
@@ -315,18 +315,18 @@ remote_segment::offset_data_stream(
offset_index::find_result pos;
std::optional<uint16_t> prefetch_override = std::nullopt;
if (first_timestamp) {
Copy link
Member

Choose a reason for hiding this comment

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

is it odd that first_timestamp wasn't used in this conditional before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

first_timestamp indicates that this is a time-query. By this point, we have already resolved to the correct segment for the time query. Since we didn't previously used the index, it makes senes that first_timestamp wasn't used (we'd just start from the beginning of the segment).

src/v/cloud_storage/remote_segment.cc Outdated Show resolved Hide resolved
Vlad Lazar added 3 commits August 29, 2023 11:26
This commit updates the timequery read path to skip up to the first
index entry with a timestamp smaller than the searched one. The result
is that timequeries will hydrate/materialize a maximum of two chunks
(two because the chunk boundaries don't always line up with the entries
in the index).

If the index is not present, or was originally created in v1, the search
starts from the first chunk as it did previously.
A shard-level metric is added to track the total number of chunks that
were hydrated (i.e. downloaded).
This commit makes a couple of changes to the timequery tests:
1. Run timequery on more offests (10 for each of the 12 segments)
2. Check that a maximum of two chunks are downloaded by any given
   timequery
3. Use the admin api to get the precise boundary between the cloud and
   local log. Previously, it was estimated based on record size.
@VladLazar VladLazar force-pushed the use-index-in-cloud-timequery branch 2 times, most recently from 604d114 to c5df897 Compare August 29, 2023 10:42
@VladLazar VladLazar requested review from dotnwat and abhijat August 29, 2023 10:43
@VladLazar VladLazar force-pushed the use-index-in-cloud-timequery branch from c5df897 to 6314700 Compare August 29, 2023 13:01
This commit refactors the handling of the index search result. If a new
result type is introduced, it's author will be reminded to handle it by
the assertions.
@VladLazar VladLazar force-pushed the use-index-in-cloud-timequery branch from 6314700 to de5aa53 Compare August 29, 2023 14:06
@VladLazar
Copy link
Contributor Author

@piyushredpanda piyushredpanda merged commit dab7b6a into redpanda-data:dev Aug 29, 2023
@vbotbuildovich
Copy link
Collaborator

/backport v23.2.x

@vbotbuildovich
Copy link
Collaborator

Failed to run cherry-pick command. I executed the commands below:

git checkout -b backport-pr-13011-v23.2.x-222 remotes/upstream/v23.2.x
git cherry-pick -x c1d03142dc993eb31d6ce67c7468fa83bdb31145 da8533ba5bd255fe41286e0d44013d60d93082d8 b78d7113406e05fade4975d76ee3efcc5b36dbf3 6d507cd0e3ee4849c531ff9e7bb3f2a90553b4e9 de5aa5345cd2449bb484be658574c3ab7a44d4ca

Workflow run logs.

@VladLazar
Copy link
Contributor Author

/backport v23.2.x

@vbotbuildovich
Copy link
Collaborator

Failed to run cherry-pick command. I executed the commands below:

git checkout -b backport-pr-13011-v23.2.x-593 remotes/upstream/v23.2.x
git cherry-pick -x c1d03142dc993eb31d6ce67c7468fa83bdb31145 da8533ba5bd255fe41286e0d44013d60d93082d8 b78d7113406e05fade4975d76ee3efcc5b36dbf3 6d507cd0e3ee4849c531ff9e7bb3f2a90553b4e9 de5aa5345cd2449bb484be658574c3ab7a44d4ca

Workflow run logs.

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

Successfully merging this pull request may close these issues.

cloud_storage: more efficient timequery
6 participants