return PQconnectGTM(connect_string);
}
-void
-disconnect_gtm(GTM_Conn *conn)
-{
- GTMPQfinish(conn);
-}
-
/*
* begin_replication_initial_sync() acquires several locks to prepare
* for copying internal transaction, xid and sequence information
return pthread_rwlock_destroy(&lock->lk_lock);
}
-/*
- * Conditionally acquire a lock. If the lock is not available, the function
- * immediately returns without blocking.
- *
- * Returns true if lock is successfully acquired. Otherwise returns false
- */
-bool
-GTM_RWLockConditionalAcquire(GTM_RWLock *lock, GTM_LockMode mode)
-{
- int status = EINVAL;
-
- switch (mode)
- {
- case GTM_LOCKMODE_WRITE:
- status = pthread_rwlock_trywrlock(&lock->lk_lock);
-#ifdef GTM_LOCK_DEBUG
- if (!status)
- {
- pthread_mutex_lock(&lock->lk_debug_mutex);
- lock->wr_granted = true;
- lock->wr_owner = pthread_self();
- lock->rd_holders_count = 0;
- lock->rd_holders_overflow = false;
- pthread_mutex_unlock(&lock->lk_debug_mutex);
- }
-#endif
- break;
-
- case GTM_LOCKMODE_READ:
- status = pthread_rwlock_tryrdlock(&lock->lk_lock);
-#ifdef GTM_LOCK_DEBUG
- if (!status)
- {
- pthread_mutex_lock(&lock->lk_debug_mutex);
- if (lock->rd_holders_count == GTM_LOCK_DEBUG_MAX_READ_TRACKERS)
- {
- elog(WARNING, "Too many threads waiting for a read-lock");
- lock->rd_holders_overflow = true;
- }
- else
- {
- lock->rd_holders[lock->rd_holders_count++] = pthread_self();
- lock->rd_holders_overflow = false;
- }
- pthread_mutex_unlock(&lock->lk_debug_mutex);
- }
-#endif
- break;
-
- default:
- elog(ERROR, "Invalid lockmode");
- break;
- }
-
- return status ? false : true;
-}
-
/*
* Initialize a mutex lock
*/
return pthread_mutex_unlock(&lock->lk_lock);
}
-/*
- * Conditionally acquire a lock. If the lock is not available, the function
- * immediately returns without blocking.
- *
- * Returns true if lock is successfully acquired. Otherwise returns false
- */
-bool
-GTM_MutexLockConditionalAcquire(GTM_MutexLock *lock)
-{
- int status = pthread_mutex_trylock(&lock->lk_lock);
- return status ? false : true;
-}
-
/*
* Initialize a condition variable
*/
return pthread_cond_init(&cv->cv_condvar, NULL);
}
-/*
- * Destroy the conditional variable
- */
-int
-GTM_CVDestroy(GTM_CV *cv)
-{
- return pthread_cond_destroy(&cv->cv_condvar);
-}
-
/*
* Wake up all the threads waiting on this conditional variable
*/
* ---> sn_xcnt ---> GXID * sn_xcnt
* |<--- sn_xip -->|
*/
-size_t
+static size_t
gtm_get_snapshotdata_size(GTM_SnapshotData *data)
{
size_t len = 0;
* gtm_serialize_snapshotdata
* Serialize a GTM_SnapshotData structure
*/
-size_t
+static size_t
gtm_serialize_snapshotdata(GTM_SnapshotData *data, char *buf, size_t buflen)
{
int len = 0;
* Deserialize a GTM_SnapshotData structure
* -----------------------------------------------------
*/
-size_t
+static size_t
gtm_deserialize_snapshotdata(GTM_SnapshotData *data, const char *buf, size_t buflen)
{
size_t len = 0;
* Original gti_gid serialization was just "null-terminated string".
* This should be prefixed with the length of the string.
*/
-size_t
+static size_t
gtm_get_transactioninfo_size(GTM_TransactionInfo *data)
{
size_t len = 0;
* Serialize a GTM_TransactionInfo structure
* -----------------------------------------------------
*/
-size_t
+static size_t
gtm_serialize_transactioninfo(GTM_TransactionInfo *data, char *buf, size_t buflen)
{
int len = 0;
* Deserialize a GTM_TransactionInfo structure
* -----------------------------------------------------
*/
-size_t
+static size_t
gtm_deserialize_transactioninfo(GTM_TransactionInfo *data, const char *buf, size_t maxlen)
{
int len = 0;
static char **result_name = NULL;
static int result_max;
+static
void gtm_util_init_nametabs(void)
{
int ii;
return "UNKNOWN_MESSAGE";
return message_name[type];
}
-
-char *gtm_util_result_name(GTM_ResultType type)
-{
- if (result_name == NULL)
- gtm_util_init_nametabs();
- if (type > result_max)
- return "UNKNOWN_RESULT";
- return result_name[type];
-}
/*
* Initialize a new sequence. Optionally set the initial value of the sequence.
*/
-int
+static int
GTM_SeqOpen(GTM_SequenceKey seqkey,
GTM_Sequence increment_by,
GTM_Sequence minval,
* We don't track altered sequences because changes to sequence values are not
* transactional and must not be rolled back if the transaction aborts.
*/
-int GTM_SeqAlter(GTM_SequenceKey seqkey,
- GTM_Sequence increment_by,
- GTM_Sequence minval,
- GTM_Sequence maxval,
- GTM_Sequence startval,
- GTM_Sequence lastval,
- bool cycle,
- bool is_restart)
+static int
+GTM_SeqAlter(GTM_SequenceKey seqkey,
+ GTM_Sequence increment_by,
+ GTM_Sequence minval,
+ GTM_Sequence maxval,
+ GTM_Sequence startval,
+ GTM_Sequence lastval,
+ bool cycle,
+ bool is_restart)
{
GTM_SeqInfo *seqinfo = seq_find_seqinfo(seqkey);
/*
* Destroy the given sequence depending on type of given key
*/
-int
+static int
GTM_SeqClose(GTM_SequenceKey seqkey, GlobalTransactionId gxid)
{
int res;
/*
* Rename an existing sequence with a new name
*/
-int
+static int
GTM_SeqRename(GTM_SequenceKey seqkey, GTM_SequenceKey newseqkey,
GlobalTransactionId gxid)
{
/*
* Get current value for the sequence without incrementing it
*/
-void
+static void
GTM_SeqGetCurrent(GTM_SequenceKey seqkey, char *coord_name,
int coord_procid, GTM_Sequence *result)
{
/*
* Set values for the sequence
*/
-int
+static int
GTM_SeqSetVal(GTM_SequenceKey seqkey, char *coord_name,
int coord_procid, GTM_Sequence nextval, bool iscalled)
{
/*
* Get next value for the sequence
*/
-int
+static int
GTM_SeqGetNext(GTM_SequenceKey seqkey, char *coord_name,
int coord_procid, GTM_Sequence range,
GTM_Sequence *result, GTM_Sequence *rangemax)
/*
* Reset the sequence
*/
-int
+static int
GTM_SeqReset(GTM_SequenceKey seqkey)
{
GTM_SeqInfo *seqinfo = seq_find_seqinfo(seqkey);
* Note: this function should probably not be called with an argument that's
* not statically allocated (see xip allocation below).
*/
-GTM_Snapshot
+static GTM_Snapshot
GTM_GetTransactionSnapshot(GTM_TransactionHandle handle[], int txn_count, int *status)
{
GlobalTransactionId xmin;
return;
}
-
-/*
- * Free the snapshot data. The snapshot itself is not freed though
- */
-void
-GTM_FreeSnapshotData(GTM_Snapshot snapshot)
-{
- if (snapshot == NULL)
- return;
-
- if (snapshot->sn_xip != NULL)
- {
- Assert(snapshot->sn_xcnt);
- pfree(snapshot->sn_xip);
- snapshot->sn_xip = NULL;
- }
-}
}
-GTM_Conn *
+static GTM_Conn *
gtm_standby_reconnect_to_standby(GTM_Conn *old_conn, int retry_max)
{
GTM_Conn *newconn = NULL;
return thrinfo;
}
-/*
- * Exit the current thread
- */
-void
-GTM_ThreadExit(void)
-{
- /* XXX To be implemented */
-}
-
-int
-GTM_ThreadJoin(GTM_ThreadInfo *thrinfo)
-{
- int error;
- void *data;
-
- error = pthread_join(thrinfo->thr_id, &data);
-
- return error;
-}
-
-/*
- * Get thread information for the given thread, identified by the
- * thread_id
- */
-GTM_ThreadInfo *
-GTM_GetThreadInfo(GTM_ThreadID thrid)
-{
-
- return NULL;
-}
-
/*
* Cleanup routine for the thread
*/
return thrinfo;
}
-void
-GTM_LockAllOtherThreads(void)
-{
- GTM_ThreadInfo *my_threadinfo = GetMyThreadInfo;
- int ii;
-
- for (ii = 0; ii < GTMThreads->gt_array_size; ii++)
- {
- if (GTMThreads->gt_threads[ii] && GTMThreads->gt_threads[ii] != my_threadinfo)
- GTM_RWLockAcquire(>MThreads->gt_threads[ii]->thr_lock, GTM_LOCKMODE_WRITE);
- }
-}
-
-void
-GTM_UnlockAllOtherThreads(void)
-{
- GTM_ThreadInfo *my_threadinfo = GetMyThreadInfo;
- int ii;
-
- for (ii = 0; ii < GTMThreads->gt_array_size; ii++)
- {
- if (GTMThreads->gt_threads[ii] && GTMThreads->gt_threads[ii] != my_threadinfo)
- GTM_RWLockRelease(>MThreads->gt_threads[ii]->thr_lock);
- }
-}
-
void
GTM_DoForAllOtherThreads(void (* process_routine)(GTM_ThreadInfo *))
{
#define GTM_CONTROL_VERSION 20160302
/* Local functions */
-static XidStatus GlobalTransactionIdGetStatus(GlobalTransactionId transactionId);
static bool GTM_SetDoVacuum(GTM_TransactionHandle handle);
static void init_GTM_TransactionInfo(GTM_TransactionInfo *gtm_txninfo,
GTM_TransactionHandle txn,
static void clean_GTM_TransactionInfo(GTM_TransactionInfo *gtm_txninfo);
static GTM_TransactionHandle GTM_GlobalSessionIDToHandle(
const char *global_sessionid);
+static bool GTM_NeedXidRestoreUpdate(void);
+static int GTM_CommitTransaction(GTM_TransactionHandle txn,
+ int waited_xid_count, GlobalTransactionId *waited_xids);
GlobalTransactionId ControlXid; /* last one written to control file */
GTM_Transactions GTMTransactions;
return;
}
-/*
- * Get the status of current or past transaction.
- */
-static XidStatus
-GlobalTransactionIdGetStatus(GlobalTransactionId transactionId)
-{
- XidStatus xidstatus = TRANSACTION_STATUS_IN_PROGRESS;
-
- /*
- * Also, check to see if the transaction ID is a permanent one.
- */
- if (!GlobalTransactionIdIsNormal(transactionId))
- {
- if (GlobalTransactionIdEquals(transactionId, BootstrapGlobalTransactionId))
- return TRANSACTION_STATUS_COMMITTED;
- if (GlobalTransactionIdEquals(transactionId, FrozenGlobalTransactionId))
- return TRANSACTION_STATUS_COMMITTED;
- return TRANSACTION_STATUS_ABORTED;
- }
-
- /*
- * TODO To be implemented
- * This code is not completed yet and the latter code must not be reached.
- */
- Assert(0);
- return xidstatus;
-}
/*
* Given the GXID, find the corresponding transaction handle.
return InvalidTransactionHandle;
}
-bool
+static bool
GTM_IsGXIDInProgress(GlobalTransactionId gxid)
{
return (GTM_GXIDToHandle_Internal(gxid, false) !=
* Given the GID (for a prepared transaction), find the corresponding
* transaction handle.
*/
-GTM_TransactionHandle
+static GTM_TransactionHandle
GTM_GIDToHandle(char *gid)
{
gtm_ListCell *elem = NULL;
return last_client_id;
}
-/*
- * GlobalTransactionIdDidCommit
- * True iff transaction associated with the identifier did commit.
- *
- * Note:
- * Assumes transaction identifier is valid.
- */
-bool /* true if given transaction committed */
-GlobalTransactionIdDidCommit(GlobalTransactionId transactionId)
-{
- XidStatus xidstatus;
-
- xidstatus = GlobalTransactionIdGetStatus(transactionId);
-
- /*
- * If it's marked committed, it's committed.
- */
- if (xidstatus == TRANSACTION_STATUS_COMMITTED)
- return true;
-
- /*
- * It's not committed.
- */
- return false;
-}
-
-/*
- * GlobalTransactionIdDidAbort
- * True iff transaction associated with the identifier did abort.
- *
- * Note:
- * Assumes transaction identifier is valid.
- */
-bool /* true if given transaction aborted */
-GlobalTransactionIdDidAbort(GlobalTransactionId transactionId)
-{
- XidStatus xidstatus;
-
- xidstatus = GlobalTransactionIdGetStatus(transactionId);
-
- /*
- * If it's marked aborted, it's aborted.
- */
- if (xidstatus == TRANSACTION_STATUS_ABORTED)
- return true;
-
- /*
- * It's not aborted.
- */
- return false;
-}
-
-
/*
* Set that the transaction is doing vacuum
*
* The new XID is also stored into the transaction info structure of the given
* transaction before returning.
*/
-bool
+static bool
GTM_GetGlobalTransactionIdMulti(GTM_TransactionHandle handle[], int txn_count,
GlobalTransactionId gxid[], GTM_TransactionHandle new_handle[],
int *new_txn_count)
}
/* Transaction Control */
-int
+static int
GTM_BeginTransactionMulti(GTM_IsolationLevel isolevel[],
bool readonly[],
const char *global_sessionid[],
}
/* Transaction Control */
-GTM_TransactionHandle
+static GTM_TransactionHandle
GTM_BeginTransaction(GTM_IsolationLevel isolevel,
bool readonly,
const char *global_sessionid)
}
-void
+static void
GTM_BkupBeginTransactionMulti(GTM_IsolationLevel *isolevel,
bool *readonly,
const char **global_sessionid,
MemoryContextSwitchTo(oldContext);
}
-void
+static void
GTM_BkupBeginTransaction(GTM_IsolationLevel isolevel,
bool readonly,
const char *global_sessionid,
&global_sessionid,
&client_id, &connid, 1);
}
-/*
- * Same as GTM_RollbackTransaction, but takes GXID as input
- */
-int
-GTM_RollbackTransactionGXID(GlobalTransactionId gxid)
-{
- GTM_TransactionHandle txn = GTM_GXIDToHandle(gxid);
- return GTM_RollbackTransaction(txn);
-}
/*
* Rollback multiple transactions in one go
*/
-int
+static int
GTM_RollbackTransactionMulti(GTM_TransactionHandle txn[], int txn_count, int status[])
{
GTM_TransactionInfo *gtm_txninfo[txn_count];
/*
* Rollback a transaction
*/
-int
+static int
GTM_RollbackTransaction(GTM_TransactionHandle txn)
{
int status;
return status;
}
-
-/*
- * Same as GTM_CommitTransaction but takes GXID as input
- */
-int
-GTM_CommitTransactionGXID(GlobalTransactionId gxid)
-{
- GTM_TransactionHandle txn = GTM_GXIDToHandle(gxid);
- return GTM_CommitTransaction(txn, 0, NULL);
-}
-
/*
* Commit multiple transactions in one go
*/
-int
+static int
GTM_CommitTransactionMulti(GTM_TransactionHandle txn[], int txn_count,
int waited_xid_count, GlobalTransactionId *waited_xids,
int status[])
/*
* Prepare a transaction
*/
-int
+static int
GTM_PrepareTransaction(GTM_TransactionHandle txn)
{
GTM_TransactionInfo *gtm_txninfo = NULL;
/*
* Commit a transaction
*/
-int
+static int
GTM_CommitTransaction(GTM_TransactionHandle txn, int waited_xid_count,
GlobalTransactionId *waited_xids)
{
/*
* Prepare a transaction
*/
-int
+static int
GTM_StartPreparedTransaction(GTM_TransactionHandle txn,
char *gid,
char *nodestring)
return STATUS_OK;
}
-/*
- * Same as GTM_PrepareTransaction but takes GXID as input
- */
-int
-GTM_StartPreparedTransactionGXID(GlobalTransactionId gxid,
- char *gid,
- char *nodestring)
-{
- GTM_TransactionHandle txn = GTM_GXIDToHandle(gxid);
- return GTM_StartPreparedTransaction(txn, gid, nodestring);
-}
-
-int
+static int
GTM_GetGIDData(GTM_TransactionHandle prepared_txn,
GlobalTransactionId *prepared_gxid,
char **nodestring)
return STATUS_OK;
}
-/*
- * Get status of the given transaction
- */
-GTM_TransactionStates
-GTM_GetStatus(GTM_TransactionHandle txn)
-{
- GTM_TransactionInfo *gtm_txninfo = GTM_HandleToTransactionInfo(txn);
- return gtm_txninfo->gti_state;
-}
-
-/*
- * Same as GTM_GetStatus but takes GXID as input
- */
-GTM_TransactionStates
-GTM_GetStatusGXID(GlobalTransactionId gxid)
-{
- GTM_TransactionHandle txn = GTM_GXIDToHandle(gxid);
- return GTM_GetStatus(txn);
-}
-
/*
* Process MSG_TXN_BEGIN message
*/
GTM_RWLockRelease(>MTransactions.gt_XidGenLock);
}
+static
bool GTM_NeedXidRestoreUpdate(void)
{
return(GlobalTransactionIdPrecedesOrEquals(GTMTransactions.gt_backedUpXid, GTMTransactions.gt_nextXid));
}
-
-GlobalTransactionId
-GTM_GetLatestCompletedXID(void)
-{
- return GTMTransactions.gt_latestCompletedXid;
-}
-
void
GTM_ForgetCreatedSequence(GlobalTransactionId gxid, void *seq)
{
gtm_txninfo->gti_altered_seqs = gtm_lcons(seq,
gtm_txninfo->gti_altered_seqs);
}
-
-
-/*
- * TODO
- */
-int GTM_GetAllTransactions(GTM_TransactionInfo txninfo[], uint32 txncnt);
-
-/*
- * TODO
- */
-uint32 GTM_GetAllPrepared(GlobalTransactionId gxids[], uint32 gxidcnt);
-
static int pgxcnode_add_info(GTM_PGXCNodeInfo *node);
static char *pgxcnode_copy_char(const char *str);
+static void Recovery_RecordRegisterInfo(GTM_PGXCNodeInfo *nodeinfo,
+ bool is_register);
+
#define pgxcnode_type_equal(type1,type2) (type1 == type2)
#define pgxcnode_port_equal(port1,port2) (port1 == port2)
/*
* Add a Register or Unregister record on PGXC Node file on disk.
*/
-void
+static void
Recovery_RecordRegisterInfo(GTM_PGXCNodeInfo *nodeinfo, bool is_register)
{
int ctlfd;
MemoryContextSwitchTo(oldContext);
}
-int
+static int
Recovery_PGXCNodeBackendDisconnect(GTM_PGXCNodeType type, char *nodename, int socket)
{
GTM_PGXCNodeInfo *nodeinfo = pgxcnode_find_info(type, nodename);
int GTM_ThreadAdd(GTM_ThreadInfo *thrinfo);
int GTM_ThreadRemove(GTM_ThreadInfo *thrinfo);
-int GTM_ThreadJoin(GTM_ThreadInfo *thrinfo);
-void GTM_ThreadExit(void);
void ConnFree(Port *port);
-void GTM_LockAllOtherThreads(void);
-void GTM_UnlockAllOtherThreads(void);
void GTM_DoForAllOtherThreads(void (* process_routine)(GTM_ThreadInfo *));
void GTM_SetInitialAndNextClientIdentifierAtPromote(void);
GTM_ThreadInfo *GTM_ThreadCreate(GTM_ConnectionInfo *conninfo,
void *(* startroutine)(void *));
-GTM_ThreadInfo * GTM_GetThreadInfo(GTM_ThreadID thrid);
-#ifdef XCP
+
extern void SaveControlInfo(void);
void GTM_RestoreSeqInfo(FILE *ctlf, struct GTM_RestoreContext *context);
+
#define CONTROL_INTERVAL 50000
-#endif
/*
* pthread keys to get thread specific information
#define GTM_MAX_CACHED_TRANSINFO 0
#define GTM_HaveEnoughCachedTransInfo() (gtm_list_length(GTM_CachedTransInfo) >= GTM_MAX_CACHED_TRANSINFO)
-#define START_CRIT_SECTION() (CritSectionCount++)
-
-#define END_CRIT_SECTION() \
- do { \
- Assert(CritSectionCount > 0); \
- CritSectionCount--; \
- } while(0)
-
#define GTM_CLIENT_ID_EQ(a, b) \
((a) == (b))
#define GTM_CLIENT_ID_LT(a, b) \
#define RestoreDuration 2000
extern void GTM_WriteRestorePoint(void);
-extern void GTM_MakeBackup(char *path);
extern void GTM_SetNeedBackup(void);
extern bool GTM_NeedBackup(void);
extern void GTM_WriteBarrierBackup(char *barrier_id);
* Connection Management API
*/
GTM_Conn *connect_gtm(const char *connect_string);
-void disconnect_gtm(GTM_Conn *conn);
int begin_replication_initial_sync(GTM_Conn *);
int end_replication_initial_sync(GTM_Conn *);
* Note: if you need to change it, you must change pg_class.h as well.
* ----------------
*/
-#define BootstrapGlobalTransactionId ((GlobalTransactionId) 1)
-#define FrozenGlobalTransactionId ((GlobalTransactionId) 2)
#define FirstNormalGlobalTransactionId ((GlobalTransactionId) 3)
#define MaxGlobalTransactionId ((GlobalTransactionId) 0xFFFFFFFF)
*/
#define GlobalTransactionIdIsNormal(xid) ((xid) >= FirstNormalGlobalTransactionId)
#define GlobalTransactionIdEquals(id1, id2) ((id1) == (id2))
-#define GlobalTransactionIdStore(xid, dest) (*(dest) = (xid))
-#define StoreInvalidGlobalTransactionId(dest) (*(dest) = InvalidGlobalTransactionId)
/* advance a transaction ID variable, handling wraparound correctly */
#define GlobalTransactionIdAdvance(dest) \
(dest) = FirstNormalGlobalTransactionId; \
} while(0)
-/* back up a transaction ID variable, handling wraparound correctly */
-#define GlobalTransactionIdRetreat(dest) \
- do { \
- (dest)--; \
- } while ((dest) < FirstNormalGlobalTransactionId)
-
extern bool GlobalTransactionIdPrecedes(GlobalTransactionId id1, GlobalTransactionId id2);
extern bool GlobalTransactionIdPrecedesOrEquals(GlobalTransactionId id1, GlobalTransactionId id2);
extern bool GlobalTransactionIdFollows(GlobalTransactionId id1, GlobalTransactionId id2);
extern bool GTM_RWLockRelease(GTM_RWLock *lock);
extern int GTM_RWLockInit(GTM_RWLock *lock);
extern int GTM_RWLockDestroy(GTM_RWLock *lock);
-extern bool GTM_RWLockConditionalAcquire(GTM_RWLock *lock, GTM_LockMode mode);
extern bool GTM_MutexLockAcquire(GTM_MutexLock *lock);
extern bool GTM_MutexLockRelease(GTM_MutexLock *lock);
extern int GTM_MutexLockInit(GTM_MutexLock *lock);
extern int GTM_MutexLockDestroy(GTM_MutexLock *lock);
-extern bool GTM_MutexLockConditionalAcquire(GTM_MutexLock *lock);
extern int GTM_CVInit(GTM_CV *cv);
-extern int GTM_CVDestroy(GTM_CV *cv);
extern int GTM_CVSignal(GTM_CV *cv);
extern int GTM_CVBcast(GTM_CV *cv);
extern int GTM_CVWait(GTM_CV *cv, GTM_MutexLock *lock);
/* SEQUENCE Management */
void GTM_InitSeqManager(void);
-int GTM_SeqOpen(GTM_SequenceKey seqkey,
- GTM_Sequence increment_by,
- GTM_Sequence minval,
- GTM_Sequence maxval,
- GTM_Sequence startval,
- bool cycle,
- GlobalTransactionId gxid);
-int GTM_SeqAlter(GTM_SequenceKey seqkey,
- GTM_Sequence increment_by,
- GTM_Sequence minval,
- GTM_Sequence maxval,
- GTM_Sequence startval,
- GTM_Sequence lastval,
- bool cycle,
- bool is_restart);
-int GTM_SeqClose(GTM_SequenceKey seqkey, GlobalTransactionId gxid);
-int GTM_SeqRename(GTM_SequenceKey seqkey, GTM_SequenceKey newseqkey,
- GlobalTransactionId gxid);
-int GTM_SeqGetNext(GTM_SequenceKey seqkey, char *coord_name,
- int coord_procid, GTM_Sequence range,
- GTM_Sequence *result, GTM_Sequence *rangemax);
-void GTM_SeqGetCurrent(GTM_SequenceKey seqkey, char *coord_name,
- int coord_procid, GTM_Sequence *result);
-int GTM_SeqSetVal(GTM_SequenceKey seqkey, char *coord_name,
- int coord_procid, GTM_Sequence nextval, bool iscalled);
-int GTM_SeqReset(GTM_SequenceKey seqkey);
+/* sequence commands in gtm/main/gtm_seq.c */
void ProcessSequenceInitCommand(Port *myport, StringInfo message, bool is_backup);
void ProcessSequenceGetCurrentCommand(Port *myport, StringInfo message);
void ProcessSequenceGetNextCommand(Port *myport, StringInfo message, bool is_backup);
#include "gtm/register.h"
#include "gtm/gtm_seq.h"
-size_t gtm_get_snapshotdata_size(GTM_SnapshotData *);
-size_t gtm_serialize_snapshotdata(GTM_SnapshotData *, char *, size_t);
-size_t gtm_deserialize_snapshotdata(GTM_SnapshotData *, const char *, size_t);
-
-size_t gtm_get_transactioninfo_size(GTM_TransactionInfo *);
-size_t gtm_serialize_transactioninfo(GTM_TransactionInfo *, char *, size_t);
-size_t gtm_deserialize_transactioninfo(GTM_TransactionInfo *, const char *, size_t);
-
size_t gtm_get_transactions_size(GTM_Transactions *);
size_t gtm_serialize_transactions(GTM_Transactions *, char *, size_t);
size_t gtm_deserialize_transactions(GTM_Transactions *, const char *, size_t);
/*
* Variables to interact with GTM active under GTM standby mode.
*/
-bool gtm_is_standby(void);
-void gtm_set_standby(bool standby);
-void gtm_set_active_conninfo(const char *addr, int port);
int gtm_standby_start_startup(void);
int gtm_standby_finish_startup(void);
GTM_Conn *gtm_standby_connect_to_standby(void);
void gtm_standby_disconnect_from_standby(GTM_Conn *conn);
-GTM_Conn *gtm_standby_reconnect_to_standby(GTM_Conn *old_conn, int retry_max);
bool gtm_standby_check_communication_error(int *retry_count, GTM_Conn *oldconn);
GTM_PGXCNodeInfo *find_standby_node_info(void);
int gtm_standby_begin_backup(void);
int gtm_standby_end_backup(void);
-void gtm_standby_closeActiveConn(void);
void gtm_standby_finishActiveConn(void);
-
-
-
/*
* Startup mode
*/
#define TRANSACTION_STATUS_ABORTED 0x02
struct GTM_RestoreContext;
-/*
- * prototypes for functions in transam/transam.c
- */
-extern bool GlobalTransactionIdDidCommit(GlobalTransactionId transactionId);
-extern bool GlobalTransactionIdDidAbort(GlobalTransactionId transactionId);
-extern void GlobalTransactionIdAbort(GlobalTransactionId transactionId);
-/* in transam/varsup.c */
+/* gtm/main/gtm_txn.c */
extern GlobalTransactionId GTM_GetGlobalTransactionId(GTM_TransactionHandle handle);
-extern bool GTM_GetGlobalTransactionIdMulti(
- GTM_TransactionHandle handle[],
- int txn_count,
- GlobalTransactionId gxids[],
- GTM_TransactionHandle new_handle[],
- int *new_txn_count);
extern GlobalTransactionId ReadNewGlobalTransactionId(void);
-extern GlobalTransactionId GTM_GetLatestCompletedXID(void);
-extern void SetGlobalTransactionIdLimit(GlobalTransactionId oldest_datfrozenxid);
extern void SetNextGlobalTransactionId(GlobalTransactionId gxid);
extern void SetControlXid(GlobalTransactionId gxid);
extern void GTM_SetShuttingDown(void);
-/* For restoration point backup */
-extern bool GTM_NeedXidRestoreUpdate(void);
+/* for restoration point backup (gtm/main/gtm_backup.c) */
extern void GTM_WriteRestorePointXid(FILE *f);
+extern void GTM_WriteRestorePointVersion(FILE *f);
+extern void GTM_RestoreStart(FILE *ctlf, struct GTM_RestoreContext *context);
+extern void GTM_SaveTxnInfo(FILE *ctlf);
+extern void GTM_RestoreTxnInfo(FILE *ctlf, GlobalTransactionId next_gxid,
+ struct GTM_RestoreContext *context, bool force_xid);
+
+/* States of the GTM component */
typedef enum GTM_States
{
GTM_STARTING,
#define GTM_MAX_SESSION_ID_LEN 64
+/* Information about a global transaction tracked by the GTM */
typedef struct GTM_TransactionInfo
{
GTM_TransactionHandle gti_handle;
gtm_List *gti_altered_seqs;
} GTM_TransactionInfo;
-#define GTM_MAX_2PC_NODES 16
/* By default a GID length is limited to 256 bits in PostgreSQL */
#define GTM_MAX_GID_LEN 256
#define GTM_MAX_NODESTRING_LEN 1024
#define GTM_CheckTransactionHandle(x) ((x) >= 0 && (x) < GTM_MAX_GLOBAL_TRANSACTIONS)
#define GTM_IsTransSerializable(x) ((x)->gti_isolevel == GTM_ISOLATION_SERIALIZABLE)
+/* Array of all global transactions tracked by the GTM */
typedef struct GTM_Transactions
{
uint32 gt_txn_count;
extern GTM_Transactions GTMTransactions;
-/* NOTE: This macro should be used with READ lock held on gt_TransArrayLock! */
-#define GTM_CountOpenTransactions() (gtm_list_length(GTMTransactions.gt_open_transactions))
-
/*
* Two hash tables will be maintained to quickly find the
* GTM_TransactionInfo block given either the GXID or the GTM_TransactionHandle.
+ *
+ * XXX seems we don't actually have the hash tables, and we simply lookup the
+ * transactions by index (handle) or by walking through open transactions and
+ * checking the GXID.
*/
GTM_TransactionInfo *GTM_HandleToTransactionInfo(GTM_TransactionHandle handle);
GTM_TransactionHandle GTM_GXIDToHandle(GlobalTransactionId gxid);
-GTM_TransactionHandle GTM_GIDToHandle(char *gid);
-bool GTM_IsGXIDInProgress(GlobalTransactionId gxid);
/* Transaction Control */
void GTM_InitTxnManager(void);
-GTM_TransactionHandle GTM_BeginTransaction(GTM_IsolationLevel isolevel,
- bool readonly,
- const char *global_sessionid);
-int GTM_BeginTransactionMulti(GTM_IsolationLevel isolevel[],
- bool readonly[],
- const char *global_sessionid[],
- GTMProxy_ConnID connid[],
- int txn_count,
- GTM_TransactionHandle txns[]);
-int GTM_RollbackTransaction(GTM_TransactionHandle txn);
-int GTM_RollbackTransactionMulti(GTM_TransactionHandle txn[], int txn_count, int status[]);
-int GTM_RollbackTransactionGXID(GlobalTransactionId gxid);
-int GTM_CommitTransaction(GTM_TransactionHandle txn,
- int waited_xid_count, GlobalTransactionId *waited_xids);
-int GTM_CommitTransactionMulti(GTM_TransactionHandle txn[], int txn_count,
- int waited_xid_count, GlobalTransactionId *waited_xids,
- int status[]);
-int GTM_CommitTransactionGXID(GlobalTransactionId gxid);
-int GTM_PrepareTransaction(GTM_TransactionHandle txn);
-int GTM_StartPreparedTransaction(GTM_TransactionHandle txn,
- char *gid,
- char *nodestring);
-int GTM_StartPreparedTransactionGXID(GlobalTransactionId gxid,
- char *gid,
- char *nodestring);
-int GTM_GetGIDData(GTM_TransactionHandle prepared_txn,
- GlobalTransactionId *prepared_gxid,
- char **nodestring);
-uint32 GTM_GetAllPrepared(GlobalTransactionId gxids[], uint32 gxidcnt);
-GTM_TransactionStates GTM_GetStatus(GTM_TransactionHandle txn);
-GTM_TransactionStates GTM_GetStatusGXID(GlobalTransactionId gxid);
-int GTM_GetAllTransactions(GTM_TransactionInfo txninfo[], uint32 txncnt);
void GTM_RemoveAllTransInfos(uint32 client_id, int backend_id);
-uint32 GTMGetFirstClientIdentifier(void);
uint32 GTMGetLastClientIdentifier(void);
-GTM_Snapshot GTM_GetSnapshotData(GTM_TransactionInfo *my_txninfo,
- GTM_Snapshot snapshot);
-GTM_Snapshot GTM_GetTransactionSnapshot(GTM_TransactionHandle handle[],
- int txn_count, int *status);
-void GTM_FreeCachedTransInfo(void);
-
+/* processing of messages in gtm_txn.c */
void ProcessBeginTransactionCommand(Port *myport, StringInfo message);
void ProcessBkupBeginTransactionCommand(Port *myport, StringInfo message);
-void GTM_BkupBeginTransactionMulti(GTM_IsolationLevel *isolevel,
- bool *readonly,
- const char **global_sessionid,
- uint32 *client_id,
- GTMProxy_ConnID *connid,
- int txn_count);
-
-void ProcessBeginTransactionCommandMulti(Port *myport, StringInfo message);
void ProcessBeginTransactionGetGXIDCommand(Port *myport, StringInfo message);
void ProcessCommitTransactionCommand(Port *myport, StringInfo message, bool is_backup);
+void ProcessCommitTransactionCommandMulti(Port *myport, StringInfo message, bool is_backup);
void ProcessCommitPreparedTransactionCommand(Port *myport, StringInfo message, bool is_backup);
void ProcessRollbackTransactionCommand(Port *myport, StringInfo message, bool is_backup);
void ProcessStartPreparedTransactionCommand(Port *myport, StringInfo message, bool is_backup);
void ProcessBkupBeginTransactionGetGXIDAutovacuumCommand(Port *myport, StringInfo message);
void ProcessBeginTransactionGetGXIDCommandMulti(Port *myport, StringInfo message);
-void ProcessCommitTransactionCommandMulti(Port *myport, StringInfo message, bool is_backup);
void ProcessRollbackTransactionCommandMulti(Port *myport, StringInfo message, bool is_backup) ;
-void GTM_WriteRestorePointVersion(FILE *f);
-void GTM_RestoreStart(FILE *ctlf, struct GTM_RestoreContext *context);
-void GTM_SaveTxnInfo(FILE *ctlf);
-void GTM_RestoreTxnInfo(FILE *ctlf, GlobalTransactionId next_gxid,
- struct GTM_RestoreContext *context, bool force_xid);
-void GTM_BkupBeginTransaction(GTM_IsolationLevel isolevel,
- bool readonly,
- const char *global_sessionid,
- uint32 client_id);
void ProcessBkupBeginTransactionGetGXIDCommand(Port *myport, StringInfo message);
void ProcessBkupBeginTransactionGetGXIDCommandMulti(Port *myport, StringInfo message);
*/
void ProcessGetSnapshotCommand(Port *myport, StringInfo message, bool get_gxid);
void ProcessGetSnapshotCommandMulti(Port *myport, StringInfo message);
-void GTM_FreeSnapshotData(GTM_Snapshot snapshot);
void GTM_RememberDroppedSequence(GlobalTransactionId gxid, void *seq);
void GTM_ForgetCreatedSequence(GlobalTransactionId gxid, void *seq);
void GTM_RememberCreatedSequence(GlobalTransactionId gxid, void *seq);
#include "gtm/libpq-int.h"
#include "gtm/gtm_msg.h"
-void gtm_util_init_nametabs(void);
char *gtm_util_message_name(GTM_MessageType type);
-char *gtm_util_result_name(GTM_ResultType type);
#endif /* GTM_UTILS_H */
char *node_name,
bool in_recovery,
int socket);
-int Recovery_PGXCNodeBackendDisconnect(GTM_PGXCNodeType type, char *nodename, int socket);
-void Recovery_RecordRegisterInfo(GTM_PGXCNodeInfo *nodeinfo, bool is_register);
void Recovery_SaveRegisterInfo(void);
void Recovery_PGXCNodeDisconnect(Port *myport);
void Recovery_SaveRegisterFileName(char *dir);