You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-07 00:35:37 +02:00
Add flag to dbGet() to require a standby.
This is needed from backup from standby functionality.
This commit is contained in:
@ -167,7 +167,7 @@ cmdCheck(void)
|
|||||||
MEM_CONTEXT_TEMP_BEGIN()
|
MEM_CONTEXT_TEMP_BEGIN()
|
||||||
{
|
{
|
||||||
// Get the primary/standby connections (standby is only required if backup from standby is enabled)
|
// Get the primary/standby connections (standby is only required if backup from standby is enabled)
|
||||||
DbGetResult dbGroup = dbGet(false, false);
|
DbGetResult dbGroup = dbGet(false, false, false);
|
||||||
|
|
||||||
if (dbGroup.standby == NULL && dbGroup.primary == NULL)
|
if (dbGroup.standby == NULL && dbGroup.primary == NULL)
|
||||||
THROW(ConfigError, "no database found\nHINT: check indexed pg-path/pg-host configurations");
|
THROW(ConfigError, "no database found\nHINT: check indexed pg-path/pg-host configurations");
|
||||||
|
@ -53,7 +53,7 @@ pgValidate(void)
|
|||||||
if (cfgOptionBool(cfgOptOnline))
|
if (cfgOptionBool(cfgOptOnline))
|
||||||
{
|
{
|
||||||
// Check the connections of the master (and standby, if any) and return the master database object.
|
// Check the connections of the master (and standby, if any) and return the master database object.
|
||||||
DbGetResult dbObject = dbGet(false, true);
|
DbGetResult dbObject = dbGet(false, true, false);
|
||||||
|
|
||||||
// Get the pgControl information from the pg*-path deemed to be the master
|
// Get the pgControl information from the pg*-path deemed to be the master
|
||||||
result = pgControlFromFile(storagePgId(dbObject.primaryId));
|
result = pgControlFromFile(storagePgId(dbObject.primaryId));
|
||||||
|
@ -50,13 +50,16 @@ dbGetId(unsigned int pgId)
|
|||||||
Get primary cluster or primary and standby cluster
|
Get primary cluster or primary and standby cluster
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
DbGetResult
|
DbGetResult
|
||||||
dbGet(bool primaryOnly, bool primaryRequired)
|
dbGet(bool primaryOnly, bool primaryRequired, bool standbyRequired)
|
||||||
{
|
{
|
||||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||||
FUNCTION_LOG_PARAM(BOOL, primaryOnly);
|
FUNCTION_LOG_PARAM(BOOL, primaryOnly);
|
||||||
FUNCTION_LOG_PARAM(BOOL, primaryRequired);
|
FUNCTION_LOG_PARAM(BOOL, primaryRequired);
|
||||||
|
FUNCTION_LOG_PARAM(BOOL, standbyRequired);
|
||||||
FUNCTION_LOG_END();
|
FUNCTION_LOG_END();
|
||||||
|
|
||||||
|
ASSERT(!(primaryOnly && standbyRequired));
|
||||||
|
|
||||||
DbGetResult result = {0};
|
DbGetResult result = {0};
|
||||||
|
|
||||||
MEM_CONTEXT_TEMP_BEGIN()
|
MEM_CONTEXT_TEMP_BEGIN()
|
||||||
@ -128,6 +131,10 @@ dbGet(bool primaryOnly, bool primaryRequired)
|
|||||||
if (result.primaryId == 0 && primaryRequired)
|
if (result.primaryId == 0 && primaryRequired)
|
||||||
THROW(DbConnectError, "unable to find primary cluster - cannot proceed");
|
THROW(DbConnectError, "unable to find primary cluster - cannot proceed");
|
||||||
|
|
||||||
|
// Error if no standby was found
|
||||||
|
if (result.standbyId == 0 && standbyRequired)
|
||||||
|
THROW(DbConnectError, "unable to find standby cluster - cannot proceed");
|
||||||
|
|
||||||
dbMove(result.primary, MEM_CONTEXT_OLD());
|
dbMove(result.primary, MEM_CONTEXT_OLD());
|
||||||
dbMove(result.standby, MEM_CONTEXT_OLD());
|
dbMove(result.standby, MEM_CONTEXT_OLD());
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ typedef struct DbGetResult
|
|||||||
Db *standby;
|
Db *standby;
|
||||||
} DbGetResult;
|
} DbGetResult;
|
||||||
|
|
||||||
DbGetResult dbGet(bool primaryOnly, bool primaryRequired);
|
DbGetResult dbGet(bool primaryOnly, bool primaryRequired, bool standbyRequired);
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Macros for function logging
|
Macros for function logging
|
||||||
|
@ -367,7 +367,7 @@ testRun(void)
|
|||||||
HRNPQ_MACRO_DONE()
|
HRNPQ_MACRO_DONE()
|
||||||
});
|
});
|
||||||
|
|
||||||
TEST_ASSIGN(db, dbGet(false, false), "get primary and standby");
|
TEST_ASSIGN(db, dbGet(false, false, false), "get primary and standby");
|
||||||
|
|
||||||
TEST_RESULT_VOID(checkDbConfig(PG_VERSION_92, db.primaryId, db.primary, false), "valid db config");
|
TEST_RESULT_VOID(checkDbConfig(PG_VERSION_92, db.primaryId, db.primary, false), "valid db config");
|
||||||
|
|
||||||
@ -429,7 +429,7 @@ testRun(void)
|
|||||||
HRNPQ_MACRO_DONE()
|
HRNPQ_MACRO_DONE()
|
||||||
});
|
});
|
||||||
|
|
||||||
TEST_ASSIGN(db, dbGet(true, true), "get primary");
|
TEST_ASSIGN(db, dbGet(true, true, false), "get primary");
|
||||||
TEST_ERROR_FMT(
|
TEST_ERROR_FMT(
|
||||||
checkDbConfig(PG_VERSION_92, db.primaryId, db.primary, false), FeatureNotSupportedError,
|
checkDbConfig(PG_VERSION_92, db.primaryId, db.primary, false), FeatureNotSupportedError,
|
||||||
"archive_mode=always not supported");
|
"archive_mode=always not supported");
|
||||||
|
@ -118,7 +118,7 @@ testRun(void)
|
|||||||
{.function = NULL}
|
{.function = NULL}
|
||||||
});
|
});
|
||||||
|
|
||||||
TEST_ERROR(dbGet(true, true), DbConnectError, "unable to find primary cluster - cannot proceed");
|
TEST_ERROR(dbGet(true, true, false), DbConnectError, "unable to find primary cluster - cannot proceed");
|
||||||
harnessLogResult(
|
harnessLogResult(
|
||||||
"P00 WARN: unable to check pg-1: [DbConnectError] unable to connect to 'dbname='postgres' port=5432': error");
|
"P00 WARN: unable to check pg-1: [DbConnectError] unable to connect to 'dbname='postgres' port=5432': error");
|
||||||
|
|
||||||
@ -135,7 +135,23 @@ testRun(void)
|
|||||||
HRNPQ_MACRO_DONE()
|
HRNPQ_MACRO_DONE()
|
||||||
});
|
});
|
||||||
|
|
||||||
TEST_ERROR(dbGet(true, true), DbConnectError, "unable to find primary cluster - cannot proceed");
|
TEST_ERROR(dbGet(true, true, false), DbConnectError, "unable to find primary cluster - cannot proceed");
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
|
TEST_TITLE("standby cluster required but not found");
|
||||||
|
|
||||||
|
harnessPqScriptSet((HarnessPq [])
|
||||||
|
{
|
||||||
|
HRNPQ_MACRO_OPEN(1, "dbname='postgres' port=5432"),
|
||||||
|
HRNPQ_MACRO_SET_SEARCH_PATH(1),
|
||||||
|
HRNPQ_MACRO_VALIDATE_QUERY(1, PG_VERSION_94, "/pgdata", NULL, NULL),
|
||||||
|
HRNPQ_MACRO_SET_APPLICATION_NAME(1),
|
||||||
|
HRNPQ_MACRO_IS_STANDBY_QUERY(1, false),
|
||||||
|
HRNPQ_MACRO_CLOSE(1),
|
||||||
|
HRNPQ_MACRO_DONE()
|
||||||
|
});
|
||||||
|
|
||||||
|
TEST_ERROR(dbGet(false, false, true), DbConnectError, "unable to find standby cluster - cannot proceed");
|
||||||
|
|
||||||
// Primary cluster found
|
// Primary cluster found
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -146,7 +162,7 @@ testRun(void)
|
|||||||
HRNPQ_MACRO_DONE()
|
HRNPQ_MACRO_DONE()
|
||||||
});
|
});
|
||||||
|
|
||||||
TEST_ASSIGN(result, dbGet(true, true), "get primary only");
|
TEST_ASSIGN(result, dbGet(true, true, false), "get primary only");
|
||||||
|
|
||||||
TEST_RESULT_INT(result.primaryId, 1, " check primary id");
|
TEST_RESULT_INT(result.primaryId, 1, " check primary id");
|
||||||
TEST_RESULT_BOOL(result.primary != NULL, true, " check primary");
|
TEST_RESULT_BOOL(result.primary != NULL, true, " check primary");
|
||||||
@ -178,7 +194,7 @@ testRun(void)
|
|||||||
HRNPQ_MACRO_DONE()
|
HRNPQ_MACRO_DONE()
|
||||||
});
|
});
|
||||||
|
|
||||||
TEST_ERROR(dbGet(true, true), DbConnectError, "more than one primary cluster found");
|
TEST_ERROR(dbGet(true, true, false), DbConnectError, "more than one primary cluster found");
|
||||||
|
|
||||||
// Two standbys found but no primary
|
// Two standbys found but no primary
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -193,7 +209,7 @@ testRun(void)
|
|||||||
HRNPQ_MACRO_DONE()
|
HRNPQ_MACRO_DONE()
|
||||||
});
|
});
|
||||||
|
|
||||||
TEST_ERROR(dbGet(false, true), DbConnectError, "unable to find primary cluster - cannot proceed");
|
TEST_ERROR(dbGet(false, true, false), DbConnectError, "unable to find primary cluster - cannot proceed");
|
||||||
|
|
||||||
// Two standbys and primary not required
|
// Two standbys and primary not required
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
@ -208,7 +224,7 @@ testRun(void)
|
|||||||
HRNPQ_MACRO_DONE()
|
HRNPQ_MACRO_DONE()
|
||||||
});
|
});
|
||||||
|
|
||||||
TEST_ASSIGN(result, dbGet(false, false), "get standbys");
|
TEST_ASSIGN(result, dbGet(false, false, false), "get standbys");
|
||||||
|
|
||||||
TEST_RESULT_INT(result.primaryId, 0, " check primary id");
|
TEST_RESULT_INT(result.primaryId, 0, " check primary id");
|
||||||
TEST_RESULT_BOOL(result.primary == NULL, true, " check primary");
|
TEST_RESULT_BOOL(result.primary == NULL, true, " check primary");
|
||||||
@ -253,7 +269,7 @@ testRun(void)
|
|||||||
HRNPQ_MACRO_DONE()
|
HRNPQ_MACRO_DONE()
|
||||||
});
|
});
|
||||||
|
|
||||||
TEST_ASSIGN(result, dbGet(false, true), "get primary and standy");
|
TEST_ASSIGN(result, dbGet(false, true, false), "get primary and standy");
|
||||||
harnessLogResultRegExp(
|
harnessLogResultRegExp(
|
||||||
"P00 WARN: unable to check pg-4: \\[DbConnectError\\] unable to connect to 'dbname='postgres' port=5433': error\n"
|
"P00 WARN: unable to check pg-4: \\[DbConnectError\\] unable to connect to 'dbname='postgres' port=5433': error\n"
|
||||||
"P00 WARN: unable to check pg-5: \\[DbConnectError\\] raised from remote-0 protocol on 'localhost':"
|
"P00 WARN: unable to check pg-5: \\[DbConnectError\\] raised from remote-0 protocol on 'localhost':"
|
||||||
|
Reference in New Issue
Block a user