/* * SetWALFileNameForCleanup() * * Set the earliest WAL filename that we want to keep on the archive * and decide whether we need_cleanup */ static void SetWALFileNameForCleanup(void) { bool fnameOK = false; TrimExtension(restartWALFileName, additional_ext); /* * If restartWALFileName is a WAL file name then just use it directly. If * restartWALFileName is a .backup filename, make sure we use the prefix * of the filename, otherwise we will remove wrong files since * 000000010000000000000010.00000020.backup is after * 000000010000000000000010. */ if (IsXLogFileName(restartWALFileName)) { strcpy(exclusiveCleanupFileName, restartWALFileName); fnameOK = true; } else if (IsBackupHistoryFileName(restartWALFileName)) { int args; uint32 tli = 1, log = 0, seg = 0, offset = 0; args = sscanf(restartWALFileName, "%08X%08X%08X.%08X.backup", &tli, &log, &seg, &offset); if (args == 4) { fnameOK = true; /* * Use just the prefix of the filename, ignore everything after * first period */ XLogFileNameById(exclusiveCleanupFileName, tli, log, seg); } } if (!fnameOK) { fprintf(stderr, "%s: invalid filename input\n", progname); fprintf(stderr, "Try \"%s --help\" for more information.\n", progname); exit(2); } }
/* * CustomizableNextWALFileReady() * * Is the requested file ready yet? */ static bool CustomizableNextWALFileReady(void) { if (stat(WALFilePath, &stat_buf) == 0) { /* * If we've not seen any WAL segments, we don't know the WAL segment * size, which we need. If it looks like a WAL segment, determine size * of segments for the cluster. */ if (WalSegSz == -1 && IsXLogFileName(nextWALFileName)) { if (SetWALSegSize()) { /* * Successfully determined WAL segment size. Can compute * cleanup cutoff now. */ need_cleanup = SetWALFileNameForCleanup(); if (debug) { fprintf(stderr, _("WAL segment size: %d \n"), WalSegSz); fprintf(stderr, "Keep archive history: "); if (need_cleanup) fprintf(stderr, "%s and later\n", exclusiveCleanupFileName); else fprintf(stderr, "no cleanup required\n"); } } } /* * If it's a backup file, return immediately. If it's a regular file * return only if it's the right size already. */ if (IsBackupHistoryFileName(nextWALFileName)) { nextWALFileType = XLOG_BACKUP_LABEL; return true; } else if (WalSegSz > 0 && stat_buf.st_size == WalSegSz) { #ifdef WIN32 /* * Windows 'cp' sets the final file size before the copy is * complete, and not yet ready to be opened by pg_standby. So we * wait for sleeptime secs before attempting to restore. If that * is not enough, we will rely on the retry/holdoff mechanism. * GNUWin32's cp does not have this problem. */ pg_usleep(sleeptime * 1000000L); #endif nextWALFileType = XLOG_DATA; return true; } /* * If still too small, wait until it is the correct size */ if (WalSegSz > 0 && stat_buf.st_size > WalSegSz) { if (debug) { fprintf(stderr, "file size greater than expected\n"); fflush(stderr); } exit(3); } } return false; }