-
Notifications
You must be signed in to change notification settings - Fork 578
Add an option to spread indexing pipelines over time #6655
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
Open
loutPhilipps
wants to merge
4
commits into
main
Choose a base branch
from
lout.philipps/byoc/add-spread-indexing-pipelines-option
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,7 @@ use tracing::{Span, debug, info_span, warn}; | |
| use ulid::Ulid; | ||
|
|
||
| use super::IndexSerializer; | ||
| use super::cooperative_indexing::{CooperativeIndexingCycle, CooperativeIndexingPeriod}; | ||
| use super::indexing_cycle::{IndexingCycle, IndexingPeriod}; | ||
| use crate::docs_clustering::{DocIdClusterer, Fingerprinter}; | ||
| use crate::metrics::SPLIT_BUILDERS; | ||
| use crate::models::{ | ||
|
|
@@ -84,7 +84,8 @@ pub struct IndexerCounters { | |
| pub num_doc_batches_in_workbench: u64, | ||
|
|
||
| /// Metrics describing the load and indexing performance of the | ||
| /// pipeline. This is only updated for cooperative indexers. | ||
| /// pipeline. This is only updated for cooperative indexers or | ||
| /// when indexing pipeline spreading is enabled. | ||
| pub pipeline_metrics_opt: Option<PipelineMetrics>, | ||
| } | ||
|
|
||
|
|
@@ -100,7 +101,7 @@ struct IndexerState { | |
| tokenizer_manager: TokenizerManager, | ||
| max_num_partitions: NonZeroU32, | ||
| index_settings: IndexSettings, | ||
| cooperative_indexing_opt: Option<CooperativeIndexingCycle>, | ||
| indexing_cycle_opt: Option<IndexingCycle>, | ||
| } | ||
|
|
||
| impl IndexerState { | ||
|
|
@@ -199,15 +200,11 @@ impl IndexerState { | |
| workbench_id=%workbench_id, | ||
| ); | ||
| let indexing_span = info_span!(parent: batch_parent_span.id(), "indexer"); | ||
| let cooperative_indexing_period = | ||
| if let Some(cooperative_indexing) = &self.cooperative_indexing_opt { | ||
| Some( | ||
| ctx.protect_future(cooperative_indexing.cooperative_indexing_period()) | ||
| .await, | ||
| ) | ||
| } else { | ||
| None | ||
| }; | ||
| let indexing_period_opt = if let Some(indexing_cycle) = &self.indexing_cycle_opt { | ||
| Some(ctx.protect_future(indexing_cycle.indexing_period()).await) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| let last_delete_opstamp_request = LastDeleteOpstampRequest { | ||
| index_uid: Some(self.pipeline_id.index_uid.clone()), | ||
|
|
@@ -239,7 +236,7 @@ impl IndexerState { | |
| publish_lock, | ||
| last_delete_opstamp, | ||
| memory_usage: GaugeGuard::new(&IN_FLIGHT_INDEX_WRITER, 0.0), | ||
| cooperative_indexing_period, | ||
| indexing_period_opt, | ||
| split_builders_guard, | ||
| }; | ||
| Ok(workbench) | ||
|
|
@@ -290,7 +287,7 @@ impl IndexerState { | |
| .get_or_create_workbench(indexing_workbench_opt, ctx) | ||
| .await?; | ||
| if publish_lock.is_dead() { | ||
| // Release indexing permit early. | ||
| // Release indexing permit early if there is one. | ||
| indexing_workbench_opt.take(); | ||
| return Ok(()); | ||
| } | ||
|
|
@@ -366,7 +363,7 @@ struct IndexingWorkbench { | |
| // Number of bytes declared as used by tantivy. | ||
| memory_usage: GaugeGuard, | ||
| split_builders_guard: GaugeGuard, | ||
| cooperative_indexing_period: Option<CooperativeIndexingPeriod>, | ||
| indexing_period_opt: Option<IndexingPeriod>, | ||
| } | ||
|
|
||
| pub struct Indexer { | ||
|
|
@@ -402,8 +399,8 @@ impl Actor for Indexer { | |
| } | ||
|
|
||
| async fn initialize(&mut self, ctx: &ActorContext<Self>) -> Result<(), ActorExitStatus> { | ||
| if let Some(cooperative_indexing_cycle) = &self.indexer_state.cooperative_indexing_opt { | ||
| let initial_sleep_duration = cooperative_indexing_cycle.initial_sleep_duration(); | ||
| if let Some(indexing_cycle) = &self.indexer_state.indexing_cycle_opt { | ||
| let initial_sleep_duration = indexing_cycle.initial_sleep_duration(); | ||
| ctx.pause(); | ||
| ctx.schedule_self_msg(initial_sleep_duration, Command::Resume); | ||
| } | ||
|
|
@@ -418,9 +415,7 @@ impl Actor for Indexer { | |
| return Ok(()); | ||
| }; | ||
|
|
||
| let Some(cooperative_indexing_period) = | ||
| indexing_workbench.cooperative_indexing_period.take() | ||
| else { | ||
| let Some(indexing_period) = indexing_workbench.indexing_period_opt.take() else { | ||
| return Ok(()); | ||
| }; | ||
|
|
||
|
|
@@ -430,9 +425,9 @@ impl Actor for Indexer { | |
| .map(|split| split.split_attrs.uncompressed_docs_size_in_bytes) | ||
| .sum::<u64>(); | ||
|
|
||
| // This also drops the indexing permit. | ||
| // This also drops the indexing permit, if any. | ||
| let (sleep_duration, pipeline_metrics) = | ||
| cooperative_indexing_period.end_of_work(uncompressed_num_bytes); | ||
| indexing_period.end_of_work(uncompressed_num_bytes); | ||
|
|
||
| self.counters.pipeline_metrics_opt = Some(pipeline_metrics); | ||
|
|
||
|
|
@@ -532,6 +527,7 @@ impl Indexer { | |
| indexing_directory: TempDirectory, | ||
| indexing_settings: IndexingSettings, | ||
| cooperative_indexing_permits_opt: Option<Arc<Semaphore>>, | ||
| spread_indexing_pipelines: bool, | ||
| index_serializer_mailbox: Mailbox<IndexSerializer>, | ||
| fingerprinter_opt: Option<Fingerprinter>, | ||
| ) -> Self { | ||
|
|
@@ -548,12 +544,12 @@ impl Indexer { | |
| // A configured fingerprinter supplies the mapping when the split is finalized. | ||
| manual_doc_id_mapping: fingerprinter_opt.is_some(), | ||
| }; | ||
| let cooperative_indexing_opt: Option<CooperativeIndexingCycle> = | ||
| cooperative_indexing_permits_opt.map(|cooperative_indexing_permits| { | ||
| CooperativeIndexingCycle::new( | ||
| let indexing_cycle_opt: Option<IndexingCycle> = | ||
| (spread_indexing_pipelines || cooperative_indexing_permits_opt.is_some()).then(|| { | ||
| IndexingCycle::new( | ||
|
loutPhilipps marked this conversation as resolved.
|
||
| &pipeline_id, | ||
| indexing_settings.commit_timeout(), | ||
| cooperative_indexing_permits, | ||
| cooperative_indexing_permits_opt, | ||
| ) | ||
| }); | ||
|
Comment on lines
+547
to
554
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where we enable the |
||
| Self { | ||
|
|
@@ -569,7 +565,7 @@ impl Indexer { | |
| tokenizer_manager: tokenizer_manager.tantivy_manager().clone(), | ||
| index_settings, | ||
| max_num_partitions: doc_mapper.max_num_partitions(), | ||
| cooperative_indexing_opt, | ||
| indexing_cycle_opt, | ||
| }, | ||
| index_serializer_mailbox, | ||
| indexing_workbench_opt: None, | ||
|
|
@@ -778,6 +774,7 @@ mod tests { | |
| indexing_directory, | ||
| indexing_settings, | ||
| None, | ||
| false, | ||
| index_serializer_mailbox, | ||
| None, | ||
| ); | ||
|
|
@@ -919,6 +916,7 @@ mod tests { | |
| indexing_directory, | ||
| indexing_settings, | ||
| None, | ||
| false, | ||
| index_serializer_mailbox, | ||
| None, | ||
| ); | ||
|
|
@@ -997,6 +995,7 @@ mod tests { | |
| indexing_directory, | ||
| indexing_settings, | ||
| None, | ||
| false, | ||
| index_serializer_mailbox, | ||
| None, | ||
| ); | ||
|
|
@@ -1081,6 +1080,7 @@ mod tests { | |
| indexing_directory, | ||
| indexing_settings, | ||
| Some(Arc::new(Semaphore::new(1))), | ||
| false, | ||
| index_serializer_mailbox, | ||
| None, | ||
| ); | ||
|
|
@@ -1170,6 +1170,7 @@ mod tests { | |
| indexing_directory, | ||
| indexing_settings, | ||
| None, | ||
| false, | ||
| index_serializer_mailbox, | ||
| None, | ||
| ); | ||
|
|
@@ -1238,6 +1239,7 @@ mod tests { | |
| TempDirectory::for_test(), | ||
| IndexingSettings::for_test(), | ||
| None, | ||
| false, | ||
| index_serializer_mailbox, | ||
| Some(Fingerprinter::new( | ||
| &serde_json::from_value::<DocsClusteringConfig>(serde_json::json!([ | ||
|
|
@@ -1358,6 +1360,7 @@ mod tests { | |
| indexing_directory, | ||
| indexing_settings, | ||
| None, | ||
| false, | ||
| index_serializer_mailbox, | ||
| None, | ||
| ); | ||
|
|
@@ -1457,6 +1460,7 @@ mod tests { | |
| indexing_directory, | ||
| indexing_settings, | ||
| None, | ||
| false, | ||
| index_serializer_mailbox, | ||
| None, | ||
| ); | ||
|
|
@@ -1530,6 +1534,7 @@ mod tests { | |
| indexing_directory, | ||
| indexing_settings, | ||
| None, | ||
| false, | ||
| index_serializer_mailbox, | ||
| None, | ||
| ); | ||
|
|
@@ -1604,6 +1609,7 @@ mod tests { | |
| indexing_directory, | ||
| indexing_settings, | ||
| None, | ||
| false, | ||
| index_serializer_mailbox, | ||
| None, | ||
| ); | ||
|
|
@@ -1670,6 +1676,7 @@ mod tests { | |
| indexing_directory, | ||
| indexing_settings, | ||
| None, | ||
| false, | ||
| index_serializer_mailbox, | ||
| None, | ||
| ); | ||
|
|
@@ -1740,6 +1747,7 @@ mod tests { | |
| indexing_directory, | ||
| indexing_settings, | ||
| None, | ||
| false, | ||
| index_serializer_mailbox, | ||
| None, | ||
| ); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make that an environment flag? (the goal is just to make it as light as possible).