void FtsHandleNetFailure(SegmentDatabaseDescriptor ** segDB, int numOfFailed) { elog(LOG, "FtsHandleNetFailure: numOfFailed %d", numOfFailed); FtsReConfigureMPP(true); ereport(ERROR, (errmsg_internal("MPP detected %d segment failures, system is reconnected", numOfFailed), errSendAlert(true))); }
/* * Reads the GP catalog tables and build a CdbComponentDatabases structure. * It then converts this to a Gang structure and initializes all the non-connection related fields. * * Call this function in GangContext. * Returns a not-null pointer. */ Gang * buildGangDefinition(GangType type, int gang_id, int size, int content) { Gang *newGangDefinition = NULL; CdbComponentDatabaseInfo *cdbinfo = NULL; CdbComponentDatabaseInfo *cdbInfoCopy = NULL; SegmentDatabaseDescriptor *segdbDesc = NULL; MemoryContext perGangContext = NULL; int segCount = 0; int i = 0; ELOG_DISPATCHER_DEBUG("buildGangDefinition:Starting %d qExec processes for %s gang", size, gangTypeToString(type)); Assert(CurrentMemoryContext == GangContext); Assert(size == 1 || size == getgpsegmentCount()); /* read gp_segment_configuration and build CdbComponentDatabases */ cdb_component_dbs = getComponentDatabases(); if (cdb_component_dbs == NULL || cdb_component_dbs->total_segments <= 0 || cdb_component_dbs->total_segment_dbs <= 0) insist_log(false, "schema not populated while building segworker group"); /* if mirroring is not configured */ if (cdb_component_dbs->total_segment_dbs == cdb_component_dbs->total_segments) { ELOG_DISPATCHER_DEBUG("building Gang: mirroring not configured"); disableFTS(); } perGangContext = AllocSetContextCreate(GangContext, "Per Gang Context", ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE); Assert(perGangContext != NULL); MemoryContextSwitchTo(perGangContext); /* allocate a gang */ newGangDefinition = (Gang *) palloc0(sizeof(Gang)); newGangDefinition->type = type; newGangDefinition->size = size; newGangDefinition->gang_id = gang_id; newGangDefinition->allocated = false; newGangDefinition->noReuse = false; newGangDefinition->dispatcherActive = false; newGangDefinition->portal_name = NULL; newGangDefinition->perGangContext = perGangContext; newGangDefinition->db_descriptors = (SegmentDatabaseDescriptor *) palloc0(size * sizeof(SegmentDatabaseDescriptor)); /* initialize db_descriptors */ switch (type) { case GANGTYPE_ENTRYDB_READER: cdbinfo = &cdb_component_dbs->entry_db_info[0]; cdbInfoCopy = copyCdbComponentDatabaseInfo(cdbinfo); segdbDesc = &newGangDefinition->db_descriptors[0]; cdbconn_initSegmentDescriptor(segdbDesc, cdbInfoCopy); setQEIdentifier(segdbDesc, -1, perGangContext); break; case GANGTYPE_SINGLETON_READER: cdbinfo = findDatabaseInfoBySegIndex(cdb_component_dbs, content); cdbInfoCopy = copyCdbComponentDatabaseInfo(cdbinfo); segdbDesc = &newGangDefinition->db_descriptors[0]; cdbconn_initSegmentDescriptor(segdbDesc, cdbInfoCopy); setQEIdentifier(segdbDesc, -1, perGangContext); break; case GANGTYPE_PRIMARY_READER: case GANGTYPE_PRIMARY_WRITER: /* * We loop through the segment_db_info. Each item has a segindex. * They are sorted by segindex, and there can be > 1 segment_db_info for * a given segindex (currently, there can be 1 or 2) */ for (i = 0; i < cdb_component_dbs->total_segment_dbs; i++) { cdbinfo = &cdb_component_dbs->segment_db_info[i]; if (SEGMENT_IS_ACTIVE_PRIMARY(cdbinfo)) { segdbDesc = &newGangDefinition->db_descriptors[segCount]; cdbInfoCopy = copyCdbComponentDatabaseInfo(cdbinfo); cdbconn_initSegmentDescriptor(segdbDesc, cdbInfoCopy); setQEIdentifier(segdbDesc, -1, perGangContext); segCount++; } } if (size != segCount) { FtsReConfigureMPP(false); elog(ERROR, "Not all primary segment instances are active and connected"); } break; default: Assert(false); } ELOG_DISPATCHER_DEBUG("buildGangDefinition done"); MemoryContextSwitchTo(GangContext); return newGangDefinition; }