1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-30 05:39:12 +02:00

Remove async archive error file when not throwing an error.

This ensures that the error will not be thrown before the async process has a chance to retry.
This commit is contained in:
David Steele 2020-02-06 20:59:04 -08:00
parent 3721e57a0e
commit 2a06df93f3
2 changed files with 20 additions and 6 deletions

View File

@ -137,14 +137,22 @@ archiveAsyncStatus(ArchiveMode archiveMode, const String *walSegment, bool confe
result = true; result = true;
} }
else if (confessOnError) else
{ {
// Error status files must have content if (confessOnError)
if (strSize(content) == 0) {
THROW_FMT(AssertError, "status file '%s' has no content", strPtr(statusFile)); // Error status files must have content
if (strSize(content) == 0)
THROW_FMT(AssertError, "status file '%s' has no content", strPtr(statusFile));
// Throw error using the code passed in the file // Throw error using the code passed in the file
THROW_CODE(code, strPtr(message)); THROW_CODE(code, strPtr(message));
}
// Remove the error if it will not be thrown to give the async process a chance to retry. Otherwise, it could be a
// race between the foreground process retrying and the async process removing error files. Ignore missing since the
// async process may have already removed the file.
storageRemoveP(storageSpoolWrite(), strNewFmt("%s/%s", strPtr(spoolQueue), strPtr(errorFile)));
} }
} }
} }

View File

@ -95,8 +95,14 @@ testRun(void)
storageNewWriteP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.error", strPtr(segment))), storageNewWriteP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.error", strPtr(segment))),
BUFSTRDEF("25\nmessage")); BUFSTRDEF("25\nmessage"));
TEST_ERROR(archiveAsyncStatus(archiveModePush, segment, true), AssertError, "message"); TEST_ERROR(archiveAsyncStatus(archiveModePush, segment, true), AssertError, "message");
TEST_RESULT_BOOL(
storageExistsP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.error", strPtr(segment))), true,
"error file was not removed");
TEST_RESULT_BOOL(archiveAsyncStatus(archiveModePush, segment, false), false, "suppress error"); TEST_RESULT_BOOL(archiveAsyncStatus(archiveModePush, segment, false), false, "suppress error");
TEST_RESULT_BOOL(
storageExistsP(storageSpool(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.error", strPtr(segment))), false,
"error file was removed");
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
storagePutP( storagePutP(