pgbackrest.git / summary / log / commit / refs

commit    464f3020a9c4de2f82c5bfaabffaacfb6d0cfd7b
Author:   David Steele <david@pgbackrest.org>
Date:     Fri Jun 12 03:11:49 2026 +0000

    Move ignoreMissing out of the storage read drivers.
    
    Previously each read driver decided whether a missing file was an error, which duplicated the ignoreMissing logic across the Posix, SFTP, remote, S3, Azure, and GCS drivers. Now driver open() simply reports whether the file exists and StorageRead throws FileMissingError when missing files are not ignored.
    
    Since the client now makes this decision, ignoreMissing no longer needs to be passed through the remote protocol and a missing file is reported locally rather than as an error raised from the remote.


src/storage/azure/read.c | 17 +++-------------- src/storage/gcs/read.c | 17 +++-------------- src/storage/posix/read.c | 12 +++--------- src/storage/read.c | 11 +++++++++-- src/storage/read.intern.h | 2 +- src/storage/remote/protocol.c | 5 ++--- src/storage/remote/read.c | 4 +--- src/storage/s3/read.c | 17 +++-------------- src/storage/sftp/read.c | 11 +++-------- test/src/common/harnessStorageHelper.c | 5 ++--- test/src/module/storage/remoteTest.c | 2 +- test/src/module/storage/s3Test.c | 20 ++++++++++++++++++++ test/src/module/storage/sftpTest.c | 2 +- 13 files changed, 52 insertions(+), 73 deletions(-) diff --git a/src/storage/azure/read.c b/src/storage/azure/read.c index a343cfef2..1bcf10d09 100644 --- a/src/storage/azure/read.c +++ b/src/storage/azure/read.c @@ -35,39 +35,28 @@ struct StorageReadAzure Open the file ***********************************************************************************************************************************/ static bool -storageReadAzureOpen(THIS_VOID, const bool ignoreMissing) +storageReadAzureOpen(THIS_VOID) { THIS(StorageReadAzure); FUNCTION_LOG_BEGIN(logLevelTrace); FUNCTION_LOG_PARAM(STORAGE_READ_AZURE, this); - FUNCTION_LOG_PARAM(BOOL, ignoreMissing); FUNCTION_LOG_END(); ASSERT(this != NULL); ASSERT(this->httpResponse == NULL); - bool result = false; - + // Request the file MEM_CONTEXT_OBJ_BEGIN(this) { this->httpResponse = storageAzureRequestP( this->storage, HTTP_VERB_GET_STR, .path = this->name, .query = this->versionId != NULL ? httpQueryPut(httpQueryNewP(), AZURE_QUERY_VERSION_ID_STR, this->versionId) : NULL, .header = httpHeaderPutRange(httpHeaderNew(NULL), this->offset, this->limit), .allowMissing = true, .contentIo = true); - - // If file exists - if (httpResponseCodeOk(this->httpResponse)) - { - result = true; - } - // Else error unless ignore missing - else if (!ignoreMissing) - THROW_FMT(FileMissingError, STORAGE_ERROR_READ_MISSING, strZ(this->name)); } MEM_CONTEXT_OBJ_END(); - FUNCTION_LOG_RETURN(BOOL, result); + FUNCTION_LOG_RETURN(BOOL, httpResponseCodeOk(this->httpResponse)); } /*********************************************************************************************************************************** diff --git a/src/storage/gcs/read.c b/src/storage/gcs/read.c index 0874b35af..0e9ae27b0 100644 --- a/src/storage/gcs/read.c +++ b/src/storage/gcs/read.c @@ -36,20 +36,18 @@ struct StorageReadGcs Open the file ***********************************************************************************************************************************/ static bool -storageReadGcsOpen(THIS_VOID, const bool ignoreMissing) +storageReadGcsOpen(THIS_VOID) { THIS(StorageReadGcs); FUNCTION_LOG_BEGIN(logLevelTrace); FUNCTION_LOG_PARAM(STORAGE_READ_GCS, this); - FUNCTION_LOG_PARAM(BOOL, ignoreMissing); FUNCTION_LOG_END(); ASSERT(this != NULL); ASSERT(this->httpResponse == NULL); - bool result = false; - + // Request the file MEM_CONTEXT_OBJ_BEGIN(this) { HttpQuery *const query = httpQueryAdd(httpQueryNewP(), GCS_QUERY_ALT_STR, GCS_QUERY_MEDIA_STR); @@ -61,19 +59,10 @@ storageReadGcsOpen(THIS_VOID, const bool ignoreMissing) this->storage, HTTP_VERB_GET_STR, .object = this->name, .header = httpHeaderPutRange(httpHeaderNew(NULL), this->offset, this->limit), .allowMissing = true, .contentIo = true, .query = query); - - // If file exists - if (httpResponseCodeOk(this->httpResponse)) - { - result = true; - } - // Else error unless ignore missing - else if (!ignoreMissing) - THROW_FMT(FileMissingError, STORAGE_ERROR_READ_MISSING, strZ(this->name)); } MEM_CONTEXT_OBJ_END(); - FUNCTION_LOG_RETURN(BOOL, result); + FUNCTION_LOG_RETURN(BOOL, httpResponseCodeOk(this->httpResponse)); } /*********************************************************************************************************************************** diff --git a/src/storage/posix/read.c b/src/storage/posix/read.c index 8413d7063..c55dc3796 100644 --- a/src/storage/posix/read.c +++ b/src/storage/posix/read.c @@ -54,13 +54,12 @@ storageReadPosixFreeResource(THIS_VOID) Open the file ***********************************************************************************************************************************/ static bool -storageReadPosixOpen(THIS_VOID, const bool ignoreMissing) +storageReadPosixOpen(THIS_VOID) { THIS(StorageReadPosix); FUNCTION_LOG_BEGIN(logLevelTrace); FUNCTION_LOG_PARAM(STORAGE_READ_POSIX, this); - FUNCTION_LOG_PARAM(BOOL, ignoreMissing); FUNCTION_LOG_END(); ASSERT(this != NULL); @@ -69,15 +68,10 @@ storageReadPosixOpen(THIS_VOID, const bool ignoreMissing) // Open the file this->fd = open(strZ(this->name), O_RDONLY, 0); - // Handle errors + // Handle errors except missing, which is reported to the caller via the result if (this->fd == -1) { - if (errno == ENOENT) // {vm_covered} - { - if (!ignoreMissing) - THROW_FMT(FileMissingError, STORAGE_ERROR_READ_MISSING, strZ(this->name)); - } - else + if (errno != ENOENT) // {vm_covered} THROW_SYS_ERROR_FMT(FileOpenError, STORAGE_ERROR_READ_OPEN, strZ(this->name)); // {vm_covered} } // Else success diff --git a/src/storage/read.c b/src/storage/read.c index 724bb0b89..0653bf777 100644 --- a/src/storage/read.c +++ b/src/storage/read.c @@ -48,7 +48,11 @@ storageReadOpen(THIS_VOID) // Open if not versioned or if versionId is not null if (!this->pub.version || this->pub.versionId != NULL) - result = storageReadDriverInterface(this->driver)->open(this->driver, this->pub.ignoreMissing); + result = storageReadDriverInterface(this->driver)->open(this->driver); + + // Error when the file is missing and missing files are not ignored + if (!result && !this->pub.ignoreMissing) + THROW_FMT(FileMissingError, STORAGE_ERROR_READ_MISSING, strZ(storageReadName(this))); FUNCTION_LOG_RETURN(BOOL, result); } @@ -114,7 +118,10 @@ storageRead(THIS_VOID, Buffer *const buffer, const bool block) .offset = this->pub.offset + this->bytesRead, .limit = this->pub.limit != NULL ? varNewUInt64(varUInt64(this->pub.limit) - this->bytesRead) : NULL, .versionId = this->pub.versionId); - storageReadDriverInterface(this->driver)->open(this->driver, false); + + // Error when the file is missing since it must have existed when the read began + if (!storageReadDriverInterface(this->driver)->open(this->driver)) + THROW_FMT(FileMissingError, STORAGE_ERROR_READ_MISSING, strZ(storageReadName(this))); } MEM_CONTEXT_OBJ_END(); } diff --git a/src/storage/read.intern.h b/src/storage/read.intern.h index b5c558c86..7976a6fbe 100644 --- a/src/storage/read.intern.h +++ b/src/storage/read.intern.h @@ -13,7 +13,7 @@ Interface typedef struct StorageReadInterface { void (*filterGroup)(void *driver, IoFilterGroup *filterGroup); // Set filter group (optional) - bool (*open)(void *driver, bool ignoreMissing); // Open read + bool (*open)(void *driver); // Open read size_t (*read)(void *driver, Buffer *buffer, bool block); // Read bytes bool (*eof)(void *driver); // Is read eof? int (*fd)(const void *driver); // Read file descriptor (optional) diff --git a/src/storage/remote/protocol.c b/src/storage/remote/protocol.c index 70fa41b9c..9b2e16d3e 100644 --- a/src/storage/remote/protocol.c +++ b/src/storage/remote/protocol.c @@ -425,15 +425,14 @@ storageRemoteReadOpenProtocol(PackRead *const param) MEM_CONTEXT_TEMP_BEGIN() { const String *file = pckReadStrP(param); - const bool ignoreMissing = pckReadBoolP(param); const uint64_t offset = pckReadU64P(param); const Variant *const limit = pckReadNullP(param) ? NULL : VARUINT64(pckReadU64P(param)); const String *const versionId = pckReadStrP(param); const Pack *const filter = pckReadPackP(param); - // Create the read object + // Create the read object ignoring missing since the client decides whether a missing file is an error StorageRead *const fileRead = storageReadNew( - storageRemoteProtocolLocal.storage, file, ignoreMissing, false, offset, limit, versionId != NULL, versionId); + storageRemoteProtocolLocal.storage, file, true, false, offset, limit, versionId != NULL, versionId); // Set filter group based on passed filters storageRemoteFilterGroup(ioReadFilterGroup(storageReadIo(fileRead)), filter); diff --git a/src/storage/remote/read.c b/src/storage/remote/read.c index ff0d756f1..3dc0dfaf1 100644 --- a/src/storage/remote/read.c +++ b/src/storage/remote/read.c @@ -194,13 +194,12 @@ storageReadRemoteFilterGroup(THIS_VOID, IoFilterGroup *const filterGroup) Open the file ***********************************************************************************************************************************/ static bool -storageReadRemoteOpen(THIS_VOID, const bool ignoreMissing) +storageReadRemoteOpen(THIS_VOID) { THIS(StorageReadRemote); FUNCTION_LOG_BEGIN(logLevelTrace); FUNCTION_LOG_PARAM(STORAGE_READ_REMOTE, this); - FUNCTION_LOG_PARAM(BOOL, ignoreMissing); FUNCTION_LOG_END(); ASSERT(this != NULL); @@ -216,7 +215,6 @@ storageReadRemoteOpen(THIS_VOID, const bool ignoreMissing) PackWrite *const param = protocolPackNew(); pckWriteStrP(param, this->name); - pckWriteBoolP(param, ignoreMissing); pckWriteU64P(param, this->offset); if (this->limit == NULL) diff --git a/src/storage/s3/read.c b/src/storage/s3/read.c index 851c09e94..afa0fc358 100644 --- a/src/storage/s3/read.c +++ b/src/storage/s3/read.c @@ -35,20 +35,18 @@ struct StorageReadS3 Open the file ***********************************************************************************************************************************/ static bool -storageReadS3Open(THIS_VOID, const bool ignoreMissing) +storageReadS3Open(THIS_VOID) { THIS(StorageReadS3); FUNCTION_LOG_BEGIN(logLevelTrace); FUNCTION_LOG_PARAM(STORAGE_READ_S3, this); - FUNCTION_LOG_PARAM(BOOL, ignoreMissing); FUNCTION_LOG_END(); ASSERT(this != NULL); ASSERT(this->httpResponse == NULL); - bool result = false; - + // Request the file MEM_CONTEXT_OBJ_BEGIN(this) { this->httpResponse = storageS3RequestP( @@ -56,19 +54,10 @@ storageReadS3Open(THIS_VOID, const bool ignoreMissing) .header = httpHeaderPutRange(httpHeaderNew(NULL), this->offset, this->limit), .query = this->versionId != NULL ? httpQueryPut(httpQueryNewP(), STRDEF("versionId"), this->versionId) : NULL, .allowMissing = true, .contentIo = true, .sseC = true); - - // If file exists - if (httpResponseCodeOk(this->httpResponse)) - { - result = true; - } - // Else error unless ignore missing - else if (!ignoreMissing) - THROW_FMT(FileMissingError, STORAGE_ERROR_READ_MISSING, strZ(this->name)); } MEM_CONTEXT_OBJ_END(); - FUNCTION_LOG_RETURN(BOOL, result); + FUNCTION_LOG_RETURN(BOOL, httpResponseCodeOk(this->httpResponse)); } /*********************************************************************************************************************************** diff --git a/src/storage/sftp/read.c b/src/storage/sftp/read.c index cbeab3ca4..6637be371 100644 --- a/src/storage/sftp/read.c +++ b/src/storage/sftp/read.c @@ -35,13 +35,12 @@ struct StorageReadSftp Open the file ***********************************************************************************************************************************/ static bool -storageReadSftpOpen(THIS_VOID, const bool ignoreMissing) +storageReadSftpOpen(THIS_VOID) { THIS(StorageReadSftp); FUNCTION_LOG_BEGIN(logLevelTrace); FUNCTION_LOG_PARAM(STORAGE_READ_SFTP, this); - FUNCTION_LOG_PARAM(BOOL, ignoreMissing); FUNCTION_LOG_END(); ASSERT(this != NULL); @@ -57,14 +56,10 @@ storageReadSftpOpen(THIS_VOID, const bool ignoreMissing) { const int rc = libssh2_session_last_errno(this->session); + // Handle errors except missing, which is reported to the caller via the result if (rc == LIBSSH2_ERROR_SFTP_PROTOCOL || rc == LIBSSH2_ERROR_EAGAIN) { - if (libssh2_sftp_last_error(this->sftpSession) == LIBSSH2_FX_NO_SUCH_FILE) - { - if (!ignoreMissing) - THROW_FMT(FileMissingError, STORAGE_ERROR_READ_MISSING, strZ(this->name)); - } - else + if (libssh2_sftp_last_error(this->sftpSession) != LIBSSH2_FX_NO_SUCH_FILE) { storageSftpEvalLibSsh2Error( rc, libssh2_sftp_last_error(this->sftpSession), &FileOpenError, diff --git a/test/src/common/harnessStorageHelper.c b/test/src/common/harnessStorageHelper.c index c9c55d491..3191f185c 100644 --- a/test/src/common/harnessStorageHelper.c +++ b/test/src/common/harnessStorageHelper.c @@ -120,18 +120,17 @@ hrnStorageTestVersionFind(const Storage *const storage, const String *const file Test storage read driver ***********************************************************************************************************************************/ static bool -hrnStorageReadTestOpen(THIS_VOID, const bool ignoreMissing) +hrnStorageReadTestOpen(THIS_VOID) { THIS(HrnStorageReadTest); FUNCTION_HARNESS_BEGIN(); FUNCTION_HARNESS_PARAM(HRN_STORAGE_READ_TEST, this); - FUNCTION_HARNESS_PARAM(BOOL, ignoreMissing); FUNCTION_HARNESS_END(); ASSERT(this != NULL); - FUNCTION_HARNESS_RETURN(BOOL, storageReadDriverInterface(this->driver)->open(this->driver, ignoreMissing)); + FUNCTION_HARNESS_RETURN(BOOL, storageReadDriverInterface(this->driver)->open(this->driver)); } static size_t diff --git a/test/src/module/storage/remoteTest.c b/test/src/module/storage/remoteTest.c index 3cfdfb282..50a118488 100644 --- a/test/src/module/storage/remoteTest.c +++ b/test/src/module/storage/remoteTest.c @@ -266,7 +266,7 @@ testRun(void) TEST_ERROR_FMT( strZ(strNewBuf(storageGetP(storageNewReadP(storagePgWrite, STRDEF("test.txt"))))), FileMissingError, - "raised from remote-0 shim protocol: " STORAGE_ERROR_READ_MISSING, TEST_PATH "/pg256/test.txt"); + STORAGE_ERROR_READ_MISSING, TEST_PATH "/pg256/test.txt"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("raw read file without compression"); diff --git a/test/src/module/storage/s3Test.c b/test/src/module/storage/s3Test.c index 6c1d94d94..ec8283289 100644 --- a/test/src/module/storage/s3Test.c +++ b/test/src/module/storage/s3Test.c @@ -687,6 +687,26 @@ testRun(void) TEST_RESULT_BOOL(errorCaught, true, "check error was caught"); + // ----------------------------------------------------------------------------------------------------------------- + TEST_TITLE("get file missing during retry"); + + testRequestP(service, s3, HTTP_VERB_GET, "/file.txt"); + testResponseP(service, .content = "12345678911234567892", .contentSize = VARUINT(30)); + + hrnServerScriptClose(service); + hrnServerScriptAccept(service); + + testRequestP(service, s3, HTTP_VERB_GET, "/file.txt", .range = "20-"); + testResponseP(service, .code = 404); + + ioBufferSizeSet(20); + + TEST_ERROR( + storageGetP(storageNewReadP(s3, STRDEF("file.txt"))), FileMissingError, + "unable to open missing file '/file.txt' for read"); + + ioBufferSizeSet(ioBufferSizeDefault); + // ----------------------------------------------------------------------------------------------------------------- TEST_TITLE("get zero-length file"); diff --git a/test/src/module/storage/sftpTest.c b/test/src/module/storage/sftpTest.c index 17d2077da..a3bce4df6 100644 --- a/test/src/module/storage/sftpTest.c +++ b/test/src/module/storage/sftpTest.c @@ -4633,7 +4633,7 @@ testRun(void) TEST_ERROR_FMT(ioReadOpen(storageReadIo(file)), FileOpenError, STORAGE_ERROR_READ_OPEN ": libssh2 error [-37]", strZ(fileName)); // Missing not sftp, not EAGAIN - TEST_RESULT_BOOL(ioReadOpen(storageReadIo(file)), false, "not sftp, not EAGAIN"); + TEST_ERROR_FMT(ioReadOpen(storageReadIo(file)), FileMissingError, STORAGE_ERROR_READ_MISSING, strZ(fileName)); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("read success"); [parent: 2b7825ad4695]