8282#endif
8383
8484bool gp_count_host_segments_using_address = false;
85+ bool gp_dispatch_on_mirrors = false;
8586MemoryContext CdbComponentsContext = NULL ;
8687static CdbComponentDatabases * cdb_component_dbs = NULL ;
8788
@@ -92,6 +93,7 @@ static CdbComponentDatabases *getCdbComponentInfo(void);
9293static void cleanupComponentIdleQEs (CdbComponentDatabaseInfo * cdi , bool includeWriter );
9394
9495static int CdbComponentDatabaseInfoCompare (const void * p1 , const void * p2 );
96+ static int CdbComponentDatabaseInfoComparem (const void * p1 , const void * p2 );
9597
9698static GpSegConfigEntry * readGpSegConfigFromCatalog (int * total_dbs );
9799static GpSegConfigEntry * readGpSegConfigFromFTSFiles (int * total_dbs );
@@ -439,10 +441,20 @@ getCdbComponentInfo(void)
439441 pRow -> numIdleQEs = 0 ;
440442 pRow -> numActiveQEs = 0 ;
441443
442- if (config -> role != GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY ||
443- (gp_count_host_segments_using_address &&
444- (config -> hostip == NULL || strlen (config -> hostip ) == 0 )))
445- continue ;
444+ if (gp_dispatch_on_mirrors )
445+ {
446+ if (config -> role != GP_SEGMENT_CONFIGURATION_ROLE_MIRROR ||
447+ (gp_count_host_segments_using_address &&
448+ (config -> hostip == NULL || strlen (config -> hostip ) == 0 )))
449+ continue ;
450+ }
451+ else
452+ {
453+ if (config -> role != GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY ||
454+ (gp_count_host_segments_using_address &&
455+ (config -> hostip == NULL || strlen (config -> hostip ) == 0 )))
456+ continue ;
457+ }
446458
447459 hsEntry = (HostSegsEntry * ) hash_search (hostSegsHash ,
448460 gp_count_host_segments_using_address ? config -> hostip : config -> hostname ,
@@ -474,14 +486,26 @@ getCdbComponentInfo(void)
474486 /*
475487 * Now sort the data by segindex, isprimary desc
476488 */
477- qsort (component_databases -> segment_db_info ,
478- component_databases -> total_segment_dbs , sizeof (CdbComponentDatabaseInfo ),
479- CdbComponentDatabaseInfoCompare );
489+ if (gp_dispatch_on_mirrors )
490+ {
491+ qsort (component_databases -> segment_db_info ,
492+ component_databases -> total_segment_dbs , sizeof (CdbComponentDatabaseInfo ),
493+ CdbComponentDatabaseInfoComparem );
480494
481- qsort (component_databases -> entry_db_info ,
482- component_databases -> total_entry_dbs , sizeof (CdbComponentDatabaseInfo ),
483- CdbComponentDatabaseInfoCompare );
495+ qsort (component_databases -> entry_db_info ,
496+ component_databases -> total_entry_dbs , sizeof (CdbComponentDatabaseInfo ),
497+ CdbComponentDatabaseInfoComparem );
498+ }
499+ else
500+ {
501+ qsort (component_databases -> segment_db_info ,
502+ component_databases -> total_segment_dbs , sizeof (CdbComponentDatabaseInfo ),
503+ CdbComponentDatabaseInfoCompare );
484504
505+ qsort (component_databases -> entry_db_info ,
506+ component_databases -> total_entry_dbs , sizeof (CdbComponentDatabaseInfo ),
507+ CdbComponentDatabaseInfoCompare );
508+ }
485509 /*
486510 * Now count the number of distinct segindexes. Since it's sorted, this is
487511 * easy.
@@ -558,10 +582,20 @@ getCdbComponentInfo(void)
558582 {
559583 cdbInfo = & component_databases -> segment_db_info [i ];
560584
561- if (cdbInfo -> config -> role != GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY ||
562- (gp_count_host_segments_using_address &&
563- (cdbInfo -> config -> hostip == NULL || strlen (cdbInfo -> config -> hostip ) == 0 )))
564- continue ;
585+ if (gp_dispatch_on_mirrors )
586+ {
587+ if (cdbInfo -> config -> role != GP_SEGMENT_CONFIGURATION_ROLE_MIRROR ||
588+ (gp_count_host_segments_using_address &&
589+ (cdbInfo -> config -> hostip == NULL || strlen (cdbInfo -> config -> hostip ) == 0 )))
590+ continue ;
591+ }
592+ else
593+ {
594+ if (cdbInfo -> config -> role != GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY ||
595+ (gp_count_host_segments_using_address &&
596+ (cdbInfo -> config -> hostip == NULL || strlen (cdbInfo -> config -> hostip ) == 0 )))
597+ continue ;
598+ }
565599
566600 hsEntry = (HostSegsEntry * ) hash_search (hostSegsHash ,
567601 gp_count_host_segments_using_address ? cdbInfo -> config -> hostip : cdbInfo -> config -> hostname ,
@@ -575,10 +609,20 @@ getCdbComponentInfo(void)
575609 {
576610 cdbInfo = & component_databases -> entry_db_info [i ];
577611
578- if (cdbInfo -> config -> role != GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY ||
579- (gp_count_host_segments_using_address &&
580- (cdbInfo -> config -> hostip == NULL || strlen (cdbInfo -> config -> hostip ) == 0 )))
581- continue ;
612+ if (gp_dispatch_on_mirrors )
613+ {
614+ if (cdbInfo -> config -> role != GP_SEGMENT_CONFIGURATION_ROLE_MIRROR ||
615+ (gp_count_host_segments_using_address &&
616+ (cdbInfo -> config -> hostip == NULL || strlen (cdbInfo -> config -> hostip ) == 0 )))
617+ continue ;
618+ }
619+ else
620+ {
621+ if (cdbInfo -> config -> role != GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY ||
622+ (gp_count_host_segments_using_address &&
623+ (cdbInfo -> config -> hostip == NULL || strlen (cdbInfo -> config -> hostip ) == 0 )))
624+ continue ;
625+ }
582626
583627 hsEntry = (HostSegsEntry * ) hash_search (hostSegsHash ,
584628 gp_count_host_segments_using_address ? cdbInfo -> config -> hostip : cdbInfo -> config -> hostname ,
@@ -693,6 +737,9 @@ cdbcomponent_updateCdbComponents(void)
693737
694738 PG_TRY ();
695739 {
740+ if (gp_dispatch_on_mirrors ) {
741+ cdb_component_dbs = NULL ;
742+ }
696743 if (cdb_component_dbs == NULL )
697744 {
698745 cdb_component_dbs = getCdbComponentInfo ();
@@ -742,7 +789,7 @@ cdbcomponent_getCdbComponents()
742789{
743790 PG_TRY ();
744791 {
745- if (cdb_component_dbs == NULL )
792+ if (cdb_component_dbs == NULL || gp_dispatch_on_mirrors )
746793 {
747794 cdb_component_dbs = getCdbComponentInfo ();
748795 cdb_component_dbs -> fts_version = getFtsVersion ();
@@ -847,7 +894,9 @@ cdbcomponent_allocateIdleQE(int contentId, SegmentType segmentType)
847894 * 1. for entrydb, it's never be writer.
848895 * 2. for first QE, it must be a writer.
849896 */
897+ /*XXX: what if gp_dispatch_on_mirrors?*/
850898 isWriter = contentId == -1 ? false: (cdbinfo -> numIdleQEs == 0 && cdbinfo -> numActiveQEs == 0 );
899+
851900 segdbDesc = cdbconn_createSegmentDescriptor (cdbinfo , nextQEIdentifer (cdbinfo -> cdbs ), isWriter );
852901 }
853902
@@ -1041,11 +1090,20 @@ cdbcomponent_getComponentInfo(int contentId)
10411090 Assert (cdbs -> total_segment_dbs == cdbs -> total_segments * 2 );
10421091 cdbInfo = & cdbs -> segment_db_info [2 * contentId ];
10431092
1044- if (! SEGMENT_IS_ACTIVE_PRIMARY ( cdbInfo ) )
1093+ if (gp_dispatch_on_mirrors )
10451094 {
1046- cdbInfo = & cdbs -> segment_db_info [2 * contentId + 1 ];
1095+ if (!SEGMENT_IS_ACTIVE_MIRROR (cdbInfo ))
1096+ {
1097+ cdbInfo = & cdbs -> segment_db_info [2 * contentId + 1 ];
1098+ }
1099+ }
1100+ else
1101+ {
1102+ if (!SEGMENT_IS_ACTIVE_PRIMARY (cdbInfo ))
1103+ {
1104+ cdbInfo = & cdbs -> segment_db_info [2 * contentId + 1 ];
1105+ }
10471106 }
1048-
10491107 return cdbInfo ;
10501108 }
10511109
@@ -1228,6 +1286,31 @@ CdbComponentDatabaseInfoCompare(const void *p1, const void *p2)
12281286 return cmp ;
12291287}
12301288
1289+ static int
1290+ CdbComponentDatabaseInfoComparem (const void * p1 , const void * p2 )
1291+ {
1292+ const CdbComponentDatabaseInfo * obj1 = (CdbComponentDatabaseInfo * ) p1 ;
1293+ const CdbComponentDatabaseInfo * obj2 = (CdbComponentDatabaseInfo * ) p2 ;
1294+
1295+ int cmp = obj1 -> config -> segindex - obj2 -> config -> segindex ;
1296+
1297+ if (cmp == 0 )
1298+ {
1299+ int obj2cmp = 0 ;
1300+ int obj1cmp = 0 ;
1301+
1302+ if (SEGMENT_IS_ACTIVE_MIRROR (obj2 ))
1303+ obj2cmp = 1 ;
1304+
1305+ if (SEGMENT_IS_ACTIVE_MIRROR (obj1 ))
1306+ obj1cmp = 1 ;
1307+
1308+ cmp = obj2cmp - obj1cmp ;
1309+ }
1310+
1311+ return cmp ;
1312+ }
1313+
12311314/*
12321315 * Maintain a cache of names.
12331316 *
0 commit comments