1818// along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
2020use std:: collections:: { HashMap , HashSet } ;
21+ use std:: fmt:: Debug ;
2122use std:: path:: PathBuf ;
2223use std:: sync:: Arc ;
2324
@@ -36,66 +37,26 @@ use quickwit_config::{
3637 build_doc_mapper, IndexConfig , IndexerConfig , SourceConfig , INGEST_API_SOURCE_ID ,
3738} ;
3839use quickwit_ingest:: { DropQueueRequest , IngestApiService , ListQueuesRequest , QUEUES_DIR_NAME } ;
39- use quickwit_metastore:: { IndexMetadata , Metastore , MetastoreError } ;
40- use quickwit_proto:: indexing:: { ApplyIndexingPlanRequest , IndexingTask } ;
41- use quickwit_proto:: { IndexUid , ServiceError , ServiceErrorCode } ;
42- use quickwit_storage:: { StorageError , StorageResolver , StorageResolverError } ;
40+ use quickwit_metastore:: { IndexMetadata , Metastore } ;
41+ use quickwit_proto:: indexing:: { ApplyIndexingPlanRequest , ApplyIndexingPlanResponse , IndexingTask } ;
42+ use quickwit_proto:: indexing_api:: { IndexingPipelineId , IndexingServiceError } ;
43+ use quickwit_proto:: IndexUid ;
44+ use quickwit_storage:: StorageResolver ;
4345use serde:: { Deserialize , Serialize } ;
44- use thiserror:: Error ;
4546use tokio:: sync:: Semaphore ;
4647use tracing:: { debug, error, info, warn} ;
4748
4849use super :: merge_pipeline:: { MergePipeline , MergePipelineParams } ;
4950use super :: MergePlanner ;
5051use crate :: models:: {
51- DetachIndexingPipeline , DetachMergePipeline , IndexingPipelineId , Observe , ObservePipeline ,
52- SpawnPipeline ,
52+ DetachIndexingPipeline , DetachMergePipeline , Observe , ObservePipeline , SpawnPipeline ,
5353} ;
5454use crate :: split_store:: { LocalSplitStore , SplitStoreQuota } ;
5555use crate :: { IndexingPipeline , IndexingPipelineParams , IndexingSplitStore , IndexingStatistics } ;
5656
5757/// Name of the indexing directory, usually located at `<data_dir_path>/indexing`.
5858pub const INDEXING_DIR_NAME : & str = "indexing" ;
5959
60- #[ derive( Error , Debug ) ]
61- pub enum IndexingServiceError {
62- #[ error( "Indexing pipeline `{index_id}` for source `{source_id}` does not exist." ) ]
63- MissingPipeline { index_id : String , source_id : String } ,
64- #[ error(
65- "Pipeline #{pipeline_ord} for index `{index_id}` and source `{source_id}` already exists."
66- ) ]
67- PipelineAlreadyExists {
68- index_id : String ,
69- source_id : String ,
70- pipeline_ord : usize ,
71- } ,
72- #[ error( "Failed to resolve the storage `{0}`." ) ]
73- StorageResolverError ( #[ from] StorageResolverError ) ,
74- #[ error( "Storage error `{0}`." ) ]
75- StorageError ( #[ from] StorageError ) ,
76- #[ error( "Metastore error `{0}`." ) ]
77- MetastoreError ( #[ from] MetastoreError ) ,
78- #[ error( "Invalid params `{0}`." ) ]
79- InvalidParams ( anyhow:: Error ) ,
80- #[ error( "Spanw pipelines errors `{pipeline_ids:?}`." ) ]
81- SpawnPipelinesError {
82- pipeline_ids : Vec < IndexingPipelineId > ,
83- } ,
84- }
85-
86- impl ServiceError for IndexingServiceError {
87- fn status_code ( & self ) -> ServiceErrorCode {
88- match self {
89- Self :: MissingPipeline { .. } => ServiceErrorCode :: NotFound ,
90- Self :: PipelineAlreadyExists { .. } => ServiceErrorCode :: BadRequest ,
91- Self :: StorageResolverError ( _) | Self :: StorageError ( _) => ServiceErrorCode :: Internal ,
92- Self :: MetastoreError ( _) => ServiceErrorCode :: Internal ,
93- Self :: InvalidParams ( _) => ServiceErrorCode :: BadRequest ,
94- Self :: SpawnPipelinesError { .. } => ServiceErrorCode :: Internal ,
95- }
96- }
97- }
98-
9960#[ derive( Clone , Debug , Default , Eq , PartialEq , Serialize , Deserialize ) ]
10061pub struct IndexingServiceCounters {
10162 pub num_running_pipelines : usize ,
@@ -142,6 +103,17 @@ pub struct IndexingService {
142103 cooperative_indexing_permits : Option < Arc < Semaphore > > ,
143104}
144105
106+ impl Debug for IndexingService {
107+ fn fmt ( & self , formatter : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
108+ formatter
109+ . debug_struct ( "IndexingService" )
110+ . field ( "cluster_id" , & self . cluster . cluster_id ( ) )
111+ . field ( "self_node_id" , & self . node_id )
112+ . field ( "indexing_root_directory" , & self . indexing_root_directory )
113+ . finish ( )
114+ }
115+ }
116+
145117impl IndexingService {
146118 #[ allow( clippy:: too_many_arguments) ]
147119 pub async fn new (
@@ -271,11 +243,12 @@ impl IndexingService {
271243 . join ( & pipeline_id. source_id )
272244 . join ( & pipeline_id. pipeline_ord . to_string ( ) )
273245 . tempdir_in ( & self . indexing_root_directory )
274- . map_err ( |error| IndexingServiceError :: StorageError ( error . into ( ) ) ) ?;
246+ . map_err ( IndexingServiceError :: Io ) ?;
275247 let storage = self
276248 . storage_resolver
277249 . resolve ( & index_config. index_uri )
278- . await ?;
250+ . await
251+ . map_err ( |err| IndexingServiceError :: StorageResolverError ( err. to_string ( ) ) ) ?;
279252 let merge_policy =
280253 crate :: merge_policy:: merge_policy_from_settings ( & index_config. indexing_settings ) ;
281254 let split_store = IndexingSplitStore :: new ( storage. clone ( ) , self . local_split_store . clone ( ) ) ;
@@ -336,7 +309,11 @@ impl IndexingService {
336309 index_id : & str ,
337310 ) -> Result < IndexMetadata , IndexingServiceError > {
338311 let _protect_guard = ctx. protect_zone ( ) ;
339- let index_metadata = self . metastore . index_metadata ( index_id) . await ?;
312+ let index_metadata = self
313+ . metastore
314+ . index_metadata ( index_id)
315+ . await
316+ . map_err ( |err| IndexingServiceError :: MetastoreError ( err. to_string ( ) ) ) ?;
340317 Ok ( index_metadata)
341318 }
342319
@@ -440,7 +417,7 @@ impl IndexingService {
440417 & mut self ,
441418 ctx : & ActorContext < Self > ,
442419 physical_indexing_plan_request : ApplyIndexingPlanRequest ,
443- ) -> Result < ( ) , IndexingServiceError > {
420+ ) -> Result < ApplyIndexingPlanResponse , IndexingServiceError > {
444421 let mut updated_pipeline_ids: HashSet < IndexingPipelineId > = HashSet :: new ( ) ;
445422 let mut pipeline_ordinals: HashMap < & IndexingTask , usize > = HashMap :: new ( ) ;
446423 for indexing_task in physical_indexing_plan_request. indexing_tasks . iter ( ) {
@@ -484,7 +461,7 @@ impl IndexingService {
484461 } ) ;
485462 }
486463
487- Ok ( ( ) )
464+ Ok ( ApplyIndexingPlanResponse { } )
488465 }
489466
490467 /// Spawns the pipelines with supplied ids and returns a list of failed pipelines.
@@ -757,7 +734,7 @@ impl Handler<Observe> for IndexingService {
757734
758735#[ async_trait]
759736impl Handler < ApplyIndexingPlanRequest > for IndexingService {
760- type Reply = Result < ( ) , IndexingServiceError > ;
737+ type Reply = Result < ApplyIndexingPlanResponse , IndexingServiceError > ;
761738
762739 async fn handle (
763740 & mut self ,
0 commit comments