Fix to avoid re-initializing MOT during switchover

This commit is contained in:
Vinoth 2020-07-25 11:32:55 +08:00
parent 33fb785204
commit f80b5433ff
8 changed files with 50 additions and 15 deletions

View File

@ -1407,7 +1407,6 @@ static void knl_t_mot_init(knl_t_mot_context* mot_cxt)
mot_cxt->bindPolicy = 2; // MPOL_BIND
mot_cxt->mbindFlags = 0;
mot_cxt->mot_startup = false;
}
void knl_thread_mot_init()

View File

@ -8243,9 +8243,7 @@ void StartupXLOG(void)
/*
* Recover MOT
*/
if (t_thrd.mot_cxt.mot_startup == true) {
MOTRecover();
}
MOTRecover();
/* initialize shared memory variables from the checkpoint record */
t_thrd.xact_cxt.ShmemVariableCache->nextXid = checkPoint.nextXid;
@ -9227,9 +9225,7 @@ void StartupXLOG(void)
/*
* Cleanup MOT recovery
*/
if (t_thrd.mot_cxt.mot_startup == true) {
MOTRecoveryDone();
}
MOTRecoveryDone();
}
void sendPMBeginHotStby()

View File

@ -519,9 +519,16 @@ bool RecoveryManager::RecoverFromCheckpoint()
bool RecoveryManager::RecoverDbStart()
{
MOT_LOG_INFO("Starting MOT recovery");
if (m_recoverFromCkptDone) {
return true;
}
if (!RecoverFromCheckpoint()) {
return false;
}
m_recoverFromCkptDone = true;
return true;
}

View File

@ -171,6 +171,7 @@ public:
RecoveryManager()
: m_logStats(nullptr),
m_initialized(false),
m_recoverFromCkptDone(false),
m_checkpointId(0),
m_lsn(0),
m_numWorkers(GetGlobalConfiguration().m_checkpointRecoveryWorkers),
@ -1010,6 +1011,8 @@ private:
bool m_initialized;
bool m_recoverFromCkptDone;
uint64_t m_checkpointId;
uint64_t m_lsn;

View File

@ -230,6 +230,11 @@ int MOTXlateRecoveryErr(int err)
void MOTRecover()
{
if (!MOTAdaptor::m_initialized) {
// This is the case when StartupXLOG is called during bootstrap.
return;
}
EnsureSafeThreadAccess();
if (!MOT::MOTEngine::GetInstance()->StartRecovery()) {
// we treat errors fatally.
@ -247,6 +252,11 @@ void MOTRecover()
void MOTRecoveryDone()
{
if (!MOTAdaptor::m_initialized) {
// This is the case when StartupXLOG is called during bootstrap.
return;
}
EnsureSafeThreadAccess();
if (!MOT::MOTEngine::GetInstance()->EndRecovery()) {
// we treat errors fatally.
@ -261,6 +271,10 @@ void MOTRecoveryDone()
*/
void MOTBeginRedoRecovery()
{
if (!MOTAdaptor::m_initialized) {
return;
}
EnsureSafeThreadAccess();
if (!MOT::MOTEngine::GetInstance()->CreateRecoverySessionContext()) {
// we treat errors fatally.
@ -276,6 +290,10 @@ void MOTBeginRedoRecovery()
void MOTEndRedoRecovery()
{
if (!MOTAdaptor::m_initialized) {
return;
}
EnsureSafeThreadAccess();
MOT::MOTEngine::GetInstance()->DestroyRecoverySessionContext();
knl_thread_mot_init(); // reset all thread locals
@ -287,9 +305,13 @@ void MOTEndRedoRecovery()
*/
void InitMOT()
{
JitExec::JitInitialize();
if (MOTAdaptor::m_initialized) {
// MOT is already initialized, probably it's primary switch-over to standby.
return;
}
InitMOTHandler();
t_thrd.mot_cxt.mot_startup = true;
JitExec::JitInitialize();
}
/**
@ -297,11 +319,20 @@ void InitMOT()
*/
void TermMOT()
{
MOTAdaptor::Fini();
if (!MOTAdaptor::m_initialized) {
return;
}
JitExec::JitDestroy();
MOTAdaptor::Destroy();
}
void MOTProcessRecoveredTransaction(uint64_t txid, bool isCommit)
{
if (!MOTAdaptor::m_initialized) {
return;
}
if (MOT::MOTEngine::GetInstance()->IsInProcessTx(txid)) {
elog(LOG, "MOTProcessRecoveredTransaction: %lu - %s", txid, isCommit ? "commit" : "abort");
MOT::TxnManager* mgr = GetSafeTxn();
@ -1898,7 +1929,6 @@ static int MOTIsForeignRelationUpdatable(Relation rel)
static void InitMOTHandler()
{
MOTAdaptor::Fini();
MOTAdaptor::Init();
MOT::GetGlobalConfiguration().m_enableIncrementalCheckpoint =
g_instance.attr.attr_storage.enableIncrementalCheckpoint;

View File

@ -702,7 +702,8 @@ static void WakeupWalWriter()
void MOTAdaptor::Init()
{
if (m_initialized) {
return;
// This is highly unexpected, and should especially be guarded in scenario of switch-over to standby.
elog(FATAL, "Double attempt to initialize MOT engine, it is already initialized");
}
MOT::GetGlobalConfiguration().SetTotalMemoryMb(g_instance.attr.attr_memory.max_process_memory / KILO_BYTE);
@ -852,7 +853,7 @@ void MOTAdaptor::InitDataNodeId()
MOT::GetGlobalConfiguration().SetPgNodes(1, 1);
}
void MOTAdaptor::Fini()
void MOTAdaptor::Destroy()
{
if (!m_initialized) {
return;

View File

@ -285,7 +285,7 @@ struct MOTFdwState_St {
class MOTAdaptor {
public:
static void Init();
static void Fini();
static void Destroy();
static void NotifyConfigChange();
static void InitDataNodeId();

View File

@ -2693,7 +2693,6 @@ typedef struct knl_t_mot_context {
// misc
uint8_t log_level;
bool init_codegen_once;
bool mot_startup;
uint16_t currentThreadId;
int currentNumaNodeId;