11use std:: {
22 cell:: RefCell ,
33 collections:: { BinaryHeap , HashSet , VecDeque } ,
4- sync:: Arc , vec,
4+ sync:: Arc ,
5+ vec,
56} ;
67
78use ahash:: HashMap ;
@@ -27,7 +28,10 @@ use parking_lot::RwLock;
2728
2829use crate :: {
2930 apps:: hnsw:: measurements:: { value_distance, HnswMetric , Metric , MetricEncoding } ,
30- graph:: { format_vertex_cell, id_list:: IdList , partitioner:: DefaultPartitioner , vertex:: Vertex , EdgeDirection , GraphEngine , NeighbourhoodError } ,
31+ graph:: {
32+ format_vertex_cell, id_list:: IdList , partitioner:: DefaultPartitioner , vertex:: Vertex ,
33+ EdgeDirection , GraphEngine , NeighbourhoodError ,
34+ } ,
3135 job:: {
3236 logger:: { append_job_log, JobLogLevel , JobLogger } ,
3337 JobId ,
@@ -380,36 +384,46 @@ impl HnswOnlinePartition {
380384 let schema_id = schema. id ;
381385 let ed = EdgeDirection :: Undirected ;
382386 for id in selected_vertex_ids {
383- let neighbours = match engine
384- . node_local_neighbour_id_and_edge ( id, schema_id, ed) {
385- Ok ( neighbours) => neighbours,
386- Err ( NeighbourhoodError :: IdListError ( IdListError :: ContainerCellNotReady ) ) if !readonly => vec ! [ ] ,
387- Err ( NeighbourhoodError :: IdListError ( IdListError :: ContainerCellNotReady ) ) => {
388- // If the container cell is not ready, we need to prepare the it
389- let field_id = ed. as_field ( ) ;
390- let _ = engine. graph_transaction ( DefaultPartitioner , move |txn| {
391- let mut list = IdList :: from_txn_and_container ( & txn. neb_txn , * id, field_id, schema_id) ;
387+ let neighbours = match engine. node_local_neighbour_id_and_edge ( id, schema_id, ed) {
388+ Ok ( neighbours) => neighbours,
389+ Err ( NeighbourhoodError :: IdListError ( IdListError :: ContainerCellNotReady ) )
390+ if !readonly =>
391+ {
392+ vec ! [ ]
393+ }
394+ Err ( NeighbourhoodError :: IdListError ( IdListError :: ContainerCellNotReady ) ) => {
395+ // If the container cell is not ready, we need to prepare the it
396+ let field_id = ed. as_field ( ) ;
397+ let _ = engine
398+ . graph_transaction ( DefaultPartitioner , move |txn| {
399+ let mut list = IdList :: from_txn_and_container (
400+ & txn. neb_txn ,
401+ * id,
402+ field_id,
403+ schema_id,
404+ ) ;
392405 async move {
393406 list. ensure_list ( ) . await ;
394407 Ok ( ( ) )
395408 }
396- } ) . await ;
397- vec ! [ ]
398- }
399- Err ( e) => {
400- append_job_log (
401- logger,
402- job_id,
403- JobLogLevel :: Error ,
404- format ! (
405- "Neighbourhood error to get neighbours for vertex {:?}: {:?}" ,
406- id, e
407- ) ,
408- ) ;
409- return Err ( HNSWIndexError :: NeighbourhoodError ( e) ) ;
410- }
409+ } )
410+ . await ;
411+ vec ! [ ]
412+ }
413+ Err ( e) => {
414+ append_job_log (
415+ logger,
416+ job_id,
417+ JobLogLevel :: Error ,
418+ format ! (
419+ "Neighbourhood error to get neighbours for vertex {:?}: {:?}" ,
420+ id, e
421+ ) ,
422+ ) ;
423+ return Err ( HNSWIndexError :: NeighbourhoodError ( e) ) ;
424+ }
411425 } ;
412- let new_frontiers = neighbours
426+ let new_frontiers = neighbours
413427 . into_iter ( )
414428 . map ( |( id, _) | id) // Only take the opposite id
415429 . collect :: < Vec < _ > > ( ) ;
@@ -630,10 +644,11 @@ impl HnswOnlinePartition {
630644
631645 visited. insert ( current_vertex) ;
632646 // Get all neighbors of the current vertex
633- match self
634- . engine
635- . node_local_neighbour_id_and_edge ( & current_vertex, level_schema, EdgeDirection :: Undirected )
636- {
647+ match self . engine . node_local_neighbour_id_and_edge (
648+ & current_vertex,
649+ level_schema,
650+ EdgeDirection :: Undirected ,
651+ ) {
637652 Ok ( neighbors) => {
638653 for ( neighbor_id, _) in neighbors {
639654 let is_local = self . conshash . get_server_id ( neighbor_id. higher )
@@ -649,15 +664,21 @@ impl HnswOnlinePartition {
649664 logger,
650665 job_id,
651666 JobLogLevel :: Info ,
652- format ! ( "Container cell not ready for vertex {:?}, skipping" , current_vertex) ,
667+ format ! (
668+ "Container cell not ready for vertex {:?}, skipping" ,
669+ current_vertex
670+ ) ,
653671 ) ;
654- } ,
672+ }
655673 Err ( e) => {
656674 append_job_log (
657675 logger,
658676 job_id,
659677 JobLogLevel :: Error ,
660- format ! ( "Error getting neighbours for vertex {:?}: {:?}" , current_vertex, e) ,
678+ format ! (
679+ "Error getting neighbours for vertex {:?}: {:?}" ,
680+ current_vertex, e
681+ ) ,
661682 ) ;
662683 }
663684 }
@@ -885,6 +906,17 @@ impl HnswOnlinePartition {
885906 ) ;
886907
887908 // Connect the new vertex to its selected neighbors
909+ append_job_log (
910+ logger,
911+ job_id,
912+ JobLogLevel :: Info ,
913+ format ! (
914+ "Going to connect {} neighbors for vertex {:?} at level {}" ,
915+ selected_neighbors. len( ) ,
916+ vertex_id,
917+ level
918+ ) ,
919+ ) ;
888920 for neighbor_id in & selected_neighbors {
889921 // Create bidirectional edges
890922 match engine
@@ -1119,10 +1151,11 @@ impl HnswOnlinePartition {
11191151 }
11201152
11211153 // Get neighbors of current vertex
1122- match self
1123- . engine
1124- . node_local_neighbour_id_and_edge ( & current_vertex, level_schema, EdgeDirection :: Undirected )
1125- {
1154+ match self . engine . node_local_neighbour_id_and_edge (
1155+ & current_vertex,
1156+ level_schema,
1157+ EdgeDirection :: Undirected ,
1158+ ) {
11261159 Ok ( neighbors) => {
11271160 for ( neighbor_id, _) in neighbors {
11281161 // Only process vertices from this partition
0 commit comments