/* * FileRepPrimary_StartResyncWorker() */ void FileRepPrimary_StartResyncWorker(void) { int status = STATUS_OK; FileRep_InsertConfigLogEntry("start resync worker"); Insist(fileRepRole == FileRepPrimaryRole); while (1) { if (status != STATUS_OK) { FileRep_SetSegmentState(SegmentStateFault, FaultTypeMirror); FileRepSubProcess_SetState(FileRepStateFault); } /* * We are waiting for following conditions to move forward: * * Database is running * And * if dataState is InResync, we wait for FileRepSubProcess to Ready state * else don't wait */ while (!isDatabaseRunning() || !(dataState == DataStateInResync ? FileRepSubProcess_GetState() == FileRepStateReady : true)) { FileRepSubProcess_ProcessSignals(); if (FileRepSubProcess_GetState() == FileRepStateShutdown || FileRepSubProcess_GetState() == FileRepStateShutdownBackends) { break; } pg_usleep(50000L); /* 50 ms */ } if (FileRepSubProcess_GetState() == FileRepStateShutdown || FileRepSubProcess_GetState() == FileRepStateShutdownBackends) { break; } FileRepSubProcess_InitHeapAccess(); status = FileRepPrimary_RunResyncWorker(); if (status != STATUS_OK) { continue; } break; } // while(1) }
/* * * FileRepPrimary_RunChangeTrackingCompacting() * */ static void FileRepPrimary_RunChangeTrackingCompacting(void) { int retry = 0; FileRep_InsertConfigLogEntry("run change tracking compacting if records has to be discarded"); /* * We have to check if any records have to be discarded from Change Tracking log file. * Due to crash it can happen that the highest change tracking log lsn > the highest xlog lsn. * * Records from change tracking log file can be discarded only after database is started. * Full environhment has to be set up in order to run queries over SPI. */ while (FileRepSubProcess_GetState() != FileRepStateShutdown && FileRepSubProcess_GetState() != FileRepStateShutdownBackends && isDatabaseRunning() == FALSE) { FileRepSubProcess_ProcessSignals(); pg_usleep(50000L); /* 50 ms */ } ChangeTracking_DoFullCompactingRoundIfNeeded(); /* * Periodically check if compacting is required. * Periodic compacting is required in order to * a) reduce space for change tracking log file * b) reduce time for transition from Change Tracking to Resync */ FileRep_InsertConfigLogEntry("run change tracking compacting"); while (1) { FileRepSubProcess_ProcessSignals(); while (FileRepSubProcess_GetState() == FileRepStateFault || segmentState == SegmentStateChangeTrackingDisabled) { FileRepSubProcess_ProcessSignals(); pg_usleep(50000L); /* 50 ms */ } if (! (FileRepSubProcess_GetState() == FileRepStateReady && dataState == DataStateInChangeTracking)) { break; } Insist(fileRepRole == FileRepPrimaryRole); Insist(dataState == DataStateInChangeTracking); Insist(FileRepSubProcess_GetState() == FileRepStateReady); /* retry compacting of change tracking log files once per minute */ pg_usleep(50000L); /* 50 ms */ if (++retry == 1200) { ChangeTracking_CompactLogsIfPossible(); retry=0; } } }