53
53
-define (MNESIA_SEMI_DURABLE_TABLE , rabbit_semi_durable_route ).
54
54
-define (MNESIA_REVERSE_TABLE , rabbit_reverse_route ).
55
55
-define (MNESIA_INDEX_TABLE , rabbit_index_route ).
56
+ -define (KHEPRI_BINDINGS_PROJECTION , rabbit_khepri_bindings ).
57
+ -define (KHEPRI_INDEX_ROUTE_PROJECTION , rabbit_khepri_index_route ).
56
58
57
59
% % -------------------------------------------------------------------
58
60
% % exists().
@@ -411,7 +413,12 @@ get_all_in_mnesia() ->
411
413
end ).
412
414
413
415
get_all_in_khepri () ->
414
- [B || # route {binding = B } <- ets :tab2list (rabbit_khepri_bindings )].
416
+ case ets :whereis (? KHEPRI_BINDINGS_PROJECTION ) of
417
+ undefined ->
418
+ [];
419
+ Table ->
420
+ [B || # route {binding = B } <- ets :tab2list (Table )]
421
+ end .
415
422
416
423
-spec get_all (VHostName ) -> [Binding ] when
417
424
VHostName :: vhost :name (),
@@ -437,11 +444,16 @@ get_all_in_mnesia(VHost) ->
437
444
[B || # route {binding = B } <- rabbit_db :list_in_mnesia (? MNESIA_TABLE , Match )].
438
445
439
446
get_all_in_khepri (VHost ) ->
440
- VHostResource = rabbit_misc :r (VHost , '_' ),
441
- Match = # route {binding = # binding {source = VHostResource ,
442
- destination = VHostResource ,
443
- _ = '_' }},
444
- [B || # route {binding = B } <- ets :match_object (rabbit_khepri_bindings , Match )].
447
+ case ets :whereis (? KHEPRI_BINDINGS_PROJECTION ) of
448
+ undefined ->
449
+ [];
450
+ Table ->
451
+ VHostResource = rabbit_misc :r (VHost , '_' ),
452
+ Match = # route {binding = # binding {source = VHostResource ,
453
+ destination = VHostResource ,
454
+ _ = '_' }},
455
+ [B || # route {binding = B } <- ets :match_object (Table , Match )]
456
+ end .
445
457
446
458
-spec get_all (Src , Dst , Reverse ) -> [Binding ] when
447
459
Src :: rabbit_types :binding_source (),
@@ -469,10 +481,15 @@ get_all_in_mnesia(SrcName, DstName, Reverse) ->
469
481
mnesia :async_dirty (Fun ).
470
482
471
483
get_all_in_khepri (SrcName , DstName ) ->
472
- MatchHead = # route {binding = # binding {source = SrcName ,
473
- destination = DstName ,
474
- _ = '_' }},
475
- [B || # route {binding = B } <- ets :match_object (rabbit_khepri_bindings , MatchHead )].
484
+ case ets :whereis (? KHEPRI_BINDINGS_PROJECTION ) of
485
+ undefined ->
486
+ [];
487
+ Table ->
488
+ MatchHead = # route {binding = # binding {source = SrcName ,
489
+ destination = DstName ,
490
+ _ = '_' }},
491
+ [B || # route {binding = B } <- ets :match_object (Table , MatchHead )]
492
+ end .
476
493
477
494
% % -------------------------------------------------------------------
478
495
% % get_all_for_source().
@@ -511,8 +528,13 @@ list_for_route(Route, true) ->
511
528
end .
512
529
513
530
get_all_for_source_in_khepri (Resource ) ->
514
- Route = # route {binding = # binding {source = Resource , _ = '_' }},
515
- [B || # route {binding = B } <- ets :match_object (rabbit_khepri_bindings , Route )].
531
+ case ets :whereis (? KHEPRI_BINDINGS_PROJECTION ) of
532
+ undefined ->
533
+ [];
534
+ Table ->
535
+ Route = # route {binding = # binding {source = Resource , _ = '_' }},
536
+ [B || # route {binding = B } <- ets :match_object (Table , Route )]
537
+ end .
516
538
517
539
% % -------------------------------------------------------------------
518
540
% % get_all_for_destination().
@@ -541,9 +563,14 @@ get_all_for_destination_in_mnesia(Dst) ->
541
563
mnesia :async_dirty (Fun ).
542
564
543
565
get_all_for_destination_in_khepri (Destination ) ->
544
- Match = # route {binding = # binding {destination = Destination ,
545
- _ = '_' }},
546
- [B || # route {binding = B } <- ets :match_object (rabbit_khepri_bindings , Match )].
566
+ case ets :whereis (? KHEPRI_BINDINGS_PROJECTION ) of
567
+ undefined ->
568
+ [];
569
+ Table ->
570
+ Match = # route {binding = # binding {destination = Destination ,
571
+ _ = '_' }},
572
+ [B || # route {binding = B } <- ets :match_object (Table , Match )]
573
+ end .
547
574
548
575
% % -------------------------------------------------------------------
549
576
% % fold().
@@ -617,11 +644,16 @@ match_in_mnesia(SrcName, Match) ->
617
644
Routes , Match (Binding )].
618
645
619
646
match_in_khepri (SrcName , Match ) ->
620
- MatchHead = # route {binding = # binding {source = SrcName ,
621
- _ = '_' }},
622
- Routes = ets :select (rabbit_khepri_bindings , [{MatchHead , [], [['$_' ]]}]),
623
- [Dest || [# route {binding = Binding = # binding {destination = Dest }}] <-
624
- Routes , Match (Binding )].
647
+ case ets :whereis (? KHEPRI_BINDINGS_PROJECTION ) of
648
+ undefined ->
649
+ [];
650
+ Table ->
651
+ MatchHead = # route {binding = # binding {source = SrcName ,
652
+ _ = '_' }},
653
+ Routes = ets :select (Table , [{MatchHead , [], [['$_' ]]}]),
654
+ [Dest || [# route {binding = Binding = # binding {destination = Dest }}] <-
655
+ Routes , Match (Binding )]
656
+ end .
625
657
626
658
% % Routing - HOT CODE PATH
627
659
% % -------------------------------------------------------------------
@@ -654,18 +686,26 @@ match_routing_key_in_mnesia(SrcName, RoutingKeys, UseIndex) ->
654
686
route_in_mnesia_v1 (SrcName , RoutingKeys )
655
687
end .
656
688
657
- match_routing_key_in_khepri (Src , ['_' ]) ->
689
+ match_routing_key_in_khepri (Src , RoutingKeys ) ->
690
+ case ets :whereis (? KHEPRI_INDEX_ROUTE_PROJECTION ) of
691
+ undefined ->
692
+ [];
693
+ Table ->
694
+ do_match_routing_key_in_khepri (Table , Src , RoutingKeys )
695
+ end .
696
+
697
+ do_match_routing_key_in_khepri (Table , Src , ['_' ]) ->
658
698
MatchHead = # index_route {source_key = {Src , '_' },
659
699
destination = '$1' ,
660
700
_ = '_' },
661
- ets :select (rabbit_khepri_index_route , [{MatchHead , [], ['$1' ]}]);
701
+ ets :select (Table , [{MatchHead , [], ['$1' ]}]);
662
702
663
- match_routing_key_in_khepri ( Src , RoutingKeys ) ->
703
+ do_match_routing_key_in_khepri ( Table , Src , RoutingKeys ) ->
664
704
lists :foldl (
665
705
fun (RK , Acc ) ->
666
706
try
667
707
Dst = ets :lookup_element (
668
- rabbit_khepri_index_route ,
708
+ Table ,
669
709
{Src , RK },
670
710
# index_route .destination ),
671
711
Dst ++ Acc
0 commit comments