From 694ce55f455b77d6e53099a47b1db19e8b2f03d9 Mon Sep 17 00:00:00 2001 From: Ashwin Agrawal Date: Sat, 9 Dec 2017 12:08:13 -0800 Subject: [PATCH] Remove filerep resync backend code. --- src/backend/access/transam/xlog.c | 3 - src/backend/cdb/Makefile | 1 - src/backend/cdb/cdbfilerepprimary.c | 25 +- src/backend/cdb/cdbfilerepresyncmanager.c | 1942 ----------------- src/backend/cdb/cdbfilerepresyncworker.c | 812 ------- src/backend/cdb/cdbfilerepservice.c | 38 +- src/backend/cdb/cdbmirroredbufferpool.c | 13 +- src/backend/cdb/cdbpersistentfilesysobj.c | 42 - .../cdb/cdbresynchronizechangetracking.c | 5 - src/backend/postmaster/postmaster.c | 21 +- src/backend/storage/ipc/ipci.c | 3 - src/include/cdb/cdbfilerepresyncmanager.h | 112 - src/include/cdb/cdbfilerepresyncworker.h | 21 - 13 files changed, 14 insertions(+), 3024 deletions(-) delete mode 100644 src/backend/cdb/cdbfilerepresyncmanager.c delete mode 100644 src/backend/cdb/cdbfilerepresyncworker.c delete mode 100644 src/include/cdb/cdbfilerepresyncmanager.h delete mode 100644 src/include/cdb/cdbfilerepresyncworker.h diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 4c623e7a8d..e050bf16bc 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -78,7 +78,6 @@ #include "cdb/cdbtm.h" #include "cdb/cdbfilerep.h" -#include "cdb/cdbfilerepresyncmanager.h" #include "cdb/cdbvars.h" #include "cdb/cdbpersistentrelation.h" #include "cdb/cdbmirroredflatfile.h" @@ -10067,8 +10066,6 @@ CreateCheckPoint(int flags) { RequestXLogSwitch(); - FileRepResyncManager_ResyncFlatFiles(); - UpdateControlFile(); LWLockRelease(MirroredLock); diff --git a/src/backend/cdb/Makefile b/src/backend/cdb/Makefile index df7373da6f..5d7852033b 100644 --- a/src/backend/cdb/Makefile +++ b/src/backend/cdb/Makefile @@ -28,7 +28,6 @@ OBJS = cdbappendonlystorage.o cdbappendonlystorageformat.o \ cdbfilerepprimary.o cdbfilerepmirror.o \ cdbfilerepprimaryack.o cdbfilerepmirrorack.o \ cdbfilerepconnclient.o cdbfilerepconnserver.o \ - cdbfilerepresyncmanager.o cdbfilerepresyncworker.o \ cdbfilerepresetpeerprocess.o \ cdbfts.o \ cdbglobalsequence.o \ diff --git a/src/backend/cdb/cdbfilerepprimary.c b/src/backend/cdb/cdbfilerepprimary.c index 15fecacea1..2c81ff5f5c 100644 --- a/src/backend/cdb/cdbfilerepprimary.c +++ b/src/backend/cdb/cdbfilerepprimary.c @@ -32,7 +32,6 @@ #include "cdb/cdbfilerepprimary.h" #include "cdb/cdbfilerepprimaryack.h" #include "cdb/cdbfilerepconnclient.h" -#include "cdb/cdbfilerepresyncmanager.h" #include "cdb/cdbvars.h" #include "storage/lwlock.h" #include "storage/pmsignal.h" @@ -96,14 +95,6 @@ FileRepPrimary_GetMirrorDataLossTrackingSessionNum(int64 *sessionNum) case DataStateNotInitialized: return MirrorDataLossTrackingState_MirrorNotConfigured; - case DataStateInResync: - if (!FileRepResync_IsReMirrorAllowed() && - (segmentState == SegmentStateInitialization || - segmentState == SegmentStateInResyncTransition)) - return MirrorDataLossTrackingState_MirrorDown; - else - return MirrorDataLossTrackingState_MirrorCurrentlyUpInResync; - case DataStateInSync: return MirrorDataLossTrackingState_MirrorCurrentlyUpInSync; @@ -140,19 +131,19 @@ FileRepPrimary_IsMirrorDataLossOccurred(void) int FileRepPrimary_IntentAppendOnlyCommitWork(void) { - return FileRepResync_IncAppendOnlyCommitCount(); + return 0; } int FileRepPrimary_FinishedAppendOnlyCommitWork(int count) { - return FileRepResync_DecAppendOnlyCommitCount(count); + return 0; } int FileRepPrimary_GetAppendOnlyCommitWorkCount(void) { - return FileRepResync_GetAppendOnlyCommitCount(); + return 0; } /* @@ -202,16 +193,6 @@ FileRepPrimary_IsMirroringRequired( /* Insist(0); */ break; - case DataStateInResync: - if (!FileRepResync_IsReMirrorAllowed()) - { - if (segmentState == SegmentStateInitialization || - segmentState == SegmentStateInResyncTransition) - { - break; - } - } - /* no break */ case DataStateInSync: /* diff --git a/src/backend/cdb/cdbfilerepresyncmanager.c b/src/backend/cdb/cdbfilerepresyncmanager.c deleted file mode 100644 index 77ea539d4b..0000000000 --- a/src/backend/cdb/cdbfilerepresyncmanager.c +++ /dev/null @@ -1,1942 +0,0 @@ -/*------------------------------------------------------------------------- - * - * cdbfilerepresyncmanager.c - * - * Portions Copyright (c) 2009-2010 Greenplum Inc - * Portions Copyright (c) 2012-Present Pivotal Software, Inc. - * - * - * IDENTIFICATION - * src/backend/cdb/cdbfilerepresyncmanager.c - * - *------------------------------------------------------------------------- - */ - -/*------------------------------------------------------------------------------ - * INVARIANCES - * - * *) Change Tracking - * *) Change Tracking is turned ON when mirror segment is down - * (gp_segment_configuration is in CHANGE TRACKING after failover) - * *) In the transition to Change Tracking recovery from the latest checkpoint is done - * *) Change tracking keeps track of changes to Heap Data Store - * (RelFileNode, Block#, LSN, Persistent TID, Persistent Serial Number) - * *) Change Tracking is turned OFF (disabled) during resynchronization transition - * while primary segment is suspended - * *) That means that new changes are not tracked and - * Change tracking log files are NOT deleted - * *) Change Tracking log files are deleted when primary and mirror segment - * transitions to InSYNC state - * - * *) Resynchronization (full copy, incremental file copy, incremental block copy) - * *) Take last LSN to be resynced “last resync LSN” - * *) Resync to mirror all CREATE file operations (RelFileNode, segmentFileNum) - * *) Resync to mirror all DROP file operations (RelFileNode, segmentFileNum) - * *) Resync to mirror all file changes up to “last resync LSN”. - * Three options available: - * *) Full Copy - * For each segment file in a relation for each relation in a - * segment repeat the following steps: - * *) Copy all blocks in segment file that has LSN < “last resync LSN” - * *) Blocks that has LSN =>”last resync LSN” will be mirrored - * *) After copy of each segment file take “resync CKPT” - * (persistently store the latest LSN, it identifies the start - * resync point in case of restarting resync due to failures) - * *) Incremental File Copy - * For each segment file in a relation that was modified during change tracking - * *) Copy all blocks in segment file that has LSN < “last resync LSN” - * *) Blocks that has LSN =>”last resync LSN” will be mirrored - * *) After copy of each segment file take “resync CKPT” - * (persistently store the latest LSN) - * *) Incremental Block Copy - * For each segment file in a relation that was modified during change tracking - * *) Copy all blocks in segment file that has LSN < “last resync LSN” - * *) Blocks that has LSN =>”last resync LSN” will be mirrored - * *) After copy of each segment file take “resync CKPT” - * (persistently store the latest LSN) - * *) Crash Recovery of primary segment during resynchronization will - * restart copy from “resync CKPT” - * *) Mirror down during resynchronization will turn Change tracking ON and - * turn Resynchronization OFF - * *) When Mirror comes up and resynchronization is restarted - * the resynchronization will be restarted from the “resync CKPT” - * *) Changes to be resynchronized are cumulative when Change Tracking is - * turned on multiple times - * *) Catch up of pg_twophase, pg_xlog, pg_control, ... before transition to InSYNC mode - * - * *) Ongoing IO to primary segment - * *) When resynchronization transition from its recovery to ready state - * changes to primary segment are mirrored (last resync LSN + 1) - * *) If primary segment crashes during resynchronization then during - * recovery any change applied during WAL replay on primary is applied - * also to mirror - * *) If mirror segment goes down then Change Tracking is turned ON on the - * primary. No disruption to IO on primary segment. - * *) During resynchronization WAL and flat files are excluded from mirroring. - *------------------------------------------------------------------------------ - */ - -/*------------------------------------------------------------------------------ - * The following steps are performed during dataState == DataStateResynchronizing - * *) FULL Copy - * *) Transition Segment State - * *) mark all relations re-create needed - * *) mark all relations full copy request - * - * - * *) Ready Segment State - * - * *) INCREMENTAL Copy - * *) Transition Segment State - * - * *) Ready Segment State - * *) Scan Change Tracking to get all relations to be marked - * in persistent file system object - *------------------------------------------------------------------------------ - */ - -/*------------------------------------------------------------------------------ - Transition from Change Tracking to InResync on primary segment - ============================================================== - 1) Shutdown FileRep Main process - 2) postmaster set - *) dataState = DataStateInResync - *) segmentState = SegmentStateInResyncTransition - 3) Start FileRep Main process - 4) Start 1 FileRep backend process as a Resync Manager - *) FileRepMain -> FileRepPrimary_StartResyncManager() - 5) Start N FileRep backend processes as a Resync Worker ( N should be GUC, Min=1, Max=8, Default =1 (Default will be increased later)) - *) FileRepMain -> FileRepPrimary_StartResyncWorker() - 6) FileRep Resync backend processes exit when resynchronization is completed - ResyncManager set - *) dataState == DataStateInSync - *) segmentState = SegmentStateReady - - Crash Recovery when dataState = DataStateInResync on primary segment - ==================================================================== - 1) postmaster sets - *) dataState = DataStateInResync - *) segmentState = SegmentStateInitialization - 2) Start FileRep Main process - 3) Start 1 FileRep backend process as a Resync Manager - *) FileRepMain() -> FileRepPrimary_StartResyncManager() - 5) Start N FileRep backend processes as a Resync Worker ( N should be GUC, Min=1, Max=8, Default =1 (Default will be increased later)) - *) FileRepMain() -> FileRepPrimary_StartResyncWorker() - 6) Resync Manager process checks the state of resync transition - If resync transition has not been completed yet then - a) Resync Manager sets - *) dataState = DataStateInChangeTracking - *) segmentState = SegmentStateReady or SegmentStateChangeTrackingDisabled - b) postmaster run XLOG recovery - c) postmaster sets - *) dataState = DataStateInResync - *) segmentState = SegmentStateInResyncTransition - else - a) Resync Manager sets - *) dataState = DataStateInResync - *) segmentState = SegmentStateReady - b) postmaster run XLOG recovery - *) dataState = DataStateInResync - *) segmentState = SegmentStateReady - 6) FileRep Resync backend processes exit when resynchronization is completed - ResyncManager set - *) dataState == DataStateInSync - *) segmentState = SegmentStateReady ------------------------------------------------------------------------------- -*/ - -#include "postgres.h" - -#include - -#include "access/xlog.h" -#include "access/xlog_internal.h" -#include "access/twophase.h" -#include "access/slru.h" -#include "cdb/cdbfilerepprimaryrecovery.h" -#include "cdb/cdbfilerepservice.h" -#include "cdb/cdbfilerepprimaryack.h" -#include "cdb/cdbfilerep.h" -#include "cdb/cdbfilerepprimary.h" -#include "cdb/cdbfilerepresyncmanager.h" -#include "cdb/cdbpersistentfilesysobj.h" -#include "cdb/cdbmirroredflatfile.h" -#include "cdb/cdbresynchronizechangetracking.h" -#include "postmaster/bgwriter.h" -#include "postmaster/primary_mirror_mode.h" -#include "storage/lmgr.h" -#include "utils/flatfiles.h" -#include "utils/faultinjector.h" - - -typedef struct FileRepResyncShmem_s -{ - - volatile int appendOnlyCommitCount; - /* This counter is protected by FileRepAppendOnlyCommitCountLock */ - - bool reMirrorAllowed; - - /* - * This flag is used just to enable FILEREP proces to perform some - * operation (like physical file drops/creates) on Mirror while - * InResyncTranstion phase. The flag set/unset has no use/impact for - * non-filerep processes. - */ - - int64 blocksSynchronized; - /* required to report number of blocks resynchronized */ - - int64 totalBlocksToSynchronize; - /* required to report total number of blocks to be resynchronized */ - - struct timeval startResyncTime; - - /* - * resynchronization start time, required to report estimate time for - * resync to complete - */ - - slock_t lock; - - XLogRecPtr endFullResyncLSN; - - XLogRecPtr endIncrResyncLSN; - - int writeCount; - /* number of relations waiting to be resynchronized */ - - int curFsobjCount; - /* Current number of file system objects to create/drop during resync */ - - int totalFsobjCount; - /* Total number of file system objects to create/drop during resync */ - - int resyncInProgressCount; - /* number of relations in resynchronization */ - - int resyncCompletedCount; - - HTAB *fileRepResyncHash; - /* List of relations to be resynced */ - -} FileRepResyncShmem_s; - -static volatile FileRepResyncShmem_s *fileRepResyncShmem = NULL; - -static void FileRepResync_ShmemReInit(void); - -static int FileRepResyncManager_InResyncTransition(void); -static int FileRepResyncManager_InSyncTransition(void); -static int FileRepPrimary_RunResyncManager(void); - -static void FileRepResync_LockAcquire(void); -static void FileRepResync_LockRelease(void); - -static int FileRepResync_InsertEntry( - FileRepResyncHashEntry_s *entry); -static FileRepResyncHashEntry_s *FileRepResync_LookupEntry( - FileName fileName); -static bool FileRepResync_RemoveEntry( - FileName fileName); - -static int FileRepResync_CheckProgress(void); - -static void -FileRepResync_LockAcquire(void) -{ - SpinLockAcquire(&fileRepResyncShmem->lock); -} - -static void -FileRepResync_LockRelease(void) -{ - SpinLockRelease(&fileRepResyncShmem->lock); -} - -void -FileRepResync_DecFsobjCount(void) -{ - Assert(fileRepResyncShmem->curFsobjCount > 0); - if (fileRepResyncShmem != NULL && (fileRepResyncShmem->curFsobjCount > 0)) - { - --(fileRepResyncShmem->curFsobjCount); - } -} - -int -FileRepResync_GetCurFsobjCount(void) -{ - return (fileRepResyncShmem != NULL) ? - fileRepResyncShmem->curFsobjCount : -1; -} - -int -FileRepResync_GetTotalFsobjCount(void) -{ - return (fileRepResyncShmem != NULL) ? - fileRepResyncShmem->totalFsobjCount : -1; -} - -int -FileRepResync_IncAppendOnlyCommitCount(void) -{ - /* This counter is protected by FileRepAppendOnlyCommitCountLock; */ - if (fileRepResyncShmem != NULL) - { - return ++(fileRepResyncShmem->appendOnlyCommitCount); - } - else - { - return 0; - } -} - -int -FileRepResync_DecAppendOnlyCommitCount(int count) -{ - /* This counter is protected by FileRepAppendOnlyCommitCountLock; */ - if (fileRepResyncShmem != NULL) - { - fileRepResyncShmem->appendOnlyCommitCount -= count; - - Assert(fileRepResyncShmem->appendOnlyCommitCount >= 0); - - return fileRepResyncShmem->appendOnlyCommitCount; - } - else - { - return 0; - } -} - -int -FileRepResync_GetAppendOnlyCommitCount(void) -{ - /* This counter is protected by FileRepAppendOnlyCommitCountLock; */ - if (fileRepResyncShmem != NULL) - { - return fileRepResyncShmem->appendOnlyCommitCount; - } - else - { - return 0; - } -} - -XLogRecPtr -FileRepResync_GetEndIncrResyncLSN(void) -{ - return fileRepResyncShmem->endIncrResyncLSN; -} - -XLogRecPtr -FileRepResync_GetEndFullResyncLSN(void) -{ - return fileRepResyncShmem->endFullResyncLSN; -} - -void -FileRepResyncManager_SetEndResyncLSN(XLogRecPtr endResyncLSN) -{ - char tmpBuf[FILEREP_MAX_LOG_DESCRIPTION_LEN]; - - Assert(!(endResyncLSN.xlogid == 0 && endResyncLSN.xrecoff == 0)); - - if (isFullResync()) - { - fileRepResyncShmem->endFullResyncLSN.xlogid = endResyncLSN.xlogid; - fileRepResyncShmem->endFullResyncLSN.xrecoff = endResyncLSN.xrecoff; - } - else - { - fileRepResyncShmem->endIncrResyncLSN.xlogid = endResyncLSN.xlogid; - fileRepResyncShmem->endIncrResyncLSN.xrecoff = endResyncLSN.xrecoff; - } - - - snprintf(tmpBuf, sizeof(tmpBuf), "full resync '%s' resync lsn '%s(%u/%u)' ", - (isFullResync() == TRUE) ? "true" : "false", - XLogLocationToString(&endResyncLSN), - endResyncLSN.xlogid, - endResyncLSN.xrecoff); - - FileRep_InsertConfigLogEntry(tmpBuf); -} - -void -FileRepResync_ResetReMirrorAllowed(void) -{ - fileRepResyncShmem->reMirrorAllowed = FALSE; -} - -void -FileRepResync_SetReMirrorAllowed(void) -{ - fileRepResyncShmem->reMirrorAllowed = TRUE; -} - -bool -FileRepResync_IsReMirrorAllowed(void) -{ - return ((fileRepResyncShmem != NULL) ? - (fileRepResyncShmem->reMirrorAllowed == TRUE && - fileRepProcessType == FileRepProcessTypeResyncManager) : false); -} - -int64 -FileRepResync_GetBlocksSynchronized(void) -{ - return ((fileRepResyncShmem != NULL) ? - (fileRepResyncShmem->blocksSynchronized) : 0); -} - -int64 -FileRepResync_GetTotalBlocksToSynchronize(void) -{ - return ((fileRepResyncShmem != NULL) ? - (fileRepResyncShmem->totalBlocksToSynchronize) : 0); -} - -void -FileRepResync_SetTotalBlocksToSynchronize(int64 totalBlocksToSynchronize) -{ - fileRepResyncShmem->totalBlocksToSynchronize = totalBlocksToSynchronize; -} - -void -FileRepResync_AddToTotalBlocksToSynchronize(int64 moreBlocksToSynchronize) -{ - fileRepResyncShmem->totalBlocksToSynchronize += moreBlocksToSynchronize; -} - -struct timeval -FileRepResync_GetEstimateResyncCompletionTime(void) -{ - char temp[128]; - pg_time_t tt; - struct timeval currentResyncTime; - struct timeval estimateResyncCompletionTime = {0, 0}; - - /* - * pull values out of shared memory into local variables so we have - * consistent values for calculation here - */ - int64 totalBlocksToSynchronize = fileRepResyncShmem == NULL ? 0L : fileRepResyncShmem->totalBlocksToSynchronize; - int64 blocksSynchronized = fileRepResyncShmem == NULL ? 0L : fileRepResyncShmem->blocksSynchronized; - - if (totalBlocksToSynchronize == 0L || blocksSynchronized == 0L) - { - return estimateResyncCompletionTime; - } - struct timeval startResyncTime = fileRepResyncShmem->startResyncTime; - - gettimeofday(¤tResyncTime, NULL); - - if (totalBlocksToSynchronize > blocksSynchronized) - { - estimateResyncCompletionTime.tv_sec = - (((currentResyncTime.tv_sec - startResyncTime.tv_sec) * - (totalBlocksToSynchronize - blocksSynchronized)) / - blocksSynchronized) + currentResyncTime.tv_sec; - } - else - { - estimateResyncCompletionTime.tv_sec = 0; - estimateResyncCompletionTime.tv_usec = 0; - } - - if (Debug_filerep_print) - { - tt = (pg_time_t) estimateResyncCompletionTime.tv_sec; - pg_strftime(temp, sizeof(temp), "%a %b %d %H:%M:%S.%%06d %Y %Z", - pg_localtime(&tt, session_timezone)); - - elog(LOG, - "resynchronization info: " - "total blocks to synchronize " INT64_FORMAT " " - "blocks synchronized " INT64_FORMAT " " - "estimate resync completion time '%s' ", - totalBlocksToSynchronize, - blocksSynchronized, - temp); - } - - return estimateResyncCompletionTime; -} - -/**************************************************************** - * FILEREP_RESYNC SHARED MEMORY - ****************************************************************/ - -Size -FileRepResync_ShmemSize(void) -{ - Size size; - - size = hash_estimate_size( - (Size) FILEREP_MAX_RESYNC_FILES, - sizeof(FileRepResyncHashEntry_s)); - - size = add_size(size, sizeof(FileRepResyncShmem_s)); - - return size; -} - -/* - * Hash table contains - * FileName(identifier) is the key in the hash table. - * Hash table in shared memory is initialized only on primary segment. - * It is not initialized on mirror and master host. - */ -void -FileRepResync_ShmemInit(void) -{ - HASHCTL hash_ctl; - bool foundPtr; - struct timeval resyncTime; - - - fileRepResyncShmem = (FileRepResyncShmem_s *) ShmemInitStruct("filerep resync", - sizeof(FileRepResyncShmem_s), - &foundPtr); - - if (fileRepResyncShmem == NULL) - { - ereport(ERROR, - (errcode(ERRCODE_OUT_OF_MEMORY), - (errmsg("not enough shared memory to run resynchronization")))); - } - - if (!foundPtr) - { - MemSet(fileRepResyncShmem, 0, sizeof(FileRepResyncShmem_s)); - } - - fileRepResyncShmem->appendOnlyCommitCount = 0; - - fileRepResyncShmem->reMirrorAllowed = FALSE; - - fileRepResyncShmem->totalBlocksToSynchronize = 0; - - fileRepResyncShmem->blocksSynchronized = 0; - - gettimeofday(&resyncTime, NULL); - - fileRepResyncShmem->startResyncTime.tv_sec = resyncTime.tv_sec; - fileRepResyncShmem->startResyncTime.tv_usec = resyncTime.tv_usec; - - SpinLockInit(&fileRepResyncShmem->lock); - - fileRepResyncShmem->endFullResyncLSN.xlogid = 0; - fileRepResyncShmem->endFullResyncLSN.xrecoff = 0; - - fileRepResyncShmem->endIncrResyncLSN.xlogid = 0; - fileRepResyncShmem->endIncrResyncLSN.xrecoff = 0; - - fileRepResyncShmem->writeCount = 0; - - fileRepResyncShmem->curFsobjCount = 0; - fileRepResyncShmem->totalFsobjCount = 0; - - fileRepResyncShmem->resyncInProgressCount = 0; - fileRepResyncShmem->resyncCompletedCount = 0; - - MemSet(&hash_ctl, 0, sizeof(hash_ctl)); - hash_ctl.keysize = MAXPGPATH; - hash_ctl.entrysize = sizeof(FileRepResyncHashEntry_s); - hash_ctl.hash = string_hash; - - fileRepResyncShmem->fileRepResyncHash = ShmemInitHash("filerep resync hash", - FILEREP_MAX_RESYNC_FILES, - FILEREP_MAX_RESYNC_FILES, - &hash_ctl, - HASH_ELEM | HASH_FUNCTION); - - if (fileRepResyncShmem->fileRepResyncHash == NULL) - { - ereport(ERROR, - (errcode(ERRCODE_OUT_OF_MEMORY), - (errmsg("not enough shared memory to run resynchronization")))); - } - - return; -} - -/* - * - */ -static void -FileRepResync_ShmemReInit(void) -{ - HASH_SEQ_STATUS hash_status; - FileRepResyncHashEntry_s *entry; - struct timeval resyncTime; - - - if (fileRepResyncShmem == NULL) - { - ereport(ERROR, - (errcode(ERRCODE_OUT_OF_MEMORY), - (errmsg("not enough shared memory to run resynchronization")))); - } - - /* - * NOTE: Do not zero Commit Work Intent count for ReInit. - */ - fileRepResyncShmem->reMirrorAllowed = FALSE; - - fileRepResyncShmem->totalBlocksToSynchronize = 0; - - fileRepResyncShmem->blocksSynchronized = 0; - - gettimeofday(&resyncTime, NULL); - - fileRepResyncShmem->startResyncTime.tv_sec = resyncTime.tv_sec; - fileRepResyncShmem->startResyncTime.tv_usec = resyncTime.tv_usec; - - SpinLockInit(&fileRepResyncShmem->lock); - - fileRepResyncShmem->endFullResyncLSN.xlogid = 0; - fileRepResyncShmem->endFullResyncLSN.xrecoff = 0; - - fileRepResyncShmem->endIncrResyncLSN.xlogid = 0; - fileRepResyncShmem->endIncrResyncLSN.xrecoff = 0; - - fileRepResyncShmem->writeCount = 0; - - fileRepResyncShmem->curFsobjCount = 0; - fileRepResyncShmem->totalFsobjCount = 0; - - fileRepResyncShmem->resyncInProgressCount = 0; - fileRepResyncShmem->resyncCompletedCount = 0; - - if (fileRepResyncShmem->fileRepResyncHash == NULL) - { - ereport(ERROR, - (errcode(ERRCODE_OUT_OF_MEMORY), - (errmsg("not enough shared memory to run resynchronization")))); - } - - FileRepResync_LockAcquire(); - - hash_seq_init(&hash_status, fileRepResyncShmem->fileRepResyncHash); - - while ((entry = (FileRepResyncHashEntry_s *) hash_seq_search(&hash_status)) != NULL) - { - - FileRepResync_RemoveEntry(entry->fileName); - } - - FileRepResync_LockRelease(); - - return; -} - -/* - * - */ -void -FileRepResync_Cleanup(void) -{ - HASH_SEQ_STATUS hash_status; - FileRepResyncHashEntry_s *entry; - - if (fileRepResyncShmem == NULL) - { - return; - } - - if (fileRepResyncShmem->fileRepResyncHash == NULL) - { - return; - } - - FileRepResync_LockAcquire(); - - hash_seq_init(&hash_status, fileRepResyncShmem->fileRepResyncHash); - - while ((entry = (FileRepResyncHashEntry_s *) hash_seq_search(&hash_status)) != NULL) - { - - FileRepResync_RemoveEntry(entry->fileName); - UnlockRelationForResynchronize( - &entry->relFileNode, - AccessExclusiveLock); - } - - LockReleaseAll(DEFAULT_LOCKMETHOD, false); - - FileRepResync_LockRelease(); - - return; -} - -/**************************************************************** - * FILEREP SUB-PROCESS (FileRep Primary RECOVERY Process) - ****************************************************************/ -/* - * - * FileRepPrimary_StartResyncManager() - * - * - */ -void -FileRepPrimary_StartResyncManager(void) -{ - int status = STATUS_OK; - bool isLastLocTracked = FALSE; - - FileRep_InsertConfigLogEntry("start resync manager"); - - Insist(fileRepRole == FileRepPrimaryRole); - - Insist(dataState == DataStateInResync); - - FileRepResync_ShmemReInit(); - - while (1) - { - - if (status != STATUS_OK) - { - FileRep_SetSegmentState(SegmentStateFault, FaultTypeMirror); - FileRepSubProcess_SetState(FileRepStateFault); - } - - while (FileRepSubProcess_GetState() == FileRepStateFault || - - (fileRepShmemArray[0]->state == FileRepStateNotInitialized && - FileRepSubProcess_GetState() != FileRepStateShutdownBackends && - FileRepSubProcess_GetState() != FileRepStateShutdown)) - { - - FileRepSubProcess_ProcessSignals(); - pg_usleep(50000L); /* 50 ms */ - } - - if (FileRepSubProcess_GetState() == FileRepStateShutdown || - FileRepSubProcess_GetState() == FileRepStateShutdownBackends) - { - - break; - } - - if (segmentState == SegmentStateInitialization) - { - - if (ChangeTracking_RetrieveLastChangeTrackedLoc()) - { - isLastLocTracked = TRUE; - FileRepSubProcess_SetState(FileRepStateReady); - getFileRepRoleAndState(&fileRepRole, &segmentState, &dataState, NULL, NULL); - - while (FileRepSubProcess_GetState() != FileRepStateShutdown && - FileRepSubProcess_GetState() != FileRepStateShutdownBackends && - isDatabaseRunning() == FALSE) - { - - FileRepSubProcess_ProcessSignals(); - pg_usleep(50000L); /* 50 ms */ - } - - if (FileRepSubProcess_GetState() == FileRepStateShutdown || - FileRepSubProcess_GetState() == FileRepStateShutdownBackends) - { - - break; - } - - } - else - { - - FileRep_SetDataState(DataStateInChangeTracking, FALSE /* signal postmaster */ ); - - if (isFullResync()) - { - FileRep_SetSegmentState(SegmentStateChangeTrackingDisabled, FaultTypeNotInitialized); - } - else - { - ChangeTracking_CreateInitialFromPreviousCheckpoint( - /* lastChangeTrackingEndLoc */ NULL); - FileRepSubProcess_SetState(FileRepStateReady); - } - - /* Wait that XLOG replay is done */ - while (FileRepSubProcess_GetState() != FileRepStateShutdown && - FileRepSubProcess_GetState() != FileRepStateShutdownBackends && - !(segmentState == SegmentStateInResyncTransition && - dataState == DataStateInResync)) - { - - FileRepSubProcess_ProcessSignals(); - pg_usleep(50000L); /* 50 ms */ - } - - if (FileRepSubProcess_GetState() == FileRepStateShutdown || - FileRepSubProcess_GetState() == FileRepStateShutdownBackends) - { - - break; - } - } - - /* - * Database was started. The local copies of ThisTimeLineID and - * RedoRecPtr has to be initialized. - */ - InitXLOGAccess(); - } - - Insist(segmentState == SegmentStateInResyncTransition || - segmentState == SegmentStateReady); - - FileRepSubProcess_InitHeapAccess(); - - if (isLastLocTracked == FALSE) - { - status = FileRepResyncManager_InResyncTransition(); - } - - if (status != STATUS_OK || - !(FileRepSubProcess_GetState() == FileRepStateReady && - dataState == DataStateInResync)) - { - continue; - } - - status = FileRepPrimary_RunResyncManager(); - - if (status != STATUS_OK || - !(FileRepSubProcess_GetState() == FileRepStateReady && - dataState == DataStateInResync)) - { - continue; - } - - status = FileRepResyncManager_InSyncTransition(); - - if (status != STATUS_OK) - { - continue; - } - - ereport(LOG, - (errmsg("mirror transition to sync completed, " - "primary address(port) '%s(%d)' mirror address(port) '%s(%d)' ", - fileRepPrimaryHostAddress, - fileRepPrimaryPort, - fileRepMirrorHostAddress, - fileRepMirrorPort), - FileRep_errcontext())); - break; - - } //while (1) - - FileRep_InsertConfigLogEntry("resync manager completed"); - -} - -/* - * FileRepResyncManager_InResyncTransition() - */ -static int -FileRepResyncManager_InResyncTransition(void) -{ - int status = STATUS_OK; - - FileRep_InsertConfigLogEntry("run resync transition"); - - if (LWLockHeldByMe(MirroredLock)) - ereport(ERROR, - (errcode(ERRCODE_INTERNAL_ERROR), - (errmsg("'MirroredLock' is already held by primary resync manager process")))); - - LWLockAcquire(MirroredLock, LW_EXCLUSIVE); - - /* - * database transitions to suspended state, IO activity on the segment is - * suspended - */ - primaryMirrorSetIOSuspended(TRUE); - - FileRep_InsertConfigLogEntry("run resync transition, record last lsn in change tracking"); - - ChangeTracking_RecordLastChangeTrackedLoc(); - - if (FileRepSubProcess_GetState() == FileRepStateFault) - { - goto exit; - } - - FileRepSubProcess_ProcessSignals(); - if (!((segmentState == SegmentStateInResyncTransition || - segmentState == SegmentStateReady) && - dataState == DataStateInResync)) - { - goto exit; - } - - if (isFullResync()) - { - FileRep_InsertConfigLogEntry("run resync transition, mark full copy"); - - PersistentFileSysObj_MarkWholeMirrorFullCopy(); - } - else - { - /* - * First, mark the special persistent tables and others as 'Scan - * Incremental'. - * - * These include OIDs {5090, 5091, 5092, 5093, and 5096} and others - * (see GpPersistent_SkipXLogInfo). - * - * And, mark any Buffer Pool managed relations that were physically - * truncated as as 'Scan incremental' because we don't know how to - * process old changes in the change tracking log. - */ - FileRep_InsertConfigLogEntry("run resync transition, mark scan incremental"); - - PersistentFileSysObj_MarkSpecialScanIncremental(); - - /* - * Second, now mark any relations that have changes in the change - * tracking log as 'Page Incremental', except those relations marked - * 'Scan Incremental' in the first step. - */ - FileRep_InsertConfigLogEntry("run resync transition, mark page incremental"); - - PersistentFileSysObj_MarkPageIncrementalFromChangeLog(); - if (segmentState == SegmentStateChangeTrackingDisabled) - { - status = STATUS_ERROR; - goto exit; - } - - /* - * Finally, find any Append-Only tables that have mirror data loss. - */ - FileRep_InsertConfigLogEntry("run resync transition, mark append only incremental"); - - PersistentFileSysObj_MarkAppendOnlyCatchup(); - } - - FileRepSubProcess_ProcessSignals(); - if (!((segmentState == SegmentStateInResyncTransition || - segmentState == SegmentStateReady) && - dataState == DataStateInResync)) - { - goto exit; - } - - /* - * It is important to keep order of dropping objects before creating - * objects since it can happen that persistent table has two entries for - * the same object. For e.g Consider that an append only segment file was - * created (when mirror was active) and dropped (after mirror went down) - * since transaction was aborted. Later, if the same Append Only segment - * file was created and transaction was committed (with the Mirror still - * down). This situation can cause to have duplicate entries for the same - * append only segment file. Now during resync phase if the file is - * created on the mirror first (re-create phase) and later dropped (redrop - * phase for original file) you can loose the file created by re-created - * phase. - */ - FileRep_InsertConfigLogEntry("run resync manager, mirror redrop"); - - fileRepResyncShmem->totalFsobjCount = fileRepResyncShmem->curFsobjCount - = PersistentFileSysObj_CountResyncObjects(); - - /* - * Drop the objects on the mirror that were dropped on the primary when - * the mirror was down/inactive by looking at Persistent Tables (all - * object types). But note that the accounting information in Persistent - * Tables will be updated later. This is because at this stage the segment - * is still in resync transition state and not ready. As a result any - * operations for e.g. write() still assume that the mirror is - * inactive/down and so won't be mirrored. Once the segment changes its - * state to ready, all such operations will be correctly mirrored. - */ - PersistentFileSysObj_MirrorReDrop(); - - FileRep_InsertConfigLogEntry("run resync manager, mirror redrop completed"); - - FileRepSubProcess_ProcessSignals(); - if (!((segmentState == SegmentStateInResyncTransition || - segmentState == SegmentStateReady) && - dataState == DataStateInResync)) - { - goto exit; - } - - SIMPLE_FAULT_INJECTOR(FileRepTransitionToInResyncMirrorReCreate); - - FileRep_InsertConfigLogEntry("run resync transition, mirror recreate"); - - PersistentFileSysObj_MirrorReCreate(); - - FileRepSubProcess_ProcessSignals(); - if (!((segmentState == SegmentStateInResyncTransition || - segmentState == SegmentStateReady) && - dataState == DataStateInResync)) - { - goto exit; - } - - FileRepSubProcess_SetState(FileRepStateReady); - - SIMPLE_FAULT_INJECTOR(FileRepTransitionToInResyncMarkReCreated); - - /* - * Mark Persistent Table entries as 'Dropped (i.e. Free)' to indicate the - * drops performed in PersistenFileSysObj_MirrorReDrop(). This module only - * updates drop pending/aborting create entries to 'free' in Persistent - * tables. - */ - FileRep_InsertConfigLogEntry("run resync transition, mark mirror redropped"); - PersistentFileSysObj_MarkMirrorReDropped(); - - FileRepSubProcess_ProcessSignals(); - if (!(segmentState == SegmentStateReady && - dataState == DataStateInResync)) - { - goto exit; - } - - FileRep_InsertConfigLogEntry("run resync transition, mark mirror recreated"); - - PersistentFileSysObj_MarkMirrorReCreated(); - - FileRepSubProcess_ProcessSignals(); - if (!(segmentState == SegmentStateReady && - dataState == DataStateInResync)) - { - goto exit; - } - - SIMPLE_FAULT_INJECTOR(FileRepTransitionToInResyncMarkCompleted); - - FileRep_InsertConfigLogEntry("run resync transition, mark transition to resync completed"); - - ChangeTracking_MarkTransitionToResyncCompleted(); - - FileRepSubProcess_ProcessSignals(); - if (!(segmentState == SegmentStateReady && - dataState == DataStateInResync)) - { - goto exit; - } - -exit: - LWLockRelease(MirroredLock); - - /* database is resumed */ - primaryMirrorSetIOSuspended(FALSE); - - return status; -} - -/* - * FileRepPrimary_RunResyncManager() - */ -static int -FileRepPrimary_RunResyncManager(void) -{ - int status = STATUS_OK; - bool retval; - int ii = 0; - bool mirroredLock = FALSE; - struct timeval resyncTime; - - FileRepResyncHashEntry_s entry; - ResynchronizeScanToken token; - - FileRep_InsertConfigLogEntry("run resync manager"); - - ResynchronizeScanToken_Init(&token); - - /* set start resync time required for reporting */ - gettimeofday(&resyncTime, NULL); - - fileRepResyncShmem->startResyncTime.tv_sec = resyncTime.tv_sec; - fileRepResyncShmem->startResyncTime.tv_usec = resyncTime.tv_usec; - - while (1) - { - - FileRepSubProcess_ProcessSignals(); - if (!(FileRepSubProcess_GetState() == FileRepStateReady && - dataState == DataStateInResync)) - { - break; - } - - if (FileRepResync_CheckProgress() == FILEREP_MAX_RESYNC_FILES) - { - pg_usleep(50000L); - //50 ms - continue; - } - - retval = PersistentFileSysObj_ResynchronizeScan( - &token, - &entry.relFileNode, - &entry.segmentFileNum, - &entry.relStorageMgr, - &entry.mirrorDataSynchronizationState, - &entry.mirrorBufpoolResyncChangedPageCount, - &entry.mirrorBufpoolResyncCkptLoc, - &entry.mirrorBufpoolResyncCkptBlockNum, - &entry.mirrorAppendOnlyLossEof, - &entry.mirrorAppendOnlyNewEof, - &entry.persistentTid, - &entry.persistentSerialNum); - - if (retval == FALSE) - { - /* wait that resync workers are completed */ - while (FileRepResync_CheckProgress() > 0) - { - pg_usleep(50000L); - //50 ms - - FileRepSubProcess_ProcessSignals(); - if (!(FileRepSubProcess_GetState() == FileRepStateReady && - dataState == DataStateInResync)) - { - break; - } - } - - if (mirroredLock == TRUE) - { - LWLockRelease(MirroredLock); - - mirroredLock = FALSE; - break; - } - - if (!(FileRepSubProcess_GetState() == FileRepStateReady && - dataState == DataStateInResync)) - { - break; - } - - LWLockAcquire(MirroredLock, LW_EXCLUSIVE); - mirroredLock = TRUE; - - if (fileRepResyncShmem->appendOnlyCommitCount == 0) - { - - FileRep_InsertConfigLogEntry("run resync transition, mark append only incremental"); - - PersistentFileSysObj_MarkAppendOnlyCatchup(); - ResynchronizeScanToken_Init(&token); - - /* - * MirroredLock is not released. AppendOnly Resync has to - * finish under MirrorLock. - */ - continue; - } - else - { - LWLockRelease(MirroredLock); - mirroredLock = FALSE; - - /* - * wait that all in progress AppendOnly transactions are - * committed and periodically check if more work to do for - * resync - */ - pg_usleep(100000L); - //100 ms - - FileRep_InsertConfigLogEntry("run resync transition, mark append only incremental"); - - LWLockAcquire(MirroredLock, LW_EXCLUSIVE); - PersistentFileSysObj_MarkAppendOnlyCatchup(); - LWLockRelease(MirroredLock); - - ResynchronizeScanToken_Init(&token); - continue; - } - } - - if (entry.mirrorDataSynchronizationState == MirroredRelDataSynchronizationState_DataSynchronized || - entry.mirrorDataSynchronizationState == MirroredRelDataSynchronizationState_None) - { - if (Debug_filerep_print) - { - elog(LOG, "Not adding this entry to hash table %s as DataSynchronized/None %d", - entry.fileName, entry.mirrorDataSynchronizationState); - } - continue; - } - - if (isFullResync()) - { - if (entry.mirrorDataSynchronizationState == MirroredRelDataSynchronizationState_BufferPoolPageIncremental) - { - ereport(WARNING, - (errmsg("resync failure, " - "unexpected mirror synchronization state during full resynchronization, " - "failover requested, " - "relation path to be resynchronized '%s' " - "relation storage manager '%s(%d)' mirror synchronization state '%s(%d)' " - "append only loss eof " INT64_FORMAT " " - "append only new eof " INT64_FORMAT " " - "mirror buffer pool resync changed page count " INT64_FORMAT " ", - entry.fileName, - PersistentFileSysRelStorageMgr_Name(entry.relStorageMgr), - entry.relStorageMgr, - MirroredRelDataSynchronizationState_Name(entry.mirrorDataSynchronizationState), - entry.mirrorDataSynchronizationState, - entry.mirrorAppendOnlyLossEof, - entry.mirrorAppendOnlyNewEof, - entry.mirrorBufpoolResyncChangedPageCount), - errhint("run gprecoverseg -F again to re-establish mirror connectivity"))); - - FileRep_SetSegmentState(SegmentStateFault, FaultTypeMirror); - FileRepSubProcess_ProcessSignals(); - } - } - - /* - * Resynchronize Lock is taken for particular relation to protect from - * drop and truncate for particular relation. - */ - LockRelationForResynchronize( - &entry.relFileNode, - AccessExclusiveLock); - - if (!PersistentFileSysObj_ResynchronizeRefetch( - &entry.relFileNode, - &entry.segmentFileNum, - &entry.persistentTid, - entry.persistentSerialNum, - &entry.relStorageMgr, - &entry.mirrorDataSynchronizationState, - &entry.mirrorBufpoolResyncCkptLoc, - &entry.mirrorBufpoolResyncCkptBlockNum, - &entry.mirrorAppendOnlyLossEof, - &entry.mirrorAppendOnlyNewEof)) - { - UnlockRelationForResynchronize( - &entry.relFileNode, - AccessExclusiveLock); - - if (Debug_filerep_print) - elog(LOG, "Not adding this entry to hash table %s", entry.fileName); - continue; - } - - SIMPLE_FAULT_INJECTOR(FileRepResync); - - FileRep_GetRelationPath( - entry.fileName, - entry.relFileNode, - entry.segmentFileNum); - - status = FileRepResync_InsertEntry(&entry); - - if (status != STATUS_OK) - { - /* - * UnlockRelationForResynchronize() will be issued in - * FileRepResync_Cleanup(). - */ - FileRep_SetSegmentState(SegmentStateFault, FaultTypeMirror); - if (mirroredLock == TRUE) - { - LWLockRelease(MirroredLock); - - mirroredLock = FALSE; - } - } - - if (Debug_filerep_config_print) - { - elog(LOG, - "resync scheduled %s index %d rel storage mgr %s(%d) mirror sync state:%s(%d) " - "ao loss eof " INT64_FORMAT " ao new eof " INT64_FORMAT " changed page count " INT64_FORMAT " " - "resync ckpt lsn %s resync ckpt blkno %u TID %s serial num " INT64_FORMAT "", - entry.fileName, - ii++, - PersistentFileSysRelStorageMgr_Name(entry.relStorageMgr), - entry.relStorageMgr, - MirroredRelDataSynchronizationState_Name(entry.mirrorDataSynchronizationState), - entry.mirrorDataSynchronizationState, - entry.mirrorAppendOnlyLossEof, - entry.mirrorAppendOnlyNewEof, - entry.mirrorBufpoolResyncChangedPageCount, - XLogLocationToString(&entry.mirrorBufpoolResyncCkptLoc), - entry.mirrorBufpoolResyncCkptBlockNum, - ItemPointerToString(&entry.persistentTid), - entry.persistentSerialNum); - } - } - - FileRepResync_Cleanup(); - - return status; -} - -/* - * FileRepResyncManager_InSyncTransition() - */ -static int -FileRepResyncManager_InSyncTransition(void) -{ - int status = STATUS_OK; - - FileRep_InsertConfigLogEntry("run resync sync transition"); - - SIMPLE_FAULT_INJECTOR(FileRepTransitionToInSyncBegin); - - while (1) - { - /* - * (MirroredLock, LW_EXCLUSIVE) is acquired and released in - * CreateCheckPoint - */ - FileRep_InsertConfigLogEntry("run sync transition, request checkpoint"); - - MirroredFlatFile_DropFilesFromDir(); - - RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT | CHECKPOINT_RESYNC_TO_INSYNC_TRANSITION); - - /* - * The second checkpoint is required in order to mirror pg_control - * with last checkpoint position in the xlog file that is mirrored - * (XLogSwitch). - */ - RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT); - - FileRepSubProcess_ProcessSignals(); - if (!(FileRepSubProcess_GetState() == FileRepStateReady && - dataState == DataStateInSync)) - { - break; - } - - FileRep_InsertConfigLogEntry("run sync transition, mirror to sync transition"); - - FileRepPrimary_MirrorInSyncTransition(); - - FileRep_InsertConfigLogEntry("run sync transition, mark transition to sync completed"); - - ChangeTracking_MarkTransitionToInsyncCompleted(); - - FileRep_InsertConfigLogEntry("run sync transition, mark transition to sync completed on primary and mirror"); - - /* primary and mirror have now completed re-sync */ - setResyncCompleted(); - primaryMirrorSetInSync(); - - SIMPLE_FAULT_INJECTOR(FileRepTransitionToInSyncMarkCompleted); - - break; - } - - return status; -} - -/* - * - */ -void -FileRepResyncManager_ResyncFlatFiles(void) -{ - int status = STATUS_OK; - - FileRep_SetSegmentState(SegmentStateInSyncTransition, FaultTypeNotInitialized); - - SIMPLE_FAULT_INJECTOR(FileRepTransitionToInSync); - - while (1) - { - FileRep_InsertConfigLogEntry("run sync transition, resync pg_control file"); - - status = XLogRecoverMirrorControlFile(); - - if (status != STATUS_OK) - { - break; - } - - FileRepSubProcess_ProcessSignals(); - if (segmentState != SegmentStateInSyncTransition) - { - break; - } - MirroredFlatFile_MirrorDropTemporaryFiles(); - FileRep_InsertConfigLogEntry("run sync transition, resync drop temporary files"); - - FileRepSubProcess_ProcessSignals(); - if (segmentState != SegmentStateInSyncTransition) - { - break; - } - - status = FlatFilesTemporaryResynchronizeMirror(); - FileRep_InsertConfigLogEntry("run sync transition, resync temporary files"); - - if (status != STATUS_OK) - { - break; - } - - FileRepSubProcess_ProcessSignals(); - if (segmentState != SegmentStateInSyncTransition) - { - break; - } - - FileRep_InsertConfigLogEntry("run sync transition, resync pg_database and pg_auth files"); - - status = FlatFilesRecoverMirror(); - - if (status != STATUS_OK) - { - break; - } - - FileRepSubProcess_ProcessSignals(); - if (segmentState != SegmentStateInSyncTransition) - { - break; - } - - FileRep_InsertConfigLogEntry("run sync transition, resync pg_twophase files"); - - status = TwoPhaseRecoverMirror(); - - if (status != STATUS_OK) - { - break; - } - - FileRepSubProcess_ProcessSignals(); - if (segmentState != SegmentStateInSyncTransition) - { - break; - } - - FileRep_InsertConfigLogEntry("run sync transition, resync slru files"); - - status = SlruRecoverMirror(); - - if (status != STATUS_OK) - { - break; - } - - FileRepSubProcess_ProcessSignals(); - if (segmentState != SegmentStateInSyncTransition) - { - break; - } - - FileRep_InsertConfigLogEntry("run sync transition, resync pgversion files"); - - status = PgVersionRecoverMirror(); - - if (status != STATUS_OK) - { - break; - } - - FileRepSubProcess_ProcessSignals(); - - FileRep_InsertConfigLogEntry("run sync transition, resync pgxlog files"); - - status = XLogRecoverMirror(); - - if (status != STATUS_OK) - { - break; - } - - FileRepSubProcess_ProcessSignals(); - - break; - } - - if (status != STATUS_OK) - { - FileRep_SetSegmentState(SegmentStateFault, FaultTypeMirror); - FileRepSubProcess_ProcessSignals(); - } - - if (segmentState == SegmentStateInSyncTransition && - status == STATUS_OK) - { - FileRep_SetDataState(DataStateInSync, FALSE); - - FileRep_SetSegmentState(SegmentStateReady, FaultTypeNotInitialized); - } - - return; -} - -static int -FileRepResync_InsertEntry( - FileRepResyncHashEntry_s *entry) -{ - int status = STATUS_OK; - bool foundPtr; - FileRepResyncHashEntry_s *entryLocal; - char key[MAXPGPATH + 1]; - - snprintf(key, sizeof(key), "%s", entry->fileName); - - if (Debug_filerep_print) - elog(LOG, "FileRepResync_InsertEntry() identifier:'%s' ", key); - - FileRepResync_LockAcquire(); - - Assert(fileRepResyncShmem->fileRepResyncHash != NULL); - - entryLocal = (FileRepResyncHashEntry_s *) hash_search( - fileRepResyncShmem->fileRepResyncHash, - (void *) &key, - HASH_ENTER_NULL, - &foundPtr); - - if (entryLocal == NULL) - { - - status = STATUS_ERROR; - ereport(WARNING, - (errmsg("resync failure, " - "could not insert resync information into hash table identifier '%s', no memory " - "failover requested", - key), - errhint("run gprecoverseg to re-establish mirror connectivity"), - FileRep_errcontext())); - goto exit; - } - - if (foundPtr) - { - - status = STATUS_ERROR; - ereport(WARNING, - (errmsg("resync failure, " - "could not insert resync information into hash table identifier '%s', entry exists " - "failover requested", - key), - errhint("run gprecoverseg to re-establish mirror connectivity"), - FileRep_errcontext())); - - - } - else - { - - entryLocal->relFileNode.relNode = entry->relFileNode.relNode; - entryLocal->relFileNode.spcNode = entry->relFileNode.spcNode; - entryLocal->relFileNode.dbNode = entry->relFileNode.dbNode; - entryLocal->segmentFileNum = entry->segmentFileNum; - - entryLocal->relStorageMgr = entry->relStorageMgr; - entryLocal->mirrorDataSynchronizationState = entry->mirrorDataSynchronizationState; - entryLocal->mirrorBufpoolResyncCkptLoc = entry->mirrorBufpoolResyncCkptLoc; - entryLocal->mirrorBufpoolResyncCkptBlockNum = entry->mirrorBufpoolResyncCkptBlockNum; - - entryLocal->mirrorAppendOnlyLossEof = entry->mirrorAppendOnlyLossEof; - entryLocal->mirrorAppendOnlyNewEof = entry->mirrorAppendOnlyNewEof; - - entryLocal->mirrorBufpoolResyncChangedPageCount = entry->mirrorBufpoolResyncChangedPageCount; - - entryLocal->persistentTid = entry->persistentTid; - entryLocal->persistentSerialNum = entry->persistentSerialNum; - - entryLocal->fileRepResyncState = FileRepResyncStateInitialized; - - fileRepResyncShmem->writeCount++; - - } - -exit: - FileRepResync_LockRelease(); - - return status; -} - - -static FileRepResyncHashEntry_s * -FileRepResync_LookupEntry(FileName fileName) -{ - FileRepResyncHashEntry_s *entry; - char key[MAXPGPATH + 1]; - bool foundPtr; - - snprintf(key, sizeof(key), "%s", fileName); - - Assert(fileRepResyncShmem->fileRepResyncHash != NULL); - - entry = (FileRepResyncHashEntry_s *) hash_search( - fileRepResyncShmem->fileRepResyncHash, - (void *) &key, - HASH_ENTER_NULL, - &foundPtr); - - if (Debug_filerep_print) - { - if (entry == NULL) - elog(LOG, "FileRepResync_LookupEntry() could not find resync entry identifier:'%s' ", fileName); - } - - return entry; -} - -static bool -FileRepResync_RemoveEntry(FileName fileName) -{ - - FileRepResyncHashEntry_s *entry; - char key[MAXPGPATH + 1]; - bool isRemoved = FALSE; - - snprintf(key, sizeof(key), "%s", fileName); - - Assert(fileRepResyncShmem->fileRepResyncHash != NULL); - - entry = hash_search(fileRepResyncShmem->fileRepResyncHash, - (void *) &key, - HASH_REMOVE, - NULL); - - if (entry) - { - if (Debug_filerep_print) - elog(LOG, "FileRepResync_RemoveEntry() removed resync entry identifier:'%s' ", fileName); - isRemoved = TRUE; - } - - return isRemoved; -} - -static int -FileRepResync_CheckProgress(void) -{ - FileRepResyncHashEntry_s *entry = NULL; - HASH_SEQ_STATUS hash_status; - int countProgress = 0; - - FileRepResync_LockAcquire(); - - Assert(fileRepResyncShmem->fileRepResyncHash != NULL); - - if (fileRepResyncShmem->resyncCompletedCount > 0) - { - - hash_seq_init(&hash_status, fileRepResyncShmem->fileRepResyncHash); - - while ((entry = (FileRepResyncHashEntry_s *) hash_seq_search(&hash_status)) != NULL) - { - switch (entry->fileRepResyncState) - { - case FileRepResyncStateInitialized: - case FileRepResyncStateInProgress: - - break; - - case FileRepResyncStateCompleted: - - /* - * Release Resynchronize Lock on relation that was taken - * before fetching the relation - */ - UnlockRelationForResynchronize( - &entry->relFileNode, - AccessExclusiveLock); - - if (FileRepResync_RemoveEntry(entry->fileName) == TRUE) - { - fileRepResyncShmem->resyncCompletedCount--; - Assert(fileRepResyncShmem->resyncCompletedCount >= 0); - } - else - { - Assert(0); - } - - fileRepResyncShmem->blocksSynchronized += entry->mirrorBufpoolResyncChangedPageCount; - - /* - * PersistentFileSysObj_ResynchronizeRelationComplete() - * issues IOs. That may be long operation especially if IO - * is issued while segment is transitioning to change - * tracking. - */ - FileRepResync_LockRelease(); - - if (Debug_filerep_print) - { - elog(LOG, "FileRepResync_CheckProgress() identifier:'%s' state:'%d' resyncCompletedCount:'%d' " - "blocks synchronized: " INT64_FORMAT " ", - entry->fileName, - entry->fileRepResyncState, - fileRepResyncShmem->resyncCompletedCount, - fileRepResyncShmem->blocksSynchronized); - } - - PersistentFileSysObj_ResynchronizeRelationComplete( - &entry->persistentTid, - entry->persistentSerialNum, - entry->mirrorAppendOnlyNewEof, - TRUE); - - FileRepResync_LockAcquire(); - - break; - - /* FileRepResyncStateFault is not in use */ - case FileRepResyncStateFault: - case FileRepResyncStateNotInitialized: - Assert(0); - break; - } - } - } - -#ifdef FAULT_INJECTOR - if (fileRepResyncShmem->resyncInProgressCount > 10) - FaultInjector_InjectFaultIfSet( - FileRepResyncInProgress, - DDLNotSpecified, - "", //databaseName - ""); - //tableName -#endif - - countProgress = fileRepResyncShmem->resyncCompletedCount + - fileRepResyncShmem->writeCount + - fileRepResyncShmem->resyncInProgressCount; - - FileRepResync_LockRelease(); - - return countProgress; -} - -/* - * This function returns either of two output parameters. For relations that - * can be resynchronized using changed blocks recorded in CT log, "request" - * object is created and returned as output parameter. These are the relations - * whose mirrorDataSynchronizationState in persistent table is PageIncremental. - * E.g. regular heap tables on which insert/update/delete was run while primary - * was in changetracking. Second category of relations are appendonly tables - * or heap tables whose mirrorDataSynchronizationState is ScanIncremental. - * These are persistent tables and heap tables that were truncated when primary - * was in changetracking. Changed blocks recorded in CT log are NOT used for - * resynchronizing these tables. The CT hash entry is directly returned in - * this case. - */ -FileRepResyncHashEntry_s * -FileRepPrimary_GetResyncEntry(ChangeTrackingRequest **request) -{ - bool found = FALSE; - FileRepResyncHashEntry_s *entry = NULL; - HASH_SEQ_STATUS hash_status; - int NumberOfRelations = 0; - ChangeTrackingRequest *requestLocal = NULL; - int64 changedPageCount = 0; - - FileRepResync_LockAcquire(); - - Assert(fileRepResyncShmem->fileRepResyncHash != NULL); - - if (fileRepResyncShmem->writeCount > 0) - { - - hash_seq_init(&hash_status, fileRepResyncShmem->fileRepResyncHash); - - while ((entry = (FileRepResyncHashEntry_s *) hash_seq_search(&hash_status)) != NULL) - { - if (entry->fileRepResyncState != FileRepResyncStateInitialized) - { - continue; - } - - if (entry->mirrorDataSynchronizationState == MirroredRelDataSynchronizationState_BufferPoolPageIncremental) - { - changedPageCount += entry->mirrorBufpoolResyncChangedPageCount; - - if (changedPageCount > gp_filerep_ct_batch_size) - { - if (NumberOfRelations == 0) - { - NumberOfRelations++; - } - hash_seq_term(&hash_status); - break; - } - - NumberOfRelations++; - } - else - { - if (NumberOfRelations > 0) - { - /* - * if first entry has BufferPoolPageIncremental state then - * group only relations with BufferPoolPageIncremental for - * next resync. - */ - continue; - } - hash_seq_term(&hash_status); - found = TRUE; - entry->fileRepResyncState = FileRepResyncStateInProgress; - fileRepResyncShmem->writeCount--; - fileRepResyncShmem->resyncInProgressCount++; - - Assert(fileRepResyncShmem->writeCount >= 0); - - if (Debug_filerep_print) - elog(LOG, - "FileRepPrimary_GetResyncEntry() identifier:'%s' " - "mirrorDataSynchronizationState:'%s(%d)' ", - entry->fileName, - MirroredRelDataSynchronizationState_Name(entry->mirrorDataSynchronizationState), - entry->mirrorDataSynchronizationState); - - break; - } - } - - if (NumberOfRelations > 0) - { - int count = 0; - - requestLocal = ChangeTracking_FormRequest(NumberOfRelations); - - hash_seq_init(&hash_status, fileRepResyncShmem->fileRepResyncHash); - - while (count < NumberOfRelations && - (entry = (FileRepResyncHashEntry_s *) hash_seq_search(&hash_status)) != NULL) - { - if (entry->fileRepResyncState != FileRepResyncStateInitialized) - { - continue; - } - - if (entry->mirrorDataSynchronizationState == MirroredRelDataSynchronizationState_BufferPoolPageIncremental) - { - - /* - * When a single relation has more changed blocks than - * gp_filerep_ct_batch_size, it must be called in - * ChangeTracking_GetChanges() by itself (with no other - * relation). The GetChanges() routine will return the - * first batch of changes, plus an indication that - * GetChanges() did not finish with this relation - * (ask_for_more flag). The caller must invoke - * GetChanges() for this relation again (when ready) and - * pass the last block number from the previous call as - * the beginning block number for this call. GetChanges() - * will then return the next batch of changes and this - * will continue until ask_for_more flag is returned as - * false. - * - * If GetChanges() was called with more than 1 relation - * (persistent serial number) at a time AND it sees more - * than gp_filerep_ct_batch_size changes it will be an - * internal error. - */ - if (entry->mirrorBufpoolResyncChangedPageCount > gp_filerep_ct_batch_size) - { - Assert(NumberOfRelations == 1); - } - - ChangeTracking_AddRequestEntry(requestLocal, entry->relFileNode); - found = TRUE; - fileRepResyncShmem->writeCount--; - fileRepResyncShmem->resyncInProgressCount++; - entry->fileRepResyncState = FileRepResyncStateInProgress; - count++; - - Assert(fileRepResyncShmem->writeCount >= 0); - - if (Debug_filerep_print) - elog(LOG, - "FileRepPrimary_GetResyncEntry() identifier:'%s' NumberOfRelations:'%d' " - "mirrorDataSynchronizationState:'%s(%d)' count:'%d' ", - entry->fileName, - NumberOfRelations, - MirroredRelDataSynchronizationState_Name(entry->mirrorDataSynchronizationState), - entry->mirrorDataSynchronizationState, - count); - } - } - if (entry != NULL) - { - hash_seq_term(&hash_status); - entry = NULL; - } - Insist(requestLocal->count == NumberOfRelations); - *request = requestLocal; - - } - } - - FileRepResync_LockRelease(); - - if (found == FALSE) - { - entry = NULL; - } - - return entry; -} - -int -FileRepResync_UpdateEntry( - FileRepResyncHashEntry_s *entry) -{ - FileRepResyncHashEntry_s *entryLocal; - int status = STATUS_OK; - - FileRepResync_LockAcquire(); - - entryLocal = FileRepResync_LookupEntry(entry->fileName); - - if (entryLocal != NULL) - { - fileRepResyncShmem->resyncCompletedCount++; - fileRepResyncShmem->resyncInProgressCount--; - - entryLocal->fileRepResyncState = FileRepResyncStateCompleted; - - if (entryLocal->mirrorBufpoolResyncChangedPageCount == 0) - { - entryLocal->mirrorBufpoolResyncChangedPageCount = entry->mirrorBufpoolResyncChangedPageCount; - } - - Assert(fileRepResyncShmem->resyncInProgressCount >= 0); - - } - else - { - Assert(0); - status = STATUS_ERROR; - } - - if (Debug_filerep_print) - { - elog(LOG, "FileRepResync_UpdateEntry() identifier:'%s' state:'%d' resyncCompletedCount:'%d' ", - entry->fileName, - entry->fileRepResyncState, - fileRepResyncShmem->resyncCompletedCount); - } - - FileRepResync_LockRelease(); - - return status; -} diff --git a/src/backend/cdb/cdbfilerepresyncworker.c b/src/backend/cdb/cdbfilerepresyncworker.c deleted file mode 100644 index 8f4c4a6371..0000000000 --- a/src/backend/cdb/cdbfilerepresyncworker.c +++ /dev/null @@ -1,812 +0,0 @@ -/*------------------------------------------------------------------------- - * - * cdbfilerepresyncworker.c - * - * Portions Copyright (c) 2009-2010 Greenplum Inc. All rights reserved. - * Portions Copyright (c) 2012-Present Pivotal Software, Inc. - * - * - * IDENTIFICATION - * src/backend/cdb/cdbfilerepresyncworker.c - * - *------------------------------------------------------------------------- - */ - -#include "postgres.h" - -#include -#include - -#include "cdb/cdbvars.h" -#include "cdb/cdbfilerep.h" -#include "cdb/cdbfilerepprimary.h" -#include "cdb/cdbfilerepprimaryrecovery.h" -#include "cdb/cdbfilerepservice.h" -#include "cdb/cdbresynchronizechangetracking.h" -#include "cdb/cdbfilerepresyncmanager.h" -#include "cdb/cdbfilerepresyncworker.h" -#include "cdb/cdbmirroredappendonly.h" -#include "storage/bufmgr.h" -#include "storage/lmgr.h" -#include "storage/smgr.h" -#include "utils/faultinjector.h" -#include "utils/relcache.h" - -#define OIDCHARS 10 /* max chars printed by %u */ - -static int FileRepPrimary_RunResyncWorker(void); -static int FileRepPrimary_ResyncWrite(FileRepResyncHashEntry_s *entry); -static int FileRepPrimary_ResyncBufferPoolIncrementalWrite(ChangeTrackingRequest *request); - -static bool readBufferRequest = FALSE; -static void FileRepResync_ResetReadBufferRequest(void); -static void FileRepResync_SetReadBufferRequest(void); - -static void -FileRepResync_ResetReadBufferRequest(void) -{ - readBufferRequest = FALSE; -} - -static void -FileRepResync_SetReadBufferRequest(void) -{ - readBufferRequest = TRUE; -} - -bool -FileRepResyncWorker_IsResyncRequest(void) -{ - return (readBufferRequest == FALSE && FileRepPrimary_IsResyncWorker()); -} - -/* - * 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; - - } -} - -/* - * FileRepPrimary_RunResyncWorker() - * - */ -static int -FileRepPrimary_RunResyncWorker(void) -{ - int status = STATUS_OK; - FileRepResyncHashEntry_s *entry = NULL; - ChangeTrackingRequest *request = NULL; - - FileRep_InsertConfigLogEntry("run resync worker"); - - while (1) - { - - FileRepSubProcess_ProcessSignals(); - - if (!(FileRepSubProcess_GetState() == FileRepStateReady && - dataState == DataStateInResync)) - { - break; - } - - entry = FileRepPrimary_GetResyncEntry(&request); - - if (entry == NULL && request == NULL) - { - - pg_usleep(100000L); /* 100 ms */ - continue; - } - - Assert(!(entry != NULL && request != NULL)); - - if (entry != NULL) - { - status = FileRepPrimary_ResyncWrite(entry); - - if (status == STATUS_OK) - { - if (entry->mirrorBufpoolResyncChangedPageCount == 0) - { - entry->mirrorBufpoolResyncChangedPageCount = (entry->mirrorAppendOnlyNewEof - entry->mirrorAppendOnlyLossEof) / BLCKSZ; - } - - status = FileRepResync_UpdateEntry(entry); - } - } - - if (request != NULL) - { - status = FileRepPrimary_ResyncBufferPoolIncrementalWrite(request); - request = NULL; - } - - if (status != STATUS_OK) - { - break; - } - - } - - return status; -} - -/* - * - * RESYNC relation (Buffer Pool) - * INPUT parameters - * *) RelFileNode - * *) beginLSN (the earliest LSN to be re-synchronized) - * *) endLSN (the latest LSN to be re-synchronized) - * *) endBlockNumber (the latest block in relation to be re-synchronized) - * *) - * - * - * RESYNC relation (Append Only) - * INPUT parameters - * *) RelFileNode - * *) - * - * The following relations will be always resynced as scan incremental - * OIDs {5090, 5091, 5092, 5093, and 5096} - * - */ - -static int -FileRepPrimary_ResyncWrite(FileRepResyncHashEntry_s *entry) -{ - - int status = STATUS_OK; - Page page; - Buffer buf; - BlockNumber numBlocks; - BlockNumber blkno; - SMgrRelation smgr_relation; - char relidstr[OIDCHARS + 1 + OIDCHARS + 1 + OIDCHARS + 1]; - XLogRecPtr loc; - int count = 0; - int thresholdCount = 0; - bool mirrorDataLossOccurred = FALSE; - - switch (entry->relStorageMgr) - { - - case PersistentFileSysRelStorageMgr_BufferPool: - - switch (entry->mirrorDataSynchronizationState) - { - case MirroredRelDataSynchronizationState_BufferPoolScanIncremental: - case MirroredRelDataSynchronizationState_FullCopy: - - smgr_relation = smgropen(entry->relFileNode); - - numBlocks = smgrnblocks(smgr_relation, MAIN_FORKNUM); - - snprintf(relidstr, sizeof(relidstr), "%u/%u/%u", - smgr_relation->smgr_rnode.spcNode, - smgr_relation->smgr_rnode.dbNode, - smgr_relation->smgr_rnode.relNode); - - if (Debug_filerep_print) - elog(LOG, "resync buffer pool relation '%s' number of blocks '%d' ", - relidstr, numBlocks); - - thresholdCount = Min(numBlocks, 1024); - - /* - * required in order to report how many blocks were - * synchronized if gp_persistent_relation_node does not - * return that information - */ - if (entry->mirrorBufpoolResyncChangedPageCount == 0) - { - entry->mirrorBufpoolResyncChangedPageCount = numBlocks - entry->mirrorBufpoolResyncCkptBlockNum; - } - - for (blkno = entry->mirrorBufpoolResyncCkptBlockNum; blkno < numBlocks; blkno++) - { - XLogRecPtr endResyncLSN = (isFullResync() ? - FileRepResync_GetEndFullResyncLSN() : - FileRepResync_GetEndIncrResyncLSN()); - - SIMPLE_FAULT_INJECTOR(FileRepResyncWorkerRead); - - FileRepResync_SetReadBufferRequest(); - buf = ReadBuffer_Resync(smgr_relation, blkno); - FileRepResync_ResetReadBufferRequest(); - - LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE); - page = BufferGetPage(buf); - - loc = PageGetLSN(page); - - if (Debug_filerep_print) - { - elog(LOG, - "full resync buffer pool identifier '%s' num blocks '%d' blkno '%d' lsn begin change tracking '%s(%u/%u)' " - "lsn page '%s(%u/%u)' lsn end change tracking '%s(%u/%u)' ", - relidstr, - numBlocks, - blkno, - XLogLocationToString(&entry->mirrorBufpoolResyncCkptLoc), - entry->mirrorBufpoolResyncCkptLoc.xlogid, - entry->mirrorBufpoolResyncCkptLoc.xrecoff, - XLogLocationToString(&loc), - loc.xlogid, - loc.xrecoff, - XLogLocationToString(&endResyncLSN), - endResyncLSN.xlogid, - endResyncLSN.xrecoff); - } - - if (XLByteLE(PageGetLSN(page), endResyncLSN) && - XLByteLE(entry->mirrorBufpoolResyncCkptLoc, PageGetLSN(page))) - { - /* - * Because filerep sync is a special case, we - * don't do our write through the buffer pool. We - * need to recalculate the checksum for every page - * that we ship via resync. We only recalculate - * the checksum in a copy of the buffer, leaving - * the version in shared buffer alone. As a - * result, the version written to disk gets the - * correct checksum, but the buffer checksum is - * inconsistent with the buffer's data. - * - * If we don't first calculate the checksum, we - * are likely to be sending over a page that isn't - * dirty, but still has the old checksum from the - * original disk read not the one that has been - * written. - */ - - char *pageCopy = PageSetChecksumCopy(page, blkno); - - smgrwrite(smgr_relation, - MAIN_FORKNUM, - blkno, - pageCopy, - FALSE); - } - - SIMPLE_FAULT_INJECTOR(FileRepResyncWorker); - - UnlockReleaseBuffer(buf); - - if (count > thresholdCount) - { - count = 0; - FileRepSubProcess_ProcessSignals(); - - if (!(FileRepSubProcess_GetState() == FileRepStateReady && - dataState == DataStateInResync)) - { - mirrorDataLossOccurred = TRUE; - break; - } - } - else - count++; - } - - if (mirrorDataLossOccurred) - break; - - if (entry->mirrorDataSynchronizationState != MirroredRelDataSynchronizationState_FullCopy) - { - LockRelationForResyncExtension(&smgr_relation->smgr_rnode, ExclusiveLock); - - numBlocks = smgrnblocks(smgr_relation, MAIN_FORKNUM); - - /* GPDB_84_MERGE_FIXME: Should this call RelationTruncate() instead? - * I don't understand where or when this gets called. In the primary or - * mirror? Should we also truncate FSM and VM? - */ - smgrtruncate(smgr_relation, - MAIN_FORKNUM, - numBlocks, - TRUE /* isTemp, TRUE means to not - * record in XLOG */); - - UnlockRelationForResyncExtension(&smgr_relation->smgr_rnode, ExclusiveLock); - } - - smgrimmedsync(smgr_relation, MAIN_FORKNUM); - smgrclose(smgr_relation); - - smgr_relation = NULL; - break; - - case MirroredRelDataSynchronizationState_None: - case MirroredRelDataSynchronizationState_DataSynchronized: - break; - - default: - ereport(LOG, - (errmsg("could not resynchronize relation '%u/%u/%u' " - "mirror synchronization state:'%s(%d)' ", - entry->relFileNode.relNode, - entry->relFileNode.spcNode, - entry->relFileNode.dbNode, - MirroredRelDataSynchronizationState_Name(entry->mirrorDataSynchronizationState), - entry->mirrorDataSynchronizationState))); - break; - } - break; - - case PersistentFileSysRelStorageMgr_AppendOnly: - { - MirroredAppendOnlyOpen mirroredOpen; - int primaryError; - bool mirrorDataLossOccurred; - char *buffer = NULL; - int64 endOffset = entry->mirrorAppendOnlyNewEof; - int64 startOffset = entry->mirrorAppendOnlyLossEof; - int32 bufferLen = 0; - int retval = 0; - - switch (entry->mirrorDataSynchronizationState) - { - case MirroredRelDataSynchronizationState_AppendOnlyCatchup: - case MirroredRelDataSynchronizationState_FullCopy: - - /* - * required in order to report how many blocks were - * synchronized if gp_persistent_relation_node does - * not return that information - */ - if (entry->mirrorBufpoolResyncChangedPageCount == 0) - { - entry->mirrorBufpoolResyncChangedPageCount = (endOffset - startOffset) / BLCKSZ; - } - - /* - * The MirroredAppendOnly_OpenResynchonize routine - * knows we are a resynch worker and will open BOTH, - * but write only the MIRROR!!! - */ - MirroredAppendOnly_OpenResynchonize( - &mirroredOpen, - &entry->relFileNode, - entry->segmentFileNum, - startOffset, - &primaryError, - &mirrorDataLossOccurred); - if (primaryError != 0) - { - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not open file %u/%u/%u.%u : %s", - entry->relFileNode.dbNode, - entry->relFileNode.spcNode, - entry->relFileNode.relNode, - entry->segmentFileNum, - strerror(primaryError)))); - - break; - } - - if (mirrorDataLossOccurred) - break; - - /* AO and CO Data Store writes 64k size by default */ - bufferLen = (Size) Min(2 * BLCKSZ, endOffset - startOffset); - buffer = (char *) palloc(bufferLen); - MemSet(buffer, 0, bufferLen); - - while (startOffset < endOffset) - { - retval = MirroredAppendOnly_Read( - &mirroredOpen, - buffer, - bufferLen); - - if (retval != bufferLen) - { - ereport(ERROR, - (errcode_for_file_access(), - errmsg("could not read from position:" INT64_FORMAT " in file %u/%u/%u.%u : %m", - startOffset, - entry->relFileNode.dbNode, - entry->relFileNode.spcNode, - entry->relFileNode.relNode, - entry->segmentFileNum))); - - break; - } - - MirroredAppendOnly_Append( - &mirroredOpen, - buffer, - bufferLen, - &primaryError, - &mirrorDataLossOccurred); - - if (mirrorDataLossOccurred) - break; - - Assert(primaryError == 0); - //No primary writes as resync worker. - - startOffset += bufferLen; - /* AO and CO Data Store writes 64k size by default */ - bufferLen = (Size) Min(2 * BLCKSZ, endOffset - startOffset); - } - - pfree(buffer); - buffer = NULL; - - if (mirrorDataLossOccurred) - break; - - /* Flush written data on Mirror */ - MirroredAppendOnly_Flush( - &mirroredOpen, - &primaryError, - &mirrorDataLossOccurred); - if (mirrorDataLossOccurred) - break; - - Assert(primaryError == 0); - //Not flushed on primary as resync worker. - - /* Close Primary and Mirror */ - MirroredAppendOnly_Close( - &mirroredOpen, - &mirrorDataLossOccurred); - - break; - - case MirroredRelDataSynchronizationState_None: - case MirroredRelDataSynchronizationState_DataSynchronized: - break; - - default: - ereport(LOG, - (errmsg("could not resynchronize relation '%u/%u/%u' " - "mirror synchronization state:'%s(%d)' ", - entry->relFileNode.relNode, - entry->relFileNode.spcNode, - entry->relFileNode.dbNode, - MirroredRelDataSynchronizationState_Name(entry->mirrorDataSynchronizationState), - entry->mirrorDataSynchronizationState))); - break; - } - - break; - } //case - default: - Assert(0); - break; - } //switch - - if (mirrorDataLossOccurred) - status = STATUS_ERROR; - - return status; -} - -static int -FileRepPrimary_ResyncBufferPoolIncrementalWrite(ChangeTrackingRequest *request) -{ - int status = STATUS_OK; - Page page; - Buffer buf; - BlockNumber numBlocks = 0; - SMgrRelation smgr_relation = NULL; - char relidstr[OIDCHARS + 1 + OIDCHARS + 1 + OIDCHARS + 1]; - int ii; - XLogRecPtr loc; - int count = 0; - int thresholdCount = 0; - bool mirrorDataLossOccurred = FALSE; - int NumberOfRelations = request->count; - - FileRepResyncHashEntry_s entry; - ChangeTrackingResult *result = NULL; - - while (1) - { - /* - * ChangeTracking_GetChanges() invokes a SQL query using SPI, which - * could result in dirty buffers being written out. Setting - * readBufferRequest indicates that these writes are performed on - * primary as well as mirror. When readBufferRequest flag is unset, - * resync workers send changed blocks only to mirror without writing - * them on primary. - */ - FileRepResync_SetReadBufferRequest(); - if ((result = ChangeTracking_GetChanges(request)) != NULL) - { - FileRepResync_ResetReadBufferRequest(); - - for (ii = 0; ii < result->count; ii++) - { - - if (smgr_relation == NULL) - { - NumberOfRelations--; - - smgr_relation = smgropen(result->entries[ii].relFileNode); - - snprintf(relidstr, sizeof(relidstr), "%u/%u/%u", - smgr_relation->smgr_rnode.spcNode, - smgr_relation->smgr_rnode.dbNode, - smgr_relation->smgr_rnode.relNode); - - numBlocks = smgrnblocks(smgr_relation, MAIN_FORKNUM); - - if (Debug_filerep_print) - elog(LOG, "resynchronize buffer pool relation '%u/%u/%u' " - "number of blocks:'%u' ", - smgr_relation->smgr_rnode.spcNode, - smgr_relation->smgr_rnode.dbNode, - smgr_relation->smgr_rnode.relNode, - numBlocks); - - thresholdCount = Min(numBlocks, 1024); - } - - /* - * if relation was truncated then block_num from change - * tracking can be beyond numBlocks - */ - const BlockNumber blkno = result->entries[ii].block_num; - - if (blkno >= numBlocks) - { - ereport(LOG, - (errmsg("could not resynchonize buffer pool relation '%s' block '%d' (maybe due to truncate), " - "lsn change tracking '%X/%X' " - "number of blocks '%d' ", - relidstr, - blkno, - result->entries[ii].lsn_end.xlogid, - result->entries[ii].lsn_end.xrecoff, - numBlocks), - FileRep_errcontext())); - - goto flush_check; - } - - /* - * ReadBuffer() may need to write out a dirty buffer to make - * room in buffer cache. Setting readBufferRequest indicates - * that resync worker process should perform writes on - * primary. When readBufferRequest flag is unset, resync - * workers send changed blocks only to mirror without writing - * them on primary. - */ - FileRepResync_SetReadBufferRequest(); - buf = ReadBuffer_Resync(smgr_relation, - blkno); - FileRepResync_ResetReadBufferRequest(); - - Assert(blkno < numBlocks); - - LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE); - page = BufferGetPage(buf); - - loc = PageGetLSN(page); - - if (Debug_filerep_config_print) - { - elog(LOG, - "incremental resync buffer pool identifier '%s' num blocks '%d' blkno '%d' lsn page '%X/%X' " - "lsn end change tracking '%X/%X' ", - relidstr, - numBlocks, - blkno, - loc.xlogid, - loc.xrecoff, - result->entries[ii].lsn_end.xlogid, - result->entries[ii].lsn_end.xrecoff); - } - - if (XLByteLE(result->entries[ii].lsn_end, PageGetLSN(page))) - { - if (!XLByteEQ(PageGetLSN(page), result->entries[ii].lsn_end)) - { - ereport(LOG, - (errmsg("Resynchonize buffer pool relation '%s' block '%d' has page lsn more than CT lsn, " - "lsn end change tracking '%X/%X' lsn page '%X/%X' " - "number of blocks '%d'", - relidstr, - blkno, - loc.xlogid, - loc.xrecoff, - result->entries[ii].lsn_end.xlogid, - result->entries[ii].lsn_end.xrecoff, - numBlocks), - FileRep_errcontext())); - - } - - /* - * We checksum every page before replicating for the - * reasons described in FileRepPrimary_ResyncWrite above - */ - char *pageCopy = PageSetChecksumCopy(page, blkno); - - /* - * It's safe and better to perform write of the page to - * mirror, for this case, as primary and mirror data pages - * should always be same. So, we might do some extra work - * but definitely won't lose out blocks, or error out and - * need to perform full recovery. Need to cover for this - * case as there are some known scenarios where CT file - * can have extra records which should have been - * discarded, but as we loose out information of xlog LSN - * cannot be discarded. One such case is when CT_TRANSIENT - * being compacted to CT_COMPACT with specific xlog LSN - * (to discard extra records) in CT mode gets interrupted - * by resync. Compaction during Resync collects all the CT - * records and doesn't have xlog LSN information to - * discard any extra records from CT_TRANSIENT. - */ - smgrwrite(smgr_relation, - MAIN_FORKNUM, - blkno, - pageCopy, - FALSE); - } - - SIMPLE_FAULT_INJECTOR(FileRepResyncWorker); - - UnlockReleaseBuffer(buf); - - SIMPLE_FAULT_INJECTOR(FileRepResyncWorker); - - flush_check: - if (((ii + 1) == result->count) || - !(result->entries[ii].relFileNode.spcNode == result->entries[ii + 1].relFileNode.spcNode && - result->entries[ii].relFileNode.dbNode == result->entries[ii + 1].relFileNode.dbNode && - result->entries[ii].relFileNode.relNode == result->entries[ii + 1].relFileNode.relNode)) - { - if (result->ask_for_more == false) - { - smgrimmedsync(smgr_relation, MAIN_FORKNUM); - - smgrclose(smgr_relation); - - smgr_relation = NULL; - - FileRep_GetRelationPath( - entry.fileName, - result->entries[ii].relFileNode, - 0 /* segment file number is - * always 0 for Buffer - * Pool */ ); - - /* - * We only want to update the state with this call to - * FileRepResync_UpdateEntry(), so to ensure that we - * don't incur any sideeffects set the changed page - * count to zero as it will only be updated to if the - * hashtable entry changed page count is zero. - */ - entry.mirrorBufpoolResyncChangedPageCount = 0; - status = FileRepResync_UpdateEntry(&entry); - if (status != STATUS_OK) - { - break; - } - } - else - { - Assert(result->count == gp_filerep_ct_batch_size); - Assert(request->count == 1); - - /* - * Update last_fetched block in request so that the - * next call to GetChanges() knows where to start - * fetching changed blocks from. - */ - if (RelFileNodeEquals(request->entries[0].relFileNode, - result->entries[ii].relFileNode)) - { - request->entries[0].last_fetched = - blkno; - elog(LOG, "%u/%u/%u last fetched block %d", - request->entries[0].relFileNode.spcNode, - request->entries[0].relFileNode.dbNode, - request->entries[0].relFileNode.relNode, - request->entries[0].last_fetched); - } - else - elog(ERROR, "changetracking request not found for " - "%u/%u/%u, block %d", - result->entries[ii].relFileNode.spcNode, - result->entries[ii].relFileNode.dbNode, - result->entries[ii].relFileNode.relNode, - blkno); - } - } - - if (count > thresholdCount) - { - count = 0; - FileRepSubProcess_ProcessSignals(); - - if (!(FileRepSubProcess_GetState() == FileRepStateReady && - dataState == DataStateInResync)) - { - mirrorDataLossOccurred = TRUE; - break; - } - } - else - count++; - } - } - FileRepResync_ResetReadBufferRequest(); - if (result == NULL || result->ask_for_more == false) - break; - } - - ChangeTracking_FreeRequest(request); - ChangeTracking_FreeResult(result); - - Insist(NumberOfRelations == 0); - - if (mirrorDataLossOccurred) - status = STATUS_ERROR; - - return status; -} diff --git a/src/backend/cdb/cdbfilerepservice.c b/src/backend/cdb/cdbfilerepservice.c index 718bffe011..742ec004c2 100644 --- a/src/backend/cdb/cdbfilerepservice.c +++ b/src/backend/cdb/cdbfilerepservice.c @@ -27,8 +27,6 @@ #include "cdb/cdbfilerepprimaryrecovery.h" #include "cdb/cdbfilerepmirror.h" #include "cdb/cdbfilerepmirrorack.h" -#include "cdb/cdbfilerepresyncmanager.h" -#include "cdb/cdbfilerepresyncworker.h" #include "cdb/cdbvars.h" #include "libpq/pqsignal.h" #include "postmaster/postmaster.h" @@ -150,20 +148,7 @@ FileRepSubProcess_ShutdownHandler(SIGNAL_ARGS) if (isInTransition == TRUE && dataStateTransition == DataStateInChangeTracking) { - /* - * Resync workers and manager may be waiting on lock that is - * acquired by backend process that is suspended during - * transition to Change Tracking and so FileRep backend - * shutdown may never be completed. - */ - if (fileRepProcessType == FileRepProcessTypeResyncManager) - { - FileRepResync_Cleanup(); - } - else - { - LockReleaseAll(DEFAULT_LOCKMETHOD, false); - } + LockReleaseAll(DEFAULT_LOCKMETHOD, false); /* * We remove ourself from LW waiter list (if applicable). @@ -884,27 +869,6 @@ FileRepSubProcess_Main() false, true); break; - case FileRepProcessTypeResyncManager: - FileRepSubProcess_InitProcess(); - FileRepPrimary_StartResyncManager(); - - ResourceOwnerRelease(CurrentResourceOwner, - RESOURCE_RELEASE_BEFORE_LOCKS, - false, true); - break; - - case FileRepProcessTypeResyncWorker1: - case FileRepProcessTypeResyncWorker2: - case FileRepProcessTypeResyncWorker3: - case FileRepProcessTypeResyncWorker4: - FileRepSubProcess_InitProcess(); - FileRepPrimary_StartResyncWorker(); - - ResourceOwnerRelease(CurrentResourceOwner, - RESOURCE_RELEASE_BEFORE_LOCKS, - false, true); - break; - default: elog(PANIC, "unrecognized process type: %s(%d)", statmsg, fileRepProcessType); diff --git a/src/backend/cdb/cdbmirroredbufferpool.c b/src/backend/cdb/cdbmirroredbufferpool.c index 0ee182e0c1..93b5930315 100755 --- a/src/backend/cdb/cdbmirroredbufferpool.c +++ b/src/backend/cdb/cdbmirroredbufferpool.c @@ -24,8 +24,6 @@ #include "catalog/pg_tablespace.h" #include "cdb/cdbfilerepprimary.h" #include "cdb/cdbmirroredbufferpool.h" -#include "cdb/cdbfilerepresyncmanager.h" -#include "cdb/cdbfilerepresyncworker.h" #include "cdb/cdbfilerepprimary.h" #include "cdb/cdbpersistenttablespace.h" #include "cdb/cdbpersistentstore.h" @@ -461,7 +459,7 @@ MirroredBufferPool_Open( mirrorDataLossTrackingSessionNum, /* create */ false, /* mirrorOnly */ false, - /* copyToMirror */ FileRepResyncWorker_IsResyncRequest(), + /* copyToMirror */ false, primaryError, mirrorDataLossOccurred); @@ -614,8 +612,7 @@ MirroredBufferPool_Flush( open->mirrorDataLossOccurred = FileRepPrimary_IsMirrorDataLossOccurred(); } - if (StorageManagerMirrorMode_DoPrimaryWork(open->mirrorMode) && - !FileRepResyncWorker_IsResyncRequest()) + if (StorageManagerMirrorMode_DoPrimaryWork(open->mirrorMode)) { errno = 0; @@ -791,8 +788,7 @@ MirroredBufferPool_Write( } - if (StorageManagerMirrorMode_DoPrimaryWork(open->mirrorMode) && - !FileRepResyncWorker_IsResyncRequest()) + if (StorageManagerMirrorMode_DoPrimaryWork(open->mirrorMode)) { errno = 0; @@ -1553,8 +1549,7 @@ MirroredBufferPool_Truncate( open->mirrorDataLossOccurred = FileRepPrimary_IsMirrorDataLossOccurred(); } - if (StorageManagerMirrorMode_DoPrimaryWork(open->mirrorMode) && - !FileRepResyncWorker_IsResyncRequest()) + if (StorageManagerMirrorMode_DoPrimaryWork(open->mirrorMode)) { errno = 0; diff --git a/src/backend/cdb/cdbpersistentfilesysobj.c b/src/backend/cdb/cdbpersistentfilesysobj.c index c529f440b6..bbf31bae43 100755 --- a/src/backend/cdb/cdbpersistentfilesysobj.c +++ b/src/backend/cdb/cdbpersistentfilesysobj.c @@ -33,7 +33,6 @@ #include "cdb/cdbmirroredfilesysobj.h" #include "cdb/cdbdirectopen.h" #include "cdb/cdbfilerepservice.h" -#include "cdb/cdbfilerepresyncmanager.h" #include "cdb/cdbresynchronizechangetracking.h" #include "cdb/cdbmirroredbufferpool.h" #include "cdb/cdbmirroredappendonly.h" @@ -4639,8 +4638,6 @@ static void PersistentFileSysObj_ScanStateAction( } - FileRepResync_AddToTotalBlocksToSynchronize(moreBlocksToSynchronize); - if (Debug_persistent_print) elog(Persistent_DebugPrintLevel(), "StateAction_MarkWholeMirrorFullCopy: Mark '%s' full copy, persistent state '%s', relation storage manager '%s', number of 32k blocks " INT64_FORMAT ", old mirror existence state '%s', new mirror existence state '%s', serial number " INT64_FORMAT " at TID %s", @@ -4712,8 +4709,6 @@ static void PersistentFileSysObj_ScanStateAction( // Don't hold lock during physical file-system operation. WRITE_PERSISTENT_STATE_ORDERED_UNLOCK; - FileRepResync_SetReMirrorAllowed(); - // UNDONE: Pass this in from the resync worker? mirrorDataLossTrackingState = FileRepPrimary_GetMirrorDataLossTrackingSessionNum( @@ -4728,18 +4723,9 @@ static void PersistentFileSysObj_ScanStateAction( mirrorDataLossTrackingSessionNum, &mirrorDataLossOccurred); - FileRepResync_ResetReMirrorAllowed(); - // UNDONE: Act on mirrorDataLossOccurred WRITE_PERSISTENT_STATE_ORDERED_LOCK; - /* - * We calculate only RelationFile objects to create for resync. - * As it seems unnecessary overhead to scan database/tablespace/etc.. - * Hence only decrement for RelationFile. - */ - if (fsObjType == PersistentFsObjType_RelationFile) - FileRepResync_DecFsobjCount(); } else { @@ -4762,15 +4748,11 @@ static void PersistentFileSysObj_ScanStateAction( DatumGetInt16( values[Anum_gp_persistent_relation_node_relation_storage_manager - 1]); - FileRepResync_SetReMirrorAllowed(); - PersistentFileSysObj_DoMirrorValidation( &fsObjName, relStorageMgr, &persistentTid, persistentSerialNum); - - FileRepResync_ResetReMirrorAllowed(); } } break; @@ -4891,9 +4873,6 @@ static void PersistentFileSysObj_ScanStateAction( */ if (StateAction_MirrorReDrop == stateAction) { - /* Set this flag to allow actions on mirror during resync transition */ - FileRepResync_SetReMirrorAllowed(); - mirrorDataLossTrackingState = FileRepPrimary_GetMirrorDataLossTrackingSessionNum( &mirrorDataLossTrackingSessionNum); @@ -4907,19 +4886,6 @@ static void PersistentFileSysObj_ScanStateAction( mirrorDataLossTrackingState, mirrorDataLossTrackingSessionNum, &mirrorDataLossOccurred); - - // UNDONE: Act on mirrorDataLossOccurred - FileRepResync_ResetReMirrorAllowed(); - - /* - * We calculate only RelationFile objects to create for resync. - * As it seems unnecessary overhead to scan database/tablespace/etc.. - * Hence only decrement for RelationFile. - */ - if (fsObjType == PersistentFsObjType_RelationFile) - { - FileRepResync_DecFsobjCount(); - } } else { @@ -5256,8 +5222,6 @@ void PersistentFileSysObj_MarkSpecialScanIncremental(void) PersistentFileSysObj_GetBufferPoolRelationTotalBlocks( PersistentFileSysObjName_GetRelFileNodePtr(&fsObjName)); - FileRepResync_AddToTotalBlocksToSynchronize(numOf32kBlocks); - if (Debug_persistent_print) elog(Persistent_DebugPrintLevel(), "PersistentFileSysObj_MarkSpecialScanIncremental: Mark '%s' needing special scan incremental, number of 32k blocks %d, persistent state '%s', mirror existence state '%s', serial number " INT64_FORMAT " at TID %s", @@ -5295,8 +5259,6 @@ void PersistentFileSysObj_MarkSpecialScanIncremental(void) PersistentFileSysObj_GetBufferPoolRelationTotalBlocks( PersistentFileSysObjName_GetRelFileNodePtr(&fsObjName)); - FileRepResync_AddToTotalBlocksToSynchronize(numOf32kBlocks); - if (Debug_persistent_print) elog(Persistent_DebugPrintLevel(), "PersistentFileSysObj_MarkSpecialScanIncremental: Mark '%s' vacuumed relation as scan incremental, number of 32k blocks %d, persistent state '%s', mirror existence state '%s', serial number " INT64_FORMAT " at TID %s", @@ -5439,8 +5401,6 @@ void PersistentFileSysObj_MarkAppendOnlyCatchup(void) roundedUp32kBlocks = (mirrorAppendOnlyNewEof - mirrorAppendOnlyLossEof + BLCKSZ - 1) / BLCKSZ; - FileRepResync_AddToTotalBlocksToSynchronize(roundedUp32kBlocks); - if (Debug_persistent_print) elog(Persistent_DebugPrintLevel(), "PersistentFileSysObj_MarkAppendOnlyCatchup: Mark '%s' Append-Only relation as needing catch-up (mirror loss EOF " INT64_FORMAT ", mirror new EOF " INT64_FORMAT ", number of 32k blocks " INT64_FORMAT "), persistent state '%s', mirror existence state '%s', serial number " INT64_FORMAT " at TID %s", @@ -5721,8 +5681,6 @@ void PersistentFileSysObj_MarkPageIncrementalFromChangeLog(void) &incrementalChangeList->entries[i].persistentTid, incrementalChangeList->entries[i].persistentSerialNum, incrementalChangeList->entries[i].numblocks); - - FileRepResync_AddToTotalBlocksToSynchronize(incrementalChangeList->entries[i].numblocks); } if (incrementalChangeList != NULL) diff --git a/src/backend/cdb/cdbresynchronizechangetracking.c b/src/backend/cdb/cdbresynchronizechangetracking.c index d2bc73db2c..622d60d857 100644 --- a/src/backend/cdb/cdbresynchronizechangetracking.c +++ b/src/backend/cdb/cdbresynchronizechangetracking.c @@ -41,7 +41,6 @@ #include "utils/snapmgr.h" #include "cdb/cdbfilerep.h" -#include "cdb/cdbfilerepresyncmanager.h" #include "cdb/cdbresynchronizechangetracking.h" #include "cdb/cdbpersistentrelation.h" #include "cdb/cdbpersistentstore.h" @@ -2534,9 +2533,6 @@ ChangeTracking_RecordLastChangeTrackedLoc(void) endResyncLSN = XLogLastChangeTrackedLoc(); - /* the routine stores last LSN in shared memory */ - FileRepResyncManager_SetEndResyncLSN(endResyncLSN); - /* * append "endResyncLSN" (last LSN recorded in Change Tracking log files) * in Change Tracking meta file. "endResyncLSN" also marks the last entry @@ -2639,7 +2635,6 @@ ChangeTracking_RetrieveLastChangeTrackedLoc(void) */ if (!XLByteEQ(recptr->resync_lsn_end, DummyRecPtr)) { - FileRepResyncManager_SetEndResyncLSN(recptr->resync_lsn_end); return recptr->resync_transition_completed; } } diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index f49cf0bc9f..d7bccbf8d8 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -695,13 +695,6 @@ bool Gp_entry_postmaster = false; static int Save_MppLocalProcessCounter = 0; static DistributedTransactionTimeStamp Save_DtxStartTime = 0; -/** resync status info from cdbfilerepresyncmanager.h **/ -extern struct timeval FileRepResync_GetEstimateResyncCompletionTime(void); -extern int64 FileRepResync_GetBlocksSynchronized(void); -extern int64 FileRepResync_GetTotalBlocksToSynchronize(void); -extern int FileRepResync_GetCurFsobjCount(void); -extern int FileRepResync_GetTotalFsobjCount(void); - /* changetracking size info from cdbresynchronizechangetracking.h */ extern int64 ChangeTracking_GetTotalSpaceUsedOnDisk(void); @@ -3083,20 +3076,18 @@ processTransitionRequest_getMirrorStatus(void) getPrimaryMirrorStatusCodes(&pm_mode, &s_state, &d_state, &f_type); - int64 resyncNumCompleted = FileRepResync_GetBlocksSynchronized(); - int64 resyncTotalToComplete = FileRepResync_GetTotalBlocksToSynchronize(); - int64 changeTrackingBytesUsed = ChangeTracking_GetTotalSpaceUsedOnDisk(); + int64 resyncNumCompleted = 0; + int64 resyncTotalToComplete = 0; + int64 changeTrackingBytesUsed = 0; - int fsobjCount = FileRepResync_GetCurFsobjCount(); - int totalFsobjCount = FileRepResync_GetTotalFsobjCount(); + int fsobjCount = 0; + int totalFsobjCount = 0; /** * Note: call this one AFTER calling the others above -- it will return a sentinel * if estimates are invalid, and we want to be sure we get the sentinel * (the system can go from valid to invalid estimates but no vice-versa) */ - struct timeval estimateResyncCompletionTime = FileRepResync_GetEstimateResyncCompletionTime(); - bool isIOSuspended = primaryMirrorIsIOSuspended(); char *databaseStatus; @@ -3153,7 +3144,7 @@ processTransitionRequest_getMirrorStatus(void) resyncNumCompleted, resyncTotalToComplete, changeTrackingBytesUsed, - (int64)estimateResyncCompletionTime.tv_sec, + (int64)0, totalFsobjCount, fsobjCount); diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index f182295ad6..ebfff9791e 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -27,7 +27,6 @@ #include "cdb/cdbfilerep.h" #include "cdb/cdbfilerepprimaryack.h" #include "cdb/cdbfilerepprimaryrecovery.h" -#include "cdb/cdbfilerepresyncmanager.h" #include "cdb/cdblocaldistribxact.h" #include "cdb/cdbpersistentfilesysobj.h" #include "cdb/cdbpersistentfilespace.h" @@ -180,7 +179,6 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port) size = add_size(size, FileRep_ShmemSize()); size = add_size(size, FileRepAck_ShmemSize()); size = add_size(size, FileRepAckPrimary_ShmemSize()); - size = add_size(size, FileRepResync_ShmemSize()); size = add_size(size, FileRepIpc_ShmemSize()); size = add_size(size, FileRepLog_ShmemSize()); } @@ -354,7 +352,6 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port) FileRep_ShmemInit(); FileRepAck_ShmemInit(); FileRepAckPrimary_ShmemInit(); - FileRepResync_ShmemInit(); FileRepIpc_ShmemInit(); FileRepLog_ShmemInit(); } diff --git a/src/include/cdb/cdbfilerepresyncmanager.h b/src/include/cdb/cdbfilerepresyncmanager.h deleted file mode 100644 index 7cfa73edbc..0000000000 --- a/src/include/cdb/cdbfilerepresyncmanager.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * cdbfilerepresyncmanager.h - * - * - * Copyright 2009-2010 Greenplum Inc. All rights reserved. - * - */ - -#ifndef CDBFILEREPRESYNCMANAGER_H -#define CDBFILEREPRESYNCMANAGER_H - -#include "cdb/cdbfilerep.h" -#include "access/persistentfilesysobjname.h" -#include "cdb/cdbresynchronizechangetracking.h" - -/* - * Resync Hash Table located in shared memory keeps - * track of files that are currently in resync. - * One entry per file. - * It has fixed MAX number of files to be resynced - * - */ -typedef struct FileRepResyncHashEntry_s { - - char fileName[MAXPGPATH+1]; - /* - * It identifies mirror relation path. - * It is key. It has to be first field in the structure. - */ - - RelFileNode relFileNode; - - int32 segmentFileNum; - - PersistentFileSysRelStorageMgr relStorageMgr; - /* relationType (Buffer Pool or AppendOnly) */ - - MirroredRelDataSynchronizationState mirrorDataSynchronizationState; - /* relationOperation (Full, IncrPage or IncrScan) */ - - int64 mirrorBufpoolResyncChangedPageCount; - - XLogRecPtr mirrorBufpoolResyncCkptLoc; - /* beginIncrResyncLSN */ - - BlockNumber mirrorBufpoolResyncCkptBlockNum; - - int64 mirrorAppendOnlyLossEof; - - int64 mirrorAppendOnlyNewEof; - - ItemPointerData persistentTid; - - int64 persistentSerialNum; - - FileRepResyncState_e fileRepResyncState; - -} FileRepResyncHashEntry_s; - - - -extern Size FileRepResync_ShmemSize(void); - -extern void FileRepResync_ShmemInit(void); - -extern void FileRepResync_Cleanup(void); - -extern void FileRepPrimary_StartResyncManager(void); - -extern FileRepResyncHashEntry_s* FileRepPrimary_GetResyncEntry(ChangeTrackingRequest **request); - -extern int FileRepResync_UpdateEntry( - FileRepResyncHashEntry_s* entry); - -extern XLogRecPtr FileRepResync_GetEndIncrResyncLSN(void); - -extern XLogRecPtr FileRepResync_GetEndFullResyncLSN(void); - -extern void FileRepResyncManager_SetEndResyncLSN( - XLogRecPtr endResyncLSN); - -extern int FileRepResync_IncAppendOnlyCommitCount(void); - -extern int FileRepResync_DecAppendOnlyCommitCount(int count); - -extern int FileRepResync_GetAppendOnlyCommitCount(void); - -extern bool FileRepResync_IsReMirrorAllowed(void); - -extern void FileRepResync_SetReMirrorAllowed(void); - -extern void FileRepResync_ResetReMirrorAllowed(void); - -extern int64 FileRepResync_GetBlocksSynchronized(void); - -extern int64 FileRepResync_GetTotalBlocksToSynchronize(void); - -extern void FileRepResync_SetTotalBlocksToSynchronize(int64 totalBlocksToSynchronize); - -extern void FileRepResync_AddToTotalBlocksToSynchronize(int64 moreBlocksToSynchronize); - -extern struct timeval FileRepResync_GetEstimateResyncCompletionTime(void); - -extern void FileRepResyncManager_ResyncFlatFiles(void); - -extern void FileRepResync_DecFsobjCount(void); - -extern int FileRepResync_GetCurFsobjCount(void); - -extern int FileRepResync_GetTotalFsobjCount(void); - -#endif /* CDBFILEREPRESYNCMANAGER_H */ diff --git a/src/include/cdb/cdbfilerepresyncworker.h b/src/include/cdb/cdbfilerepresyncworker.h deleted file mode 100644 index 134c7703c5..0000000000 --- a/src/include/cdb/cdbfilerepresyncworker.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * cdbfilerepresyncworker.h - * - * Copyright 2009-2010, Greenplum Inc. All rights reserved. - * - */ - -#ifndef CDBFILEREPRESYNCWORKER_H -#define CDBFILEREPRESYNCWORKER_H - -#include "c.h" -#include "storage/relfilenode.h" -#include "access/xlogdefs.h" -#include "storage/fd.h" -#include "storage/dbdirnode.h" - -extern void FileRepPrimary_StartResyncWorker(void); - -extern bool FileRepResyncWorker_IsResyncRequest(void); - -#endif /* CDBFILEREPRESYNCWORKER_H */ -- GitLab