@@ -863,6 +863,11 @@ pub trait MetaStore: DIService + Send + Sync {
863863 ) -> Result < Vec < IdRow < Partition > > , CubeError > ;
864864 async fn get_index ( & self , index_id : u64 ) -> Result < IdRow < Index > , CubeError > ;
865865
866+ async fn get_index_with_active_partitions_out_of_queue (
867+ & self ,
868+ index_id : u64 ,
869+ ) -> Result < ( IdRow < Index > , Vec < IdRow < Partition > > ) , CubeError > ;
870+
866871 async fn create_partitioned_index (
867872 & self ,
868873 schema : String ,
@@ -927,6 +932,7 @@ pub trait MetaStore: DIService + Send + Sync {
927932 max : Option < Row > ,
928933 in_memory : bool ,
929934 ) -> Result < IdRow < Chunk > , CubeError > ;
935+ async fn insert_chunks ( & self , chunks : Vec < Chunk > ) -> Result < Vec < IdRow < Chunk > > , CubeError > ;
930936 async fn get_chunk ( & self , chunk_id : u64 ) -> Result < IdRow < Chunk > , CubeError > ;
931937 async fn get_chunks_out_of_queue ( & self , ids : Vec < u64 > ) -> Result < Vec < IdRow < Chunk > > , CubeError > ;
932938 async fn get_partitions_out_of_queue (
@@ -1046,11 +1052,11 @@ pub trait MetaStore: DIService + Send + Sync {
10461052 async fn all_replay_handles_to_merge (
10471053 & self ,
10481054 ) -> Result < Vec < ( IdRow < ReplayHandle > , bool ) > , CubeError > ;
1049- async fn update_replay_handle_failed (
1055+ async fn update_replay_handle_failed_if_exists (
10501056 & self ,
10511057 id : u64 ,
10521058 failed : bool ,
1053- ) -> Result < IdRow < ReplayHandle > , CubeError > ;
1059+ ) -> Result < ( ) , CubeError > ;
10541060 async fn replace_replay_handles (
10551061 & self ,
10561062 old_ids : Vec < u64 > ,
@@ -2909,6 +2915,28 @@ impl MetaStore for RocksMetaStore {
29092915 . await
29102916 }
29112917
2918+ async fn get_index_with_active_partitions_out_of_queue (
2919+ & self ,
2920+ index_id : u64 ,
2921+ ) -> Result < ( IdRow < Index > , Vec < IdRow < Partition > > ) , CubeError > {
2922+ self . read_operation_out_of_queue ( move |db_ref| {
2923+ let index = IndexRocksTable :: new ( db_ref. clone ( ) ) . get_row_or_not_found ( index_id) ?;
2924+ let rocks_partition = PartitionRocksTable :: new ( db_ref) ;
2925+
2926+ let partitions = rocks_partition
2927+ . get_rows_by_index (
2928+ & PartitionIndexKey :: ByIndexId ( index. get_id ( ) ) ,
2929+ & PartitionRocksIndex :: IndexId ,
2930+ ) ?
2931+ . into_iter ( )
2932+ . filter ( |r| r. get_row ( ) . active )
2933+ . collect :: < Vec < _ > > ( ) ;
2934+
2935+ Ok ( ( index, partitions) )
2936+ } )
2937+ . await
2938+ }
2939+
29122940 #[ tracing:: instrument( level = "trace" , skip( self , key_columns) ) ]
29132941 async fn create_partitioned_index (
29142942 & self ,
@@ -3086,6 +3114,22 @@ impl MetaStore for RocksMetaStore {
30863114 . await
30873115 }
30883116
3117+ #[ tracing:: instrument( level = "trace" , skip( self , chunks) ) ]
3118+ async fn insert_chunks ( & self , chunks : Vec < Chunk > ) -> Result < Vec < IdRow < Chunk > > , CubeError > {
3119+ self . write_operation ( move |db_ref, batch_pipe| {
3120+ let rocks_chunk = ChunkRocksTable :: new ( db_ref. clone ( ) ) ;
3121+ let mut result = Vec :: with_capacity ( chunks. len ( ) ) ;
3122+
3123+ for chunk in chunks. into_iter ( ) {
3124+ let id_row = rocks_chunk. insert ( chunk, batch_pipe) ?;
3125+ result. push ( id_row) ;
3126+ }
3127+
3128+ Ok ( result)
3129+ } )
3130+ . await
3131+ }
3132+
30893133 #[ tracing:: instrument( level = "trace" , skip( self ) ) ]
30903134 async fn get_chunk ( & self , chunk_id : u64 ) -> Result < IdRow < Chunk > , CubeError > {
30913135 self . read_operation ( move |db_ref| {
@@ -3723,17 +3767,18 @@ impl MetaStore for RocksMetaStore {
37233767 }
37243768
37253769 #[ tracing:: instrument( level = "trace" , skip( self ) ) ]
3726- async fn update_replay_handle_failed (
3770+ async fn update_replay_handle_failed_if_exists (
37273771 & self ,
37283772 id : u64 ,
37293773 failed : bool ,
3730- ) -> Result < IdRow < ReplayHandle > , CubeError > {
3774+ ) -> Result < ( ) , CubeError > {
37313775 self . write_operation ( move |db_ref, batch_pipe| {
3732- Ok ( ReplayHandleRocksTable :: new ( db_ref. clone ( ) ) . update_with_fn (
3733- id,
3734- |h| h. set_failed_to_persist_chunks ( failed) ,
3735- batch_pipe,
3736- ) ?)
3776+ let table = ReplayHandleRocksTable :: new ( db_ref. clone ( ) ) ;
3777+ if table. get_row ( id) ?. is_some ( ) {
3778+ table. update_with_fn ( id, |h| h. set_failed_to_persist_chunks ( failed) , batch_pipe) ?;
3779+ }
3780+
3781+ Ok ( ( ) )
37373782 } )
37383783 . await
37393784 }
@@ -3759,10 +3804,11 @@ impl MetaStore for RocksMetaStore {
37593804 & ChunkRocksIndex :: ReplayHandleId ,
37603805 ) ?;
37613806
3762- if !chunks. is_empty ( ) {
3807+ let active_chunks = chunks. iter ( ) . filter ( |c| c. get_row ( ) . active ( ) || !c. get_row ( ) . uploaded ( ) ) . collect :: < Vec < _ > > ( ) ;
3808+ if !active_chunks. is_empty ( ) {
37633809 return Err ( CubeError :: internal ( format ! (
3764- "Can't merge replay handle with chunks: {:?}" ,
3765- replay_handle
3810+ "Can't merge replay handle with chunks: {:?}, {} " ,
3811+ replay_handle, active_chunks [ 0 ] . get_id ( )
37663812 ) ) )
37673813 }
37683814
@@ -3811,7 +3857,9 @@ impl MetaStore for RocksMetaStore {
38113857 ) ?;
38123858 result. push ( (
38133859 replay_handle,
3814- chunks. iter ( ) . filter ( |c| c. get_row ( ) . active ( ) ) . count ( ) == 0 ,
3860+ chunks
3861+ . iter ( )
3862+ . all ( |c| !c. get_row ( ) . active ( ) && c. get_row ( ) . uploaded ( ) ) ,
38153863 ) ) ;
38163864 }
38173865 Ok ( result)
0 commit comments