From 133d5624c224463882dad6ae7a1eeb212da03680 Mon Sep 17 00:00:00 2001 From: shirley_zhengx Date: Wed, 26 Apr 2023 15:58:58 +0800 Subject: [PATCH] support dual cluster for shared storage --- src/bin/pg_ctl/backup.cpp | 15 +- .../ddes/adapter/ss_dms_bufmgr.cpp | 11 +- .../ddes/adapter/ss_dms_callback.cpp | 15 ++ .../ddes/adapter/ss_dms_recovery.cpp | 9 ++ .../ddes/adapter/ss_reform_common.cpp | 8 +- .../process/postmaster/postmaster.cpp | 26 ++-- .../storage/access/transam/xlog.cpp | 52 ++++++- src/gausskernel/storage/ipc/procarray.cpp | 10 ++ .../storage/replication/basebackup.cpp | 7 + src/gausskernel/storage/smgr/segstore.cpp | 4 +- .../xlog_share_storage/xlog_share_storage.cpp | 50 ++++++- src/include/ddes/dms/dms_api.h | 1 + src/include/ddes/dms/ss_common_attr.h | 48 +++++-- .../xlog_share_storage/xlog_share_storage.h | 2 + src/test/ss/build_ss_database_common.sh | 27 +++- src/test/ss/conf_start_dss_inst.sh | 49 +++++-- .../common_function.sh | 129 ++++++++++++++++++ .../standby_full_build_reconnect.sh | 39 ++++++ src/test/ss/ha_test.sh | 54 +++++++- 19 files changed, 515 insertions(+), 41 deletions(-) create mode 100644 src/test/ss/dual_cluster_single_shared_storage/common_function.sh create mode 100644 src/test/ss/dual_cluster_single_shared_storage/standby_full_build_reconnect.sh diff --git a/src/bin/pg_ctl/backup.cpp b/src/bin/pg_ctl/backup.cpp index 81b79cd47b..6563a8d960 100755 --- a/src/bin/pg_ctl/backup.cpp +++ b/src/bin/pg_ctl/backup.cpp @@ -1012,9 +1012,13 @@ static bool ReceiveAndUnpackTarFile(PGconn* conn, PGresult* res, int rownum) totaldone += r; continue; } - + + /* pg_control will be written into a specified postion of main stanby corresponding to */ if (instance_config.dss.enable_dss && strcmp(filename, "+data/pg_control") == 0) { pg_log(PG_WARNING, _("file size %d. \n"), r); + int main_standby_id = instance_config.dss.instance_id; + off_t seekpos = (off_t)BLCKSZ * main_standby_id; + fseek(file, seekpos, SEEK_SET); } if (forbid_write == false) { @@ -2733,8 +2737,13 @@ bool RenameTblspcDir(char *dataDir) if (strcmp(remotenodename, pgxcnodename) == 0) { return true; } - - rc = snprintf_s(tblspcParentPath, MAXPGPATH, MAXPGPATH - 1, "%s/%s", dataDir, "pg_tblspc"); + + if (instance_config.dss.enable_dss) { + char *dssdir = instance_config.dss.vgdata; + rc = snprintf_s(tblspcParentPath, MAXPGPATH, MAXPGPATH - 1, "%s/%s", dssdir, "pg_tblspc"); + } else { + rc = snprintf_s(tblspcParentPath, MAXPGPATH, MAXPGPATH - 1, "%s/%s", dataDir, "pg_tblspc"); + } securec_check_ss_c(rc, "\0", "\0"); tblspcParentDir = opendir(tblspcParentPath); if (!tblspcParentDir) { diff --git a/src/gausskernel/ddes/adapter/ss_dms_bufmgr.cpp b/src/gausskernel/ddes/adapter/ss_dms_bufmgr.cpp index 77710921eb..bc17008873 100644 --- a/src/gausskernel/ddes/adapter/ss_dms_bufmgr.cpp +++ b/src/gausskernel/ddes/adapter/ss_dms_bufmgr.cpp @@ -675,7 +675,16 @@ dms_session_e DMSGetProcType4RequestPage() { // proc type used in DMS request page if (AmDmsReformProcProcess() || AmPageRedoProcess() || AmStartupProcess()) { - return DMS_SESSION_RECOVER; + /* When xlog_file_path is not null and enable_dms is set on, main standby always is in recovery. + * When pmState is PM_HOT_STANDBY, this case indicates main standby support to read only. So here + * DMS_SESSION_RECOVER_HOT_STANDBY will be returned, it indicates that normal threads can access + * page in recovery state. + */ + if (SS_STANDBY_CLUSTER_MAIN_STANDBY && pmState == PM_HOT_STANDBY) { + return DMS_SESSION_RECOVER_HOT_STANDBY; + } else { + return DMS_SESSION_RECOVER; + } } else { return DMS_SESSION_NORMAL; } diff --git a/src/gausskernel/ddes/adapter/ss_dms_callback.cpp b/src/gausskernel/ddes/adapter/ss_dms_callback.cpp index d704adbd47..6b0469cb9f 100644 --- a/src/gausskernel/ddes/adapter/ss_dms_callback.cpp +++ b/src/gausskernel/ddes/adapter/ss_dms_callback.cpp @@ -1575,6 +1575,8 @@ static void CBReformStartNotify(void *db_handle, dms_role_t role, unsigned char pg_memory_barrier(); g_instance.dms_cxt.SSRecoveryInfo.failover_triggered = true; g_instance.dms_cxt.SSClusterState = NODESTATE_STANDBY_FAILOVER_PROMOTING; + /* Backends should exit in here, this step should be bring forward and not in CBFailoverPromote */ + pmState = PM_WAIT_BACKENDS; ereport(LOG, (errmodule(MOD_DMS), errmsg("[SS failover] failover trigger."))); } } @@ -1602,6 +1604,12 @@ static void CBReformStartNotify(void *db_handle, dms_role_t role, unsigned char SendPostmasterSignal(PMSIGNAL_DMS_REFORM); } + /* After reform done, standby of standby cluster need to set mode to STANDBY_MODE in dual cluster. */ + if (SS_REFORM_REFORMER && (g_instance.attr.attr_common.cluster_run_mode == RUN_MODE_STANDBY) && + (g_instance.attr.attr_storage.xlog_file_path != 0)) { + t_thrd.postmaster_cxt.HaShmData->current_mode = STANDBY_MODE; + } + while (true) { if (dms_reform_failed()) { ereport(WARNING, (errmodule(MOD_DMS), errmsg("[SS reform]reform failed during caneling backends"))); @@ -1624,6 +1632,13 @@ static int CBReformDoneNotify(void *db_handle) g_instance.attr.attr_storage.dms_attr.instance_id))); } } + + /* After reform done, primary of master cluster need to set mode to PRIMARY_MODE in dual cluster. */ + if (SS_REFORM_REFORMER && (g_instance.attr.attr_common.cluster_run_mode == RUN_MODE_PRIMARY) && + (g_instance.attr.attr_storage.xlog_file_path != 0)) { + t_thrd.postmaster_cxt.HaShmData->current_mode = PRIMARY_MODE; + } + /* SSClusterState and in_reform must be set atomically */ g_instance.dms_cxt.SSClusterState = NODESTATE_NORMAL; g_instance.dms_cxt.SSReformInfo.in_reform = false; diff --git a/src/gausskernel/ddes/adapter/ss_dms_recovery.cpp b/src/gausskernel/ddes/adapter/ss_dms_recovery.cpp index 3c64f1ce8e..86bbb53731 100644 --- a/src/gausskernel/ddes/adapter/ss_dms_recovery.cpp +++ b/src/gausskernel/ddes/adapter/ss_dms_recovery.cpp @@ -110,6 +110,15 @@ bool SSRecoveryNodes() break; } LWLockRelease(ControlFileLock); + + /* If main standby is set hot standby to on, when it reach consistency or recovery all xlogs in disk, + * recovery phase could be regarded successful in hot_standby thus set pmState = PM_HOT_STANDBY, which + * indicate database systerm is ready to accept read only connections. + */ + if (SS_STANDBY_CLUSTER_MAIN_STANDBY && pmState == PM_HOT_STANDBY) { + result = true; + break; + } pg_usleep(REFORM_WAIT_TIME); } return result; diff --git a/src/gausskernel/ddes/adapter/ss_reform_common.cpp b/src/gausskernel/ddes/adapter/ss_reform_common.cpp index b32e1c0304..0dd6a2d109 100644 --- a/src/gausskernel/ddes/adapter/ss_reform_common.cpp +++ b/src/gausskernel/ddes/adapter/ss_reform_common.cpp @@ -230,23 +230,23 @@ bool SSReadXlogInternal(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, X * record just writing into pg_xlog file when source is XLOG_FROM_STREAM and dms and dss are enabled. So we * need to reread xlog from dss to preReadBuf. */ - if (SS_STANDBY_CLUSTER_NORMAL_MAIN_STANDBY) { + if (SS_STANDBY_CLUSTER_MAIN_STANDBY) { volatile XLogCtlData *xlogctl = t_thrd.shemem_ptr_cxt.XLogCtl; if (XLByteInPreReadBuf(targetPagePtr, xlogreader->preReadStartPtr) && ((targetRecPtr < xlogFlushPtrForPerRead && t_thrd.xlog_cxt.readSource == XLOG_FROM_STREAM) || - (!xlogctl->IsRecoveryDone))) { + (!xlogctl->IsRecoveryDone) || (t_thrd.xlog_cxt.readSource != XLOG_FROM_STREAM))) { isReadFile = false; } } if ((XLByteInPreReadBuf(targetPagePtr, xlogreader->preReadStartPtr) && - !SS_STANDBY_CLUSTER_NORMAL_MAIN_STANDBY) || (!isReadFile)) { + !SS_STANDBY_CLUSTER_MAIN_STANDBY) || (!isReadFile)) { preReadOff = targetPagePtr % XLogPreReadSize; int err = memcpy_s(buf, XLOG_BLCKSZ, xlogreader->preReadBuf + preReadOff, XLOG_BLCKSZ); securec_check(err, "\0", "\0"); break; } else { - if (SS_STANDBY_CLUSTER_NORMAL_MAIN_STANDBY) { + if (SS_STANDBY_CLUSTER_MAIN_STANDBY) { xlogreader->xlogFlushPtrForPerRead = GetWalRcvWriteRecPtr(NULL); xlogFlushPtrForPerRead = xlogreader->xlogFlushPtrForPerRead; } diff --git a/src/gausskernel/process/postmaster/postmaster.cpp b/src/gausskernel/process/postmaster/postmaster.cpp index bb578682ee..4c38e5c7d3 100644 --- a/src/gausskernel/process/postmaster/postmaster.cpp +++ b/src/gausskernel/process/postmaster/postmaster.cpp @@ -3914,7 +3914,9 @@ static int ServerLoop(void) if (g_instance.pid_cxt.ReaperBackendPID == 0) g_instance.pid_cxt.ReaperBackendPID = initialize_util_thread(REAPER); - if ((pmState == PM_RUN || t_thrd.xlog_cxt.is_hadr_main_standby) && + if (((!ENABLE_DMS && (pmState == PM_RUN || t_thrd.xlog_cxt.is_hadr_main_standby)) || + (ENABLE_DMS && pmState == PM_RUN && t_thrd.postmaster_cxt.HaShmData->current_mode == PRIMARY_MODE && + !SS_PERFORMING_SWITCHOVER)) && g_instance.pid_cxt.sharedStorageXlogCopyThreadPID == 0 && !dummyStandbyMode && g_instance.attr.attr_storage.xlog_file_path != NULL) { g_instance.pid_cxt.sharedStorageXlogCopyThreadPID = initialize_util_thread(SHARE_STORAGE_XLOG_COPYER); @@ -6869,7 +6871,8 @@ static void reaper(SIGNAL_ARGS) } if (g_instance.pid_cxt.sharedStorageXlogCopyThreadPID == 0 && !dummyStandbyMode && - g_instance.attr.attr_storage.xlog_file_path != NULL) { + g_instance.attr.attr_storage.xlog_file_path != NULL && (!SS_PRIMARY_STANDBY_CLUSTER_STANDBY + && !SS_PRIMARY_DEMOTING)) { g_instance.pid_cxt.sharedStorageXlogCopyThreadPID = initialize_util_thread(SHARE_STORAGE_XLOG_COPYER); } @@ -7194,7 +7197,11 @@ static void reaper(SIGNAL_ARGS) * Any unexpected exit of the checkpointer (including FATAL * exit) is treated as a crash. */ - HandleChildCrash(pid, exitstatus, _("checkpointer process")); + if (pid == g_instance.pid_cxt.sharedStorageXlogCopyThreadPID) { + HandleChildCrash(pid, exitstatus, _("sharedStorageXlogCopy process")); + } else { + HandleChildCrash(pid, exitstatus, _("checkpointer process")); + } } continue; @@ -9964,7 +9971,7 @@ static void sigusr1_handler(SIGNAL_ARGS) * and walrecwrite. Other modes don't need when dms is enabled. */ if (CheckPostmasterSignal(PMSIGNAL_START_WALRECEIVER) && g_instance.pid_cxt.WalReceiverPID == 0 && (pmState == PM_STARTUP || pmState == PM_RECOVERY || pmState == PM_HOT_STANDBY || pmState == PM_WAIT_READONLY) && - g_instance.status == NoShutdown && (!ENABLE_DMS || SS_STANDBY_CLUSTER_NORMAL_MAIN_STANDBY)) { + g_instance.status == NoShutdown && (!ENABLE_DMS || SS_STANDBY_CLUSTER_MAIN_STANDBY)) { if (g_instance.pid_cxt.WalRcvWriterPID == 0) { g_instance.pid_cxt.WalRcvWriterPID = initialize_util_thread(WALRECWRITE); SetWalRcvWriterPID(g_instance.pid_cxt.WalRcvWriterPID); @@ -10181,7 +10188,6 @@ static void sigusr1_handler(SIGNAL_ARGS) if (g_instance.pid_cxt.PgJobSchdPID != 0) signal_child(g_instance.pid_cxt.PgJobSchdPID, SIGTERM); - /* * before init startup threads, need close WalWriter and WalWriterAuxiliary * because during StartupXLOG remove_xlogtemp_files() occurs process file concurrently @@ -10191,7 +10197,6 @@ static void sigusr1_handler(SIGNAL_ARGS) if (g_instance.pid_cxt.WalWriterAuxiliaryPID != 0) signal_child(g_instance.pid_cxt.WalWriterAuxiliaryPID, SIGTERM); - pmState = PM_WAIT_BACKENDS; if (ENABLE_THREAD_POOL) { g_threadPoolControler->EnableAdjustPool(); @@ -12494,6 +12499,11 @@ const char* wal_get_db_state_string(DbState db_state) static ServerMode get_cur_mode(void) { if (ENABLE_DMS) { + /* except for main standby in standby cluster, current mode of instance is determined by SS_OFFICIAL_PRIMARY*/ + if (g_instance.attr.attr_storage.xlog_file_path !=0 && SS_OFFICIAL_PRIMARY && + t_thrd.postmaster_cxt.HaShmData->current_mode == STANDBY_MODE) { + return STANDBY_MODE; + } return !SS_OFFICIAL_PRIMARY ? STANDBY_MODE : PRIMARY_MODE; } return t_thrd.postmaster_cxt.HaShmData->current_mode; @@ -14748,13 +14758,13 @@ void InitShmemForDmsCallBack() const char *GetSSServerMode(ServerMode mode) { if (g_instance.attr.attr_storage.xlog_file_path != 0) { - if (SS_OFFICIAL_PRIMARY && mode == PRIMARY_MODE) { + if (SS_OFFICIAL_PRIMARY && (mode == PRIMARY_MODE || mode == NORMAL_MODE)) { return "Primary"; } /* main standby in standby cluster */ if (SS_OFFICIAL_PRIMARY && mode == STANDBY_MODE) { - return "Standby"; + return "Main Standby"; } if (!SS_OFFICIAL_PRIMARY) { diff --git a/src/gausskernel/storage/access/transam/xlog.cpp b/src/gausskernel/storage/access/transam/xlog.cpp index b05dcfc7c2..c752821265 100755 --- a/src/gausskernel/storage/access/transam/xlog.cpp +++ b/src/gausskernel/storage/access/transam/xlog.cpp @@ -4206,6 +4206,23 @@ int XLogFileOpen(XLogSegNo segno) return fd; } +/* + * Copy one page starting with targetpageptr of EndOfLog from old priamry to new primary. + */ +void SSXLOGCopyFromOldPrimary(XLogReaderState *state, XLogRecPtr pageptr) +{ + ssize_t actualBytes = write(t_thrd.xlog_cxt.openLogFile, state->readBuf, XLOG_BLCKSZ); + if (actualBytes != XLOG_BLCKSZ) { + if (errno == 0) { + errno = ENOSPC; + } + uint32 shiftSize = 32; + ereport(PANIC, (errcode_for_file_access(), errmsg("could not write xlog at start:%X/%X, length %d: %m", + static_cast(pageptr >> shiftSize), + static_cast(pageptr), XLOG_BLCKSZ))); + } +} + /* * Open a logfile segment for reading (during recovery). * @@ -10547,9 +10564,15 @@ void StartupXLOG(void) (void)XLogFileInit(endLogSegNo, &use_existent, true); } uint32 redoReadOff = t_thrd.xlog_cxt.readOff; - - GetWritePermissionSharedStorage(); - CheckShareStorageCtlInfo(EndOfLog); + + /* only primary mode can call getwritepermissionsharedstorage wnen dorado hyperreplication + * and dms enabled. + */ + if(!SS_PRIMARY_STANDBY_CLUSTER_STANDBY) { + GetWritePermissionSharedStorage(); + CheckShareStorageCtlInfo(EndOfLog); + } + /* * Complain if we did not roll forward far enough to render the backup * dump consistent. Note: it is indeed okay to look at the local variable @@ -10799,6 +10822,29 @@ void StartupXLOG(void) /* Shut down readFile facility, free space. */ ShutdownReadFileFacility(); + if (SS_STANDBY_FAILOVER && SS_PRIMARY_CLUSTER_STANDBY) { + ereport(LOG, (errmodule(MOD_DMS), + errmsg("[SS failover] standby promoting: copy endofxlog pageptr from primary to standby"))); + XLogRecPtr EndOfLogPagePtr = EndOfLog - (EndOfLog % XLOG_BLCKSZ); + SSXLOGCopyFromOldPrimary(xlogreader, EndOfLogPagePtr); + + ereport(LOG, (errmodule(MOD_DMS), errmsg("[SS failover] standby promoting: copy xlog from local to dorado"))); + ShareStorageXLogCtl *sharestorageCtl = g_instance.xlog_cxt.shareStorageXLogCtl; + XLogRecPtr localFlush = InvalidXLogRecPtr; + localFlush = EndOfLog; + XLogRecPtr maxPosCanWrite = GetMaxPosCanOverWrite(); + uint32 shiftSize = 32; + ereport(LOG, + (errmsg("start to copy xlog from local to shared storage, localFlush: %X/%X, maxPosCanWrite: %X/%X.", + static_cast(localFlush >> shiftSize), static_cast(localFlush), + static_cast(maxPosCanWrite >> shiftSize), static_cast(maxPosCanWrite)))); + + if (XLByteLT(sharestorageCtl->insertHead, maxPosCanWrite)) { + XLogRecPtr expectPos = XLByteLT(localFlush, maxPosCanWrite) ? localFlush : maxPosCanWrite; + SSDoXLogCopyFromLocal(expectPos); + } + } + /* Shut down the xlog reader facility. */ XLogReaderFree(xlogreader); xlogreader = NULL; diff --git a/src/gausskernel/storage/ipc/procarray.cpp b/src/gausskernel/storage/ipc/procarray.cpp index ac72ac86d3..35f7d632a9 100755 --- a/src/gausskernel/storage/ipc/procarray.cpp +++ b/src/gausskernel/storage/ipc/procarray.cpp @@ -2301,6 +2301,16 @@ GROUP_GET_SNAPSHOT: TransactionIdPrecedes(replication_slot_xmin, u_sess->utils_cxt.RecentGlobalXmin)) { u_sess->utils_cxt.RecentGlobalXmin = replication_slot_xmin; } + + /* Check whether there's a standby requiring an older xmin when dms is enabled. */ + if (ENABLE_DMS && SS_STANDBY_CLUSTER_NORMAL_MAIN_STANDBY && SSGetOldestXminFromAllStandby()) { + TransactionId ss_oldest_xmin = pg_atomic_read_u64(&g_instance.dms_cxt.xminAck); + if (TransactionIdIsValid(ss_oldest_xmin) && TransactionIdIsNormal(ss_oldest_xmin) && + TransactionIdPrecedes(ss_oldest_xmin, u_sess->utils_cxt.RecentGlobalXmin)) { + u_sess->utils_cxt.RecentGlobalXmin = ss_oldest_xmin; + } + } + /* Non-catalog tables can be vacuumed if older than this xid */ u_sess->utils_cxt.RecentGlobalDataXmin = u_sess->utils_cxt.RecentGlobalXmin; diff --git a/src/gausskernel/storage/replication/basebackup.cpp b/src/gausskernel/storage/replication/basebackup.cpp index 4314a91a8e..5d9f334b43 100755 --- a/src/gausskernel/storage/replication/basebackup.cpp +++ b/src/gausskernel/storage/replication/basebackup.cpp @@ -2186,9 +2186,16 @@ static bool sendFile(char *readfilename, char *tarfilename, struct stat *statbuf /* send the pkg header containing msg like file size */ _tarWriteHeader(tarfilename, NULL, statbuf); + /* Because pg_control file is shared in all instance when dss is enabled. Here pg_control of primary id + * need to send to main standby in standby cluster, so we must seek a postion accoring to primary id. + * Then content of primary id will be read. + */ if (ENABLE_DSS && strcmp(tarfilename, XLOG_CONTROL_FILE) == 0) { int read_size = BUFFERALIGN(sizeof(ControlFileData)); statbuf->st_size = read_size; + int primary_id = SSGetPrimaryInstId(); + off_t seekpos = (off_t)BLCKSZ * primary_id; + fseek(fp, seekpos, SEEK_SET); } while ((cnt = fread(t_thrd.basebackup_cxt.buf_block, 1, Min(TAR_SEND_SIZE, statbuf->st_size - len), fp)) > 0) { diff --git a/src/gausskernel/storage/smgr/segstore.cpp b/src/gausskernel/storage/smgr/segstore.cpp index 6309edc25c..76c606bc56 100755 --- a/src/gausskernel/storage/smgr/segstore.cpp +++ b/src/gausskernel/storage/smgr/segstore.cpp @@ -369,10 +369,10 @@ SegPageLocation seg_logic_to_physic_mapping(SMgrRelation reln, SegmentHead *seg_ BlockNumber blocknum; /* Recovery thread should use physical location to read data directly. */ - if (ENABLE_DMS && t_thrd.postmaster_cxt.HaShmData->current_mode == STANDBY_MODE && + if (ENABLE_DMS && t_thrd.postmaster_cxt.HaShmData->current_mode == STANDBY_MODE && g_instance.attr.attr_common.cluster_run_mode == RUN_MODE_STANDBY && g_instance.attr.attr_storage.xlog_file_path != 0) { - ereport(DEBUG1, (errmsg("can segment address translation when role is SS_STANDBY_CLUSTER_NORMAL_MAIN_STANDBY"))); + ereport(DEBUG1, (errmsg("can segment address translation when role is SS_STANDBY_CLUSTER_MAIN_STANDBY"))); } else { if (RecoveryInProgress() && !CurrentThreadIsWorker() && !SS_IN_FLUSHCOPY) { ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("recovery is in progress"), diff --git a/src/gausskernel/storage/xlog_share_storage/xlog_share_storage.cpp b/src/gausskernel/storage/xlog_share_storage/xlog_share_storage.cpp index 17750e84dc..d8969dc4a5 100644 --- a/src/gausskernel/storage/xlog_share_storage/xlog_share_storage.cpp +++ b/src/gausskernel/storage/xlog_share_storage/xlog_share_storage.cpp @@ -139,7 +139,16 @@ void LocalXLogRead(char *buf, XLogRecPtr startptr, Size count) } XLByteToSeg(recptr, t_thrd.sharestoragexlogcopyer_cxt.readSegNo); - XLogFilePath(path, MAXPGPATH, t_thrd.xlog_cxt.ThisTimeLineID, t_thrd.sharestoragexlogcopyer_cxt.readSegNo); + if (SS_STANDBY_FAILOVER && SS_PRIMARY_CLUSTER_STANDBY) { + int nRet; + nRet = snprintf_s(path, MAXPGPATH, MAXPGPATH - 1, "%s/%08X%08X%08X", + g_instance.dms_cxt.SSRecoveryInfo.recovery_xlogDir, t_thrd.xlog_cxt.ThisTimeLineID, + (uint32)((t_thrd.sharestoragexlogcopyer_cxt.readSegNo) / XLogSegmentsPerXLogId), + (uint32)((t_thrd.sharestoragexlogcopyer_cxt.readSegNo) % XLogSegmentsPerXLogId)); + securec_check_ss(nRet, "\0", "\0"); + } else { + XLogFilePath(path, MAXPGPATH, t_thrd.xlog_cxt.ThisTimeLineID, t_thrd.sharestoragexlogcopyer_cxt.readSegNo); + } t_thrd.sharestoragexlogcopyer_cxt.readFile = BasicOpenFile(path, O_RDONLY | PG_BINARY, 0); if (t_thrd.sharestoragexlogcopyer_cxt.readFile < 0) { @@ -680,6 +689,45 @@ void WakeUpXLogCopyerBackend() } } +void SSDoXLogCopyFromLocal(XLogRecPtr copyEnd) +{ + uint32 shiftSize = 32; + ShareStorageXLogCtl *ctlInfo = g_instance.xlog_cxt.shareStorageXLogCtl; + uint64 xlogFileSize = static_cast(g_instance.attr.attr_storage.xlog_file_size); + + GetWritePermissionSharedStorage(); + ReadShareStorageCtlInfo(ctlInfo); + if (XLByteLE(copyEnd, ctlInfo->insertHead)){ + return; + } + + if (t_thrd.sharestoragexlogcopyer_cxt.originBuf == NULL) { + t_thrd.sharestoragexlogcopyer_cxt.originBuf = + (char *)palloc(ShareStorageBufSize + g_instance.xlog_cxt.shareStorageopCtl.blkSize); + t_thrd.sharestoragexlogcopyer_cxt.buf = (char *)TYPEALIGN(g_instance.xlog_cxt.shareStorageopCtl.blkSize, + t_thrd.sharestoragexlogcopyer_cxt.originBuf); + } + + ereport(LOG, + (errmsg("start to copy xlog from local to shared storage, start: %X/%X, end: %X/%X.", + static_cast(ctlInfo->insertHead >> shiftSize), static_cast(ctlInfo->insertHead), + static_cast(copyEnd >> shiftSize), static_cast(copyEnd)))); + + DoXlogCopy(copyEnd); + if (t_thrd.sharestoragexlogcopyer_cxt.readFile >= 0) { + (void)close(t_thrd.sharestoragexlogcopyer_cxt.readFile); + } + if (t_thrd.sharestoragexlogcopyer_cxt.originBuf != NULL) { + pfree(t_thrd.sharestoragexlogcopyer_cxt.originBuf); + t_thrd.sharestoragexlogcopyer_cxt.originBuf = NULL; + t_thrd.sharestoragexlogcopyer_cxt.buf = NULL; + } + + ereport(LOG, + (errmsg("successfully overwrite xlog from local to shared storage, shared storage's head is %X/%X", + static_cast(ctlInfo->insertHead >> shiftSize), static_cast(ctlInfo->insertHead)))); +} + static void DoXLogCopyFromLocal(XLogRecPtr copyStart, XLogRecPtr copyEnd) { uint32 shiftSize = 32; diff --git a/src/include/ddes/dms/dms_api.h b/src/include/ddes/dms/dms_api.h index 5fc372ca8f..969f175a57 100644 --- a/src/include/ddes/dms/dms_api.h +++ b/src/include/ddes/dms/dms_api.h @@ -160,6 +160,7 @@ typedef enum en_dms_session { DMS_SESSION_NORMAL = 0, // can not access DRC when DRC is inaccessible DMS_SESSION_REFORM = 1, // can access DRC when DRC is inaccessible DMS_SESSION_RECOVER = 2, // can access DRC when DRC is inaccessible, buf if no owner, should set in recovery + DMS_SESSION_RECOVER_HOT_STANDBY = 3, // can access DRC when pmstate = PM_HOT_STANDBY } dms_session_e; #define DMS_RESID_SIZE 32 diff --git a/src/include/ddes/dms/ss_common_attr.h b/src/include/ddes/dms/ss_common_attr.h index 206deef701..e256ec6abb 100644 --- a/src/include/ddes/dms/ss_common_attr.h +++ b/src/include/ddes/dms/ss_common_attr.h @@ -91,25 +91,57 @@ /* Mode in dorado hyperreplication and dms enabled as follow */ -/* main standby which is runing normally, not in intermediate state */ +/* main standby in standby cluster */ +#define SS_STANDBY_CLUSTER_MAIN_STANDBY \ + (ENABLE_DMS && (t_thrd.xlog_cxt.server_mode == STANDBY_MODE || \ + t_thrd.postmaster_cxt.HaShmData->current_mode == STANDBY_MODE) && \ + (g_instance.attr.attr_common.cluster_run_mode == RUN_MODE_STANDBY) && \ + (g_instance.attr.attr_storage.xlog_file_path != 0)) + +/* standby mode in primary or standby cluster */ +#define SS_PRIMARY_STANDBY_CLUSTER_STANDBY \ + (ENABLE_DMS && (t_thrd.xlog_cxt.server_mode == NORMAL_MODE || \ + t_thrd.postmaster_cxt.HaShmData->current_mode == NORMAL_MODE) && \ + (g_instance.attr.attr_storage.xlog_file_path != 0)) + +/* standby mode in primary cluster */ +#define SS_PRIMARY_CLUSTER_STANDBY \ + (ENABLE_DMS && (t_thrd.xlog_cxt.server_mode == NORMAL_MODE || \ + t_thrd.postmaster_cxt.HaShmData->current_mode == NORMAL_MODE) && \ + (g_instance.attr.attr_common.cluster_run_mode == RUN_MODE_PRIMARY) && \ + (g_instance.attr.attr_storage.xlog_file_path != 0)) + +/* arbitrary mode when dorado hyperreplication and dms enabled */ +#define SS_PRIMARY_STANDBY_CLUSTER_NORMAL \ + (ENABLE_DMS && ((g_instance.attr.attr_common.cluster_run_mode == RUN_MODE_PRIMARY) || \ + (g_instance.attr.attr_common.cluster_run_mode == RUN_MODE_STANDBY)) && \ + (g_instance.attr.attr_storage.xlog_file_path != 0)) + +/* primary mode in primary cluster, after reform done and primary id has been determined */ #define SS_PRIMARY_CLUSTER_NORMAL_PRIMARY \ - (ENABLE_DMS && (t_thrd.xlog_cxt.server_mode == PRIMARY_MODE) && \ + (SS_NORMAL_PRIMARY && (t_thrd.xlog_cxt.server_mode == PRIMARY_MODE || \ + t_thrd.postmaster_cxt.HaShmData->current_mode == PRIMARY_MODE) && \ (g_instance.attr.attr_common.cluster_run_mode == RUN_MODE_PRIMARY) && \ (g_instance.attr.attr_storage.xlog_file_path != 0)) -/* main standby which is runing normally, not in intermediate state */ +/* main standby in standby cluster, after reform done and primary id has been determined */ #define SS_STANDBY_CLUSTER_NORMAL_MAIN_STANDBY \ - (ENABLE_DMS && (t_thrd.xlog_cxt.server_mode == STANDBY_MODE || \ + (SS_NORMAL_PRIMARY && (t_thrd.xlog_cxt.server_mode == STANDBY_MODE || \ t_thrd.postmaster_cxt.HaShmData->current_mode == STANDBY_MODE) && \ (g_instance.attr.attr_common.cluster_run_mode == RUN_MODE_STANDBY) && \ (g_instance.attr.attr_storage.xlog_file_path != 0)) -/* main standby which is runing normally, not in intermediate state */ -#define SS_PRIMARY_STANDBY_CLUSTER_NORMAL \ - (ENABLE_DMS && ((g_instance.attr.attr_common.cluster_run_mode == RUN_MODE_PRIMARY) || \ - (g_instance.attr.attr_common.cluster_run_mode == RUN_MODE_STANDBY)) && \ +/* standby mode in standby cluster, after reform done and primary id has been determined */ +#define SS_STANDBY_CLUSTER_NORMAL_STANDBY \ + (SS_NORMAL_STANDBY && (t_thrd.xlog_cxt.server_mode == STANDBY_MODE || \ + t_thrd.postmaster_cxt.HaShmData->current_mode == STANDBY_MODE) && \ + (g_instance.attr.attr_common.cluster_run_mode == RUN_MODE_STANDBY) && \ (g_instance.attr.attr_storage.xlog_file_path != 0)) +/* standby mode in primary or standby, after reform done and primary id has been determined */ +#define SS_PRIMARY_STANDBY_CLUSTER_NORMAL_STANDBY \ + (SS_NORMAL_STANDBY && (g_instance.attr.attr_storage.xlog_file_path != 0)) + /* DMS_BUF_NEED_LOAD */ #define BUF_NEED_LOAD 0x1 /* DMS_BUF_IS_LOADED */ diff --git a/src/include/storage/xlog_share_storage/xlog_share_storage.h b/src/include/storage/xlog_share_storage/xlog_share_storage.h index 82a0b97665..d8c73f5da4 100644 --- a/src/include/storage/xlog_share_storage/xlog_share_storage.h +++ b/src/include/storage/xlog_share_storage/xlog_share_storage.h @@ -39,6 +39,8 @@ ShareStorageXLogCtl *AlignAllocShareStorageCtl(); void AlignFreeShareStorageCtl(ShareStorageXLogCtl *ctlInfo); bool LockNasWriteFile(int fd); bool UnlockNasWriteFile(int fd); +void SSDoXLogCopyFromLocal(XLogRecPtr copyEnd); +XLogRecPtr GetMaxPosCanOverWrite(); static inline void AddShareStorageXLopCopyBackendWakeupRequest() { diff --git a/src/test/ss/build_ss_database_common.sh b/src/test/ss/build_ss_database_common.sh index d67b738489..cdfa3a5466 100644 --- a/src/test/ss/build_ss_database_common.sh +++ b/src/test/ss/build_ss_database_common.sh @@ -68,15 +68,38 @@ assign_hatest_parameter() done } +assign_dorado_parameter() +{ + SS_DATA=$1 + for node in $@ + do + if [ ${node} == ${SS_DATA} ]; then + continue + fi + echo -e "\nxlog_lock_file_path = '${SS_DATA}/shared_lock_primary'" >> ${node}/postgresql.conf + echo -e "\nss_log_level = 255" >> ${node}/postgresql.conf + echo -e "\nss_log_backup_file_count = 100" >> ${node}/postgresql.conf + echo -e "\nss_log_max_file_size = 1GB" >> ${node}/postgresql.conf + done +} + + init_gaussdb() { inst_id=$1 dss_home=$2 SS_DATA=$3 nodedata_cfg=$4 - echo "${GAUSSHOME}/bin/gs_initdb -D ${SS_DATA}/dn${inst_id} --nodename=single_node -w ${SUPER_PASSWORD} --vgname=\"+data,+log${inst_id}\" --enable-dss --dms_url=\"${nodedata_cfg}\" -I ${inst_id} --socketpath=\"UDS:${dss_home}/.dss_unix_d_socket\"" + if [ $# == 5 ]; then + dorado_shared_disk=$5 + echo "${GAUSSHOME}/bin/gs_initdb -D ${SS_DATA}/dn${inst_id} --nodename=single_node -w ${SUPER_PASSWORD} --vgname=\"+data,+log${inst_id}\" --enable-dss --dms_url=\"${nodedata_cfg}\" -I ${inst_id} --socketpath=\"UDS:${dss_home}/.dss_unix_d_socket\" -d -n -g ${dorado_shared_disk}" - ${GAUSSHOME}/bin/gs_initdb -D ${SS_DATA}/dn${inst_id} --nodename=single_node -w ${SUPER_PASSWORD} --vgname="+data,+log${inst_id}" --enable-dss --dms_url="${nodedata_cfg}" -I ${inst_id} --socketpath="UDS:${dss_home}/.dss_unix_d_socket" + ${GAUSSHOME}/bin/gs_initdb -D ${SS_DATA}/dn${inst_id} --nodename=single_node -w ${SUPER_PASSWORD} --vgname="+data,+log${inst_id}" --enable-dss --dms_url="${nodedata_cfg}" -I ${inst_id} --socketpath="UDS:${dss_home}/.dss_unix_d_socket" -d -n -g ${dorado_shared_disk} + else + echo "${GAUSSHOME}/bin/gs_initdb -D ${SS_DATA}/dn${inst_id} --nodename=single_node -w ${SUPER_PASSWORD} --vgname=\"+data,+log${inst_id}\" --enable-dss --dms_url=\"${nodedata_cfg}\" -I ${inst_id} --socketpath=\"UDS:${dss_home}/.dss_unix_d_socket\"" + + ${GAUSSHOME}/bin/gs_initdb -D ${SS_DATA}/dn${inst_id} --nodename=single_node -w ${SUPER_PASSWORD} --vgname="+data,+log${inst_id}" --enable-dss --dms_url="${nodedata_cfg}" -I ${inst_id} --socketpath="UDS:${dss_home}/.dss_unix_d_socket" + fi } set_gaussdb_port() diff --git a/src/test/ss/conf_start_dss_inst.sh b/src/test/ss/conf_start_dss_inst.sh index 6255bb06d2..57bac8dc60 100644 --- a/src/test/ss/conf_start_dss_inst.sh +++ b/src/test/ss/conf_start_dss_inst.sh @@ -23,12 +23,33 @@ init_nodes_list() done } +init_nodes_list_standby_cluster() +{ + inst_count=$1 + last_id=`expr $inst_count - 1` + for i in `seq 0 $last_id` + do + inst_id=`expr $i + $INST_OFFSET - 2` + port=`expr $i + $DSS_PORT_BASE + 10000` + if [ $i != $last_id ]; then + mes_cfg=$mes_cfg$inst_id":127.0.0.1:"$port"," + else + mes_cfg=$mes_cfg$inst_id":127.0.0.1:"$port + fi + done +} + init_dss_conf() { dss_home=$1 - inst_id=`expr $2 + $INST_OFFSET` simu_path=$3 lock_path=$4 + cluster_mode=$5 + if [ ${cluster_mode} == 'standby_cluster' ]; then + inst_id=`expr $2 + $INST_OFFSET - 2` + else + inst_id=`expr $2 + $INST_OFFSET` + fi echo "init ${dss_home}" mkdir -p ${dss_home}/cfg @@ -84,6 +105,11 @@ create_vg() start_dss() { dsshome_pre=$1 + inst_count=$2 + cluster_mode=$3 + if [ ${cluster_mode} == 'standby_cluster' ]; then + inst_count=4 + fi echo " ================= starting $inst_count dssserver process =================" for i in `seq 0 $last_id` do @@ -110,16 +136,23 @@ function main() { mkdir -p ${pre_path} fi simu_path=$3 - init_nodes_list $inst_count - echo "init & start $inst_count dss node" + cluster_mode=$4 + if [ ${cluster_mode} == 'standby_cluster' ]; then + init_nodes_list_standby_cluster $inst_count + echo "init & start $inst_count dss node for standby_cluster" + else + cluster_mode='single_cluster' + init_nodes_list $inst_count + echo "init & start $inst_count dss node" + fi for i in `seq 0 $last_id` - do - echo "init_dss_conf ${pre_path}/dss_home$i" - init_dss_conf ${pre_path}/dss_home$i $i ${simu_path} ${pre_path} - done + do + echo "init_dss_conf ${pre_path}/dss_home$i" + init_dss_conf ${pre_path}/dss_home$i $i ${simu_path} ${pre_path} ${cluster_mode} + done create_vg ${pre_path}/dss_home0 ${simu_path} - start_dss ${pre_path}/dss_home ${inst_count} + start_dss ${pre_path}/dss_home ${inst_count} ${cluster_mode} } main $@ \ No newline at end of file diff --git a/src/test/ss/dual_cluster_single_shared_storage/common_function.sh b/src/test/ss/dual_cluster_single_shared_storage/common_function.sh new file mode 100644 index 0000000000..489f089429 --- /dev/null +++ b/src/test/ss/dual_cluster_single_shared_storage/common_function.sh @@ -0,0 +1,129 @@ +#!/bin/sh +# common function + +BIN_PATH=${GAUSSHOME}/bin +LIB_PATH=${GAUSSHOME}/lib + +PGPORT=(6600 6700) +SS_DATA=${HOME}/ss_hatest +nodedata_cfg="0:127.0.0.1:6611,1:127.0.0.1:6711" +export CM_CONFIG_PATH=${CURPATH}/cm_config.ini + + +STANDBY_PGPORT=(9600 9700) +SS_DATA_STANDBY=${HOME}/ss_hatest1 +standby_nodedata_cfg="0:127.0.0.1:9611,1:127.0.0.1:9711" + +master_cluster_dn=("$SS_DATA/dn0" "$SS_DATA/dn1") +standby_cluster_dn=("$SS_DATA_STANDBY/dn0" "$SS_DATA_STANDBY/dn1") + +function kill_dn() +{ + data_dir=$1 + echo "kill $data_dir" + ps -ef | grep -w $data_dir | grep -v grep | awk '{print $2}' | xargs kill -9 + sleep 1 +} + +function kill_primary_cluster() { + primary_dn=$1 + standby_dn=$2 + kill_dn $primary_dn + kill_dn $standby_dn +} + +function kill_standby_cluster() { + main_standby_dn=$1 + standby_dn=$2 + kill_dn $main_standby_dn + kill_dn $standby_dn +} + +function check_dn_startup() +{ + echo"checking $data_dir startup" + for i in $(seq 1 30) + do + if [ $(ps -ef | grep -w $data_dir | grep -v grep | awk '{print $2}' | wc -l) -gt 0 ]; then + sleep 2 + else + sleep 5 + return 0 + fi + done + echo "failed when check $data_dir startup" + exit 1 +} + +function start_dn() +{ + data_dir=$1 + echo "start $data_dir" + nohup $BIN_PATH/gaussdb -D $data_dir & 2>&1 & + sleep 10 +} + +function start_primary_cluster() { + primary_dn=$1 + standby_dn=$2 + ss_data=$3 + for node in $@ + do + if [ ${node} == ${ss_data} ]; then + continue + fi + gs_guc set -Z datanode -D $node -c "cluster_run_mode=cluster_primary" + done + export DSS_HOME=${ss_data}/dss_home0 + start_dn $primary_dn + export DSS_HOME=${ss_data}/dss_home1 + start_dn $standby_dn +} + +function start_standby_cluster() { + main_standby_dn=$1 + standby_dn=$2 + ss_data=$3 + for node in $@ + do + if [ ${node} == ${ss_data} ]; then + continue + fi + gs_guc set -Z datanode -D $node -c "cluster_run_mode=cluster_standby" + done + start_dn $main_standby_dn + start_dn $standby_dn +} + +function assign_dorado_master_parameter() +{ + for id in $@ + do + gs_guc set -Z datanode -D ${SS_DATA}/dn${id} -c "xlog_lock_file_path = '${SS_DATA}/shared_lock_primary'" + gs_guc set -Z datanode -D ${SS_DATA}/dn${id} -c "application_name = 'master_${id}'" + gs_guc set -Z datanode -D ${SS_DATA}/dn${id} -c "cross_cluster_replconninfo1='localhost=127.0.0.1 localport=${PGPORT[id]} remotehost=127.0.0.1 remoteport=${STANDBY_PGPORT[0]}'" + gs_guc set -Z datanode -D ${SS_DATA}/dn${id} -c "cross_cluster_replconninfo2='localhost=127.0.0.1 localport=${PGPORT[id]} remotehost=127.0.0.1 remoteport=${STANDBY_PGPORT[1]}'" + gs_guc set -Z datanode -D ${SS_DATA}/dn${id} -c "cluster_run_mode = 'cluster_primary'" + gs_guc set -Z datanode -D ${SS_DATA}/dn${id} -c "ha_module_debug = off" + gs_guc set -Z datanode -D ${SS_DATA}/dn${id} -c "ss_log_level = 255" + gs_guc set -Z datanode -D ${SS_DATA}/dn${id} -c "ss_log_backup_file_count = 100" + gs_guc set -Z datanode -D ${SS_DATA}/dn${id} -c "ss_log_max_file_size = 1GB" + done +} + +function assign_dorado_standby_parameter() +{ + for id in $@ + do + gs_guc set -Z datanode -D ${SS_DATA_STANDBY}/dn${id} -c "xlog_file_path = '${SS_DATA}/dorado_shared_disk'" + gs_guc set -Z datanode -D ${SS_DATA_STANDBY}/dn${id} -c "xlog_lock_file_path = '${SS_DATA_STANDBY}/shared_lock_standby'" + gs_guc set -Z datanode -D ${SS_DATA_STANDBY}/dn${id} -c "application_name = 'standby_${id}'" + gs_guc set -Z datanode -D ${SS_DATA_STANDBY}/dn${id} -c "cross_cluster_replconninfo1='localhost=127.0.0.1 localport=${STANDBY_PGPORT[id]} remotehost=127.0.0.1 remoteport=${PGPORT[0]}'" + gs_guc set -Z datanode -D ${SS_DATA_STANDBY}/dn${id} -c "cross_cluster_replconninfo2='localhost=127.0.0.1 localport=${STANDBY_PGPORT[id]} remotehost=127.0.0.1 remoteport=${PGPORT[1]}'" + gs_guc set -Z datanode -D ${SS_DATA_STANDBY}/dn${id} -c "cluster_run_mode = 'cluster_standby'" + gs_guc set -Z datanode -D ${SS_DATA_STANDBY}/dn${id} -c "ha_module_debug = off" + gs_guc set -Z datanode -D ${SS_DATA_STANDBY}/dn${id} -c "ss_log_level = 255" + gs_guc set -Z datanode -D ${SS_DATA_STANDBY}/dn${id} -c "ss_log_backup_file_count = 100" + gs_guc set -Z datanode -D ${SS_DATA_STANDBY}/dn${id} -c "ss_log_max_file_size = 1GB" + done +} \ No newline at end of file diff --git a/src/test/ss/dual_cluster_single_shared_storage/standby_full_build_reconnect.sh b/src/test/ss/dual_cluster_single_shared_storage/standby_full_build_reconnect.sh new file mode 100644 index 0000000000..270bb4eac7 --- /dev/null +++ b/src/test/ss/dual_cluster_single_shared_storage/standby_full_build_reconnect.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# full build + +CURPATH=$(dirname $(readlink -f $0)) +source ./common_function.sh + +function test_1() +{ + echo ${SS_DATA} + kill_primary_cluster ${SS_DATA}/dn0 ${SS_DATA}/dn1 + + assign_dorado_master_parameter 0 1 + + export CM_CONFIG_PATH=${CURPATH}/../cm_config.ini + export DSS_HOME=${SS_DATA}/dss_home0 + start_primary_cluster ${SS_DATA}/dn0 ${SS_DATA}/dn1 ${SS_DATA} + echo "start primary cluster success!" + + kill_standby_cluster ${SS_DATA_STANDBY}/dn0 ${SS_DATA_STANDBY}/dn1 + assign_dorado_standby_parameter 0 1 + echo "start standby cluster full build, cmd is: gs_ctl build -D ${SS_DATA_STANDBY}/dn0 -b cross_cluster_full -g 0 --vgname=+data --enable-dss --socketpath=\'${SS_DATA_STANDBY}/dss_home0/.dss_unix_d_socket\'" + export DSS_HOME=${SS_DATA_STANDBY}/dss_home0 + dss_home=${SS_DATA_STANDBY}/dss_home0 + gs_ctl build -D ${SS_DATA_STANDBY}/dn0 -b cross_cluster_full -g 0 --vgname=+data --enable-dss --socketpath="UDS:${dss_home}/.dss_unix_d_socket" -q + echo "start standby cluster full build success!" + + export CM_CONFIG_PATH=${CURPATH}/../cm_config_standby.ini + start_standby_cluster ${SS_DATA_STANDBY}/dn0 ${SS_DATA_STANDBY}/dn1 ${SS_DATA_STANDBY} + echo "start standby cluster success!" +} + +function tear_down() { + stop_primary_cluster + stop_standby_cluster + sleep 5 +} + +test_1 +#tear_down \ No newline at end of file diff --git a/src/test/ss/ha_test.sh b/src/test/ss/ha_test.sh index ac932fc84e..0d799fb739 100644 --- a/src/test/ss/ha_test.sh +++ b/src/test/ss/ha_test.sh @@ -15,8 +15,11 @@ declare -a DB_STATUS declare -a DB_HOME PGPORT=(6600 6700) +STANDBY_PGPORT=(9600 9700) SS_DATA=${HOME}/ss_hatest +SS_DATA_STANDBY=${HOME}/ss_hatest1 nodedata_cfg="0:127.0.0.1:6611,1:127.0.0.1:6711" +standby_nodedata_cfg="0:127.0.0.1:9611,1:127.0.0.1:9711" export CM_CONFIG_PATH=${CURPATH}/cm_config.ini export TPCC_PATH=~/benchmarksql/run TPCC_P=("0-primary.gs" "1-primary.gs" "2-primary.gs") @@ -295,6 +298,49 @@ function deploy_two_inst start_gaussdb ${SS_DATA}/dn1 } +function deploy_dual_cluster +{ + echo "deploy master cluster" + source ${CURPATH}/build_ss_database_common.sh + kill_gaussdb + clean_database_env ${SS_DATA} + DORADO_SHARED_DISK=${HOME}/ss_hatest/dorado_shared_disk + + sh ${CURPATH}/conf_start_dss_inst.sh 2 ${SS_DATA} ${SS_DATA}/dss_disk + init_gaussdb 0 ${SS_DATA}/dss_home0 $SS_DATA $nodedata_cfg $DORADO_SHARED_DISK + init_gaussdb 1 ${SS_DATA}/dss_home1 $SS_DATA $nodedata_cfg + + set_gaussdb_port ${SS_DATA}/dn0 ${PGPORT[0]} + set_gaussdb_port ${SS_DATA}/dn1 ${PGPORT[1]} + + assign_hatest_parameter ${SS_DATA}/dn0 ${SS_DATA}/dn1 + assign_dorado_parameter ${SS_DATA} ${SS_DATA}/dn0 + + export DSS_HOME=${SS_DATA}/dss_home0 + start_gaussdb ${SS_DATA}/dn0 + export DSS_HOME=${SS_DATA}/dss_home1 + start_gaussdb ${SS_DATA}/dn1 + + echo "deploy standby cluster" + clean_database_env ${SS_DATA_STANDBY} + sh ${CURPATH}/conf_start_dss_inst.sh 2 ${SS_DATA_STANDBY} ${SS_DATA_STANDBY}/dss_disk standby_cluster + init_gaussdb 0 ${SS_DATA_STANDBY}/dss_home0 $SS_DATA_STANDBY $standby_nodedata_cfg + init_gaussdb 1 ${SS_DATA_STANDBY}/dss_home1 $SS_DATA_STANDBY $standby_nodedata_cfg + + set_gaussdb_port ${SS_DATA_STANDBY}/dn0 ${STANDBY_PGPORT[0]} + set_gaussdb_port ${SS_DATA_STANDBY}/dn1 ${STANDBY_PGPORT[1]} + + assign_hatest_parameter ${SS_DATA_STANDBY}/dn0 ${SS_DATA_STANDBY}/dn1 + + cp ${CURPATH}/cm_config.ini ${CURPATH}/cm_config_standby.ini + export CM_CONFIG_PATH=${CURPATH}/cm_config_standby.ini + export DSS_HOME=${SS_DATA_STANDBY}/dss_home0 + start_gaussdb ${SS_DATA_STANDBY}/dn0 + export DSS_HOME=${SS_DATA_STANDBY}/dss_home1 + start_gaussdb ${SS_DATA_STANDBY}/dn1 + +} + function testcase() { restart_primary @@ -514,7 +560,13 @@ function muti_execute() } check_user -deploy_two_inst +if [ "$1" == "dual_cluster" ]; then + echo "starting dual cluster" + deploy_dual_cluster +else + echo "starting single cluster" + deploy_two_inst +fi ha_test_init testcase ## if you want use tpcc -- Gitee