Ejemplo n.º 1
0
void GTM_WriteRestorePoint(void)
{
	FILE *f;

	GTM_RWLockAcquire(&gtm_bkup_lock, GTM_LOCKMODE_WRITE);
	if (!gtm_need_bkup)
	{
		GTM_RWLockRelease(&gtm_bkup_lock);
		return;
	}

	f = fopen(GTMControlFile, "w");
	if (f == NULL)
	{
		ereport(LOG, (errno,
					  errmsg("Cannot open control file"),
					  errhint("%s", strerror(errno))));
		return;
	}
	gtm_need_bkup = FALSE;
	GTM_RWLockRelease(&gtm_bkup_lock);
	GTM_WriteRestorePointXid(f);
	GTM_WriteRestorePointSeq(f);
	fclose(f);
}
Ejemplo n.º 2
0
void
ProcessGTMEndBackup(Port *myport, StringInfo message)
{
	int ii;
	GTM_ThreadInfo *my_threadinfo;
	StringInfoData buf;

	pq_getmsgend(message);
	my_threadinfo = GetMyThreadInfo;

	for (ii = 0; ii < GTMThreads->gt_array_size; ii++)
	{
		if (GTMThreads->gt_threads[ii] && GTMThreads->gt_threads[ii] != my_threadinfo)
			GTM_RWLockRelease(&GTMThreads->gt_threads[ii]->thr_lock);
	}
	my_threadinfo->thr_status = GTM_THREAD_RUNNING;
	pq_beginmessage(&buf, 'S');
	pq_sendint(&buf, END_BACKUP_RESULT, 4);
	pq_endmessage(myport, &buf);
	pq_flush(myport);
}
Ejemplo n.º 3
0
void GTM_WriteBarrierBackup(char *barrier_id)
{
#define MyMAXPATH 1023

	FILE  *f;
	char BarrierFilePath[MyMAXPATH+1];
	extern char *GTMDataDir;

	snprintf(BarrierFilePath, MyMAXPATH, "%s/GTM_%s.control", GTMDataDir, barrier_id);
	if ((f = fopen(BarrierFilePath, "w")) == NULL)
	{
		ereport(LOG, (errno,
					  errmsg("Cannot open control file"),
					  errhint("%s", strerror(errno))));
		return;
	}
	GTM_RWLockAcquire(&gtm_bkup_lock, GTM_LOCKMODE_WRITE);
	gtm_need_bkup = FALSE;
	GTM_RWLockRelease(&gtm_bkup_lock);
	GTM_WriteRestorePointXid(f);
	GTM_WriteRestorePointSeq(f);
	fclose(f);
}
Ejemplo n.º 4
0
void GTM_SetNeedBackup(void)
{
	GTM_RWLockAcquire(&gtm_bkup_lock, GTM_LOCKMODE_READ);
	gtm_need_bkup = TRUE;
	GTM_RWLockRelease(&gtm_bkup_lock);
}
Ejemplo n.º 5
0
int
gtm_standby_restore_gxid(void)
{
	int num_txn;
	GTM_Transactions txn;
	int i;

	/*
	 * Restore gxid data.
	 */
	num_txn = get_txn_gxid_list(GTM_ActiveConn, &txn);

	GTM_RWLockAcquire(&GTMTransactions.gt_XidGenLock, GTM_LOCKMODE_WRITE);
	GTM_RWLockAcquire(&GTMTransactions.gt_TransArrayLock, GTM_LOCKMODE_WRITE);

	GTMTransactions.gt_txn_count = txn.gt_txn_count;
	GTMTransactions.gt_gtm_state = txn.gt_gtm_state;
	GTMTransactions.gt_nextXid = txn.gt_nextXid;
	GTMTransactions.gt_oldestXid = txn.gt_oldestXid;
	GTMTransactions.gt_xidVacLimit = txn.gt_xidVacLimit;
	GTMTransactions.gt_xidWarnLimit = txn.gt_xidWarnLimit;
	GTMTransactions.gt_xidStopLimit = txn.gt_xidStopLimit;
	GTMTransactions.gt_xidWrapLimit = txn.gt_xidWrapLimit;
	GTMTransactions.gt_latestCompletedXid = txn.gt_latestCompletedXid;
	GTMTransactions.gt_recent_global_xmin = txn.gt_recent_global_xmin;
	GTMTransactions.gt_lastslot = txn.gt_lastslot;

	for (i = 0; i < num_txn; i++)
	{
		GTMTransactions.gt_transactions_array[i].gti_handle = txn.gt_transactions_array[i].gti_handle;
		GTMTransactions.gt_transactions_array[i].gti_thread_id = txn.gt_transactions_array[i].gti_thread_id;
		GTMTransactions.gt_transactions_array[i].gti_in_use = txn.gt_transactions_array[i].gti_in_use;
		GTMTransactions.gt_transactions_array[i].gti_gxid = txn.gt_transactions_array[i].gti_gxid;
		GTMTransactions.gt_transactions_array[i].gti_state = txn.gt_transactions_array[i].gti_state;
		GTMTransactions.gt_transactions_array[i].gti_coordname = txn.gt_transactions_array[i].gti_coordname;
		GTMTransactions.gt_transactions_array[i].gti_xmin = txn.gt_transactions_array[i].gti_xmin;
		GTMTransactions.gt_transactions_array[i].gti_isolevel = txn.gt_transactions_array[i].gti_isolevel;
		GTMTransactions.gt_transactions_array[i].gti_readonly = txn.gt_transactions_array[i].gti_readonly;
		GTMTransactions.gt_transactions_array[i].gti_backend_id = txn.gt_transactions_array[i].gti_backend_id;

		if (txn.gt_transactions_array[i].nodestring == NULL )
			GTMTransactions.gt_transactions_array[i].nodestring = NULL;
		else
			GTMTransactions.gt_transactions_array[i].nodestring = txn.gt_transactions_array[i].nodestring;

		/* GID */
		if (txn.gt_transactions_array[i].gti_gid == NULL )
			GTMTransactions.gt_transactions_array[i].gti_gid = NULL;
		else
			GTMTransactions.gt_transactions_array[i].gti_gid = txn.gt_transactions_array[i].gti_gid;

		/* copy GTM_SnapshotData */
		GTMTransactions.gt_transactions_array[i].gti_current_snapshot.sn_xmin =
						txn.gt_transactions_array[i].gti_current_snapshot.sn_xmin;
		GTMTransactions.gt_transactions_array[i].gti_current_snapshot.sn_xmax =
						txn.gt_transactions_array[i].gti_current_snapshot.sn_xmax;
		GTMTransactions.gt_transactions_array[i].gti_current_snapshot.sn_recent_global_xmin =
						txn.gt_transactions_array[i].gti_current_snapshot.sn_recent_global_xmin;
		GTMTransactions.gt_transactions_array[i].gti_current_snapshot.sn_xcnt =
						txn.gt_transactions_array[i].gti_current_snapshot.sn_xcnt;
		GTMTransactions.gt_transactions_array[i].gti_current_snapshot.sn_xip =
						txn.gt_transactions_array[i].gti_current_snapshot.sn_xip;
		/* end of copying GTM_SnapshotData */

		GTMTransactions.gt_transactions_array[i].gti_snapshot_set =
						txn.gt_transactions_array[i].gti_snapshot_set;
		GTMTransactions.gt_transactions_array[i].gti_vacuum =
						txn.gt_transactions_array[i].gti_vacuum;

		/*
		 * Is this correct? Is GTM_TXN_COMMITTED transaction categorized as "open"?
		 */
		if (GTMTransactions.gt_transactions_array[i].gti_state != GTM_TXN_ABORTED)
		{
			GTMTransactions.gt_open_transactions =
					gtm_lappend(GTMTransactions.gt_open_transactions,
							&GTMTransactions.gt_transactions_array[i]);
		}
	}

	dump_transactions_elog(&GTMTransactions, num_txn);

	GTM_RWLockRelease(&GTMTransactions.gt_TransArrayLock);
	GTM_RWLockRelease(&GTMTransactions.gt_XidGenLock);

	elog(LOG, "Restoring %d gxid(s) done.", num_txn);
	return 1;
}