diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gtm/client/gtm_client.c | 6 | ||||
-rw-r--r-- | src/gtm/common/gtm_lock.c | 79 | ||||
-rw-r--r-- | src/gtm/common/gtm_serialize.c | 12 | ||||
-rw-r--r-- | src/gtm/common/gtm_utils.c | 10 | ||||
-rw-r--r-- | src/gtm/main/gtm_seq.c | 31 | ||||
-rw-r--r-- | src/gtm/main/gtm_snap.c | 19 | ||||
-rw-r--r-- | src/gtm/main/gtm_standby.c | 2 | ||||
-rw-r--r-- | src/gtm/main/gtm_thread.c | 57 | ||||
-rw-r--r-- | src/gtm/main/gtm_txn.c | 184 | ||||
-rw-r--r-- | src/gtm/recovery/register_common.c | 7 | ||||
-rw-r--r-- | src/include/gtm/gtm.h | 17 | ||||
-rw-r--r-- | src/include/gtm/gtm_backup.h | 1 | ||||
-rw-r--r-- | src/include/gtm/gtm_client.h | 1 | ||||
-rw-r--r-- | src/include/gtm/gtm_gxid.h | 10 | ||||
-rw-r--r-- | src/include/gtm/gtm_lock.h | 3 | ||||
-rw-r--r-- | src/include/gtm/gtm_seq.h | 27 | ||||
-rw-r--r-- | src/include/gtm/gtm_serialize.h | 8 | ||||
-rw-r--r-- | src/include/gtm/gtm_standby.h | 8 | ||||
-rw-r--r-- | src/include/gtm/gtm_txn.h | 98 | ||||
-rw-r--r-- | src/include/gtm/gtm_utils.h | 2 | ||||
-rw-r--r-- | src/include/gtm/register.h | 2 |
21 files changed, 68 insertions, 516 deletions
diff --git a/src/gtm/client/gtm_client.c b/src/gtm/client/gtm_client.c index ce9845e975..a9e0c6f911 100644 --- a/src/gtm/client/gtm_client.c +++ b/src/gtm/client/gtm_client.c @@ -110,12 +110,6 @@ connect_gtm(const char *connect_string) 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 diff --git a/src/gtm/common/gtm_lock.c b/src/gtm/common/gtm_lock.c index 53ccd0a463..d46b338fa7 100644 --- a/src/gtm/common/gtm_lock.c +++ b/src/gtm/common/gtm_lock.c @@ -204,63 +204,6 @@ GTM_RWLockDestroy(GTM_RWLock *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 */ int @@ -300,19 +243,6 @@ GTM_MutexLockRelease(GTM_MutexLock *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 */ int @@ -322,15 +252,6 @@ GTM_CVInit(GTM_CV *cv) } /* - * 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 */ int diff --git a/src/gtm/common/gtm_serialize.c b/src/gtm/common/gtm_serialize.c index d28535aeeb..4ff5ad72ec 100644 --- a/src/gtm/common/gtm_serialize.c +++ b/src/gtm/common/gtm_serialize.c @@ -43,7 +43,7 @@ * ---> sn_xcnt ---> GXID * sn_xcnt * |<--- sn_xip -->| */ -size_t +static size_t gtm_get_snapshotdata_size(GTM_SnapshotData *data) { size_t len = 0; @@ -63,7 +63,7 @@ gtm_get_snapshotdata_size(GTM_SnapshotData *data) * 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; @@ -109,7 +109,7 @@ gtm_serialize_snapshotdata(GTM_SnapshotData *data, char *buf, size_t buflen) * 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; @@ -153,7 +153,7 @@ gtm_deserialize_snapshotdata(GTM_SnapshotData *data, const char *buf, size_t buf * 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; @@ -191,7 +191,7 @@ gtm_get_transactioninfo_size(GTM_TransactionInfo *data) * Serialize a GTM_TransactionInfo structure * ----------------------------------------------------- */ -size_t +static size_t gtm_serialize_transactioninfo(GTM_TransactionInfo *data, char *buf, size_t buflen) { int len = 0; @@ -304,7 +304,7 @@ gtm_serialize_transactioninfo(GTM_TransactionInfo *data, char *buf, size_t bufle * 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; diff --git a/src/gtm/common/gtm_utils.c b/src/gtm/common/gtm_utils.c index 6e72ecc0db..12e9b024f1 100644 --- a/src/gtm/common/gtm_utils.c +++ b/src/gtm/common/gtm_utils.c @@ -149,6 +149,7 @@ static int message_max; static char **result_name = NULL; static int result_max; +static void gtm_util_init_nametabs(void) { int ii; @@ -190,12 +191,3 @@ char *gtm_util_message_name(GTM_MessageType type) 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]; -} diff --git a/src/gtm/main/gtm_seq.c b/src/gtm/main/gtm_seq.c index 5ff1ee0fdd..47cf7559f1 100644 --- a/src/gtm/main/gtm_seq.c +++ b/src/gtm/main/gtm_seq.c @@ -358,7 +358,7 @@ seq_copy_key(GTM_SequenceKey key) /* * 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, @@ -478,14 +478,15 @@ GTM_SeqOpen(GTM_SequenceKey seqkey, * 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); @@ -585,7 +586,7 @@ GTM_SeqRestore(GTM_SequenceKey seqkey, /* * Destroy the given sequence depending on type of given key */ -int +static int GTM_SeqClose(GTM_SequenceKey seqkey, GlobalTransactionId gxid) { int res; @@ -753,7 +754,7 @@ seq_drop_with_dbkey(GTM_SequenceKey nsp) /* * Rename an existing sequence with a new name */ -int +static int GTM_SeqRename(GTM_SequenceKey seqkey, GTM_SequenceKey newseqkey, GlobalTransactionId gxid) { @@ -788,7 +789,7 @@ GTM_SeqRename(GTM_SequenceKey seqkey, GTM_SequenceKey newseqkey, /* * 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) { @@ -899,7 +900,7 @@ seq_set_lastval(GTM_SeqInfo *seqinfo, char *coord_name, /* * Set values for the sequence */ -int +static int GTM_SeqSetVal(GTM_SequenceKey seqkey, char *coord_name, int coord_procid, GTM_Sequence nextval, bool iscalled) { @@ -933,7 +934,7 @@ GTM_SeqSetVal(GTM_SequenceKey seqkey, char *coord_name, /* * 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) @@ -1089,7 +1090,7 @@ get_rangemax(GTM_SeqInfo *seqinfo, GTM_Sequence range) /* * Reset the sequence */ -int +static int GTM_SeqReset(GTM_SequenceKey seqkey) { GTM_SeqInfo *seqinfo = seq_find_seqinfo(seqkey); diff --git a/src/gtm/main/gtm_snap.c b/src/gtm/main/gtm_snap.c index f8e3d31976..a331ed4189 100644 --- a/src/gtm/main/gtm_snap.c +++ b/src/gtm/main/gtm_snap.c @@ -49,7 +49,7 @@ * 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; @@ -449,20 +449,3 @@ retry: 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; - } -} diff --git a/src/gtm/main/gtm_standby.c b/src/gtm/main/gtm_standby.c index 5c8a6a4979..5ae1da0c28 100644 --- a/src/gtm/main/gtm_standby.c +++ b/src/gtm/main/gtm_standby.c @@ -416,7 +416,7 @@ gtm_standby_disconnect_from_standby(GTM_Conn *conn) } -GTM_Conn * +static GTM_Conn * gtm_standby_reconnect_to_standby(GTM_Conn *old_conn, int retry_max) { GTM_Conn *newconn = NULL; diff --git a/src/gtm/main/gtm_thread.c b/src/gtm/main/gtm_thread.c index 9d166f4a0e..462a2a8517 100644 --- a/src/gtm/main/gtm_thread.c +++ b/src/gtm/main/gtm_thread.c @@ -299,37 +299,6 @@ GTM_ThreadCreate(GTM_ConnectionInfo *conninfo, } /* - * 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 */ static void @@ -441,32 +410,6 @@ GTM_ThreadMainWrapper(void *argp) } 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 *)) { GTM_ThreadInfo *my_threadinfo = GetMyThreadInfo; diff --git a/src/gtm/main/gtm_txn.c b/src/gtm/main/gtm_txn.c index 706b9bc256..1fde21aff8 100644 --- a/src/gtm/main/gtm_txn.c +++ b/src/gtm/main/gtm_txn.c @@ -35,7 +35,6 @@ extern bool Backup_synchronously; #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, @@ -47,6 +46,9 @@ static void init_GTM_TransactionInfo(GTM_TransactionInfo *gtm_txninfo, 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; @@ -118,33 +120,6 @@ GTM_InitTxnManager(void) 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. @@ -210,7 +185,7 @@ GTM_GlobalSessionIDToHandle(const char *global_sessionid) return InvalidTransactionHandle; } -bool +static bool GTM_IsGXIDInProgress(GlobalTransactionId gxid) { return (GTM_GXIDToHandle_Internal(gxid, false) != @@ -220,7 +195,7 @@ GTM_IsGXIDInProgress(GlobalTransactionId gxid) * 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; @@ -424,59 +399,6 @@ GTMGetLastClientIdentifier(void) } /* - * 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 * */ @@ -498,7 +420,7 @@ GTM_SetDoVacuum(GTM_TransactionHandle handle) * 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) @@ -668,7 +590,7 @@ SetControlXid(GlobalTransactionId gxid) } /* Transaction Control */ -int +static int GTM_BeginTransactionMulti(GTM_IsolationLevel isolevel[], bool readonly[], const char *global_sessionid[], @@ -762,7 +684,7 @@ GTM_BeginTransactionMulti(GTM_IsolationLevel isolevel[], } /* Transaction Control */ -GTM_TransactionHandle +static GTM_TransactionHandle GTM_BeginTransaction(GTM_IsolationLevel isolevel, bool readonly, const char *global_sessionid) @@ -912,7 +834,7 @@ clean_GTM_TransactionInfo(GTM_TransactionInfo *gtm_txninfo) } -void +static void GTM_BkupBeginTransactionMulti(GTM_IsolationLevel *isolevel, bool *readonly, const char **global_sessionid, @@ -937,7 +859,7 @@ GTM_BkupBeginTransactionMulti(GTM_IsolationLevel *isolevel, MemoryContextSwitchTo(oldContext); } -void +static void GTM_BkupBeginTransaction(GTM_IsolationLevel isolevel, bool readonly, const char *global_sessionid, @@ -949,20 +871,11 @@ GTM_BkupBeginTransaction(GTM_IsolationLevel isolevel, &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]; @@ -995,7 +908,7 @@ GTM_RollbackTransactionMulti(GTM_TransactionHandle txn[], int txn_count, int sta /* * Rollback a transaction */ -int +static int GTM_RollbackTransaction(GTM_TransactionHandle txn) { int status; @@ -1003,21 +916,10 @@ GTM_RollbackTransaction(GTM_TransactionHandle txn) 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[]) @@ -1080,7 +982,7 @@ GTM_CommitTransactionMulti(GTM_TransactionHandle txn[], int txn_count, /* * Prepare a transaction */ -int +static int GTM_PrepareTransaction(GTM_TransactionHandle txn) { GTM_TransactionInfo *gtm_txninfo = NULL; @@ -1103,7 +1005,7 @@ GTM_PrepareTransaction(GTM_TransactionHandle txn) /* * Commit a transaction */ -int +static int GTM_CommitTransaction(GTM_TransactionHandle txn, int waited_xid_count, GlobalTransactionId *waited_xids) { @@ -1115,7 +1017,7 @@ GTM_CommitTransaction(GTM_TransactionHandle txn, int waited_xid_count, /* * Prepare a transaction */ -int +static int GTM_StartPreparedTransaction(GTM_TransactionHandle txn, char *gid, char *nodestring) @@ -1158,19 +1060,7 @@ GTM_StartPreparedTransaction(GTM_TransactionHandle txn, 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) @@ -1201,26 +1091,6 @@ GTM_GetGIDData(GTM_TransactionHandle prepared_txn, } /* - * 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 */ void @@ -2814,18 +2684,12 @@ GTM_SetShuttingDown(void) 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) { @@ -2890,15 +2754,3 @@ GTM_RememberAlteredSequence(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); - diff --git a/src/gtm/recovery/register_common.c b/src/gtm/recovery/register_common.c index 4e999bd002..ff0f960e33 100644 --- a/src/gtm/recovery/register_common.c +++ b/src/gtm/recovery/register_common.c @@ -68,6 +68,9 @@ static int pgxcnode_remove_info(GTM_PGXCNodeInfo *node); 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) @@ -582,7 +585,7 @@ Recovery_SaveRegisterInfo(void) /* * 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; @@ -726,7 +729,7 @@ Recovery_PGXCNodeDisconnect(Port *myport) MemoryContextSwitchTo(oldContext); } -int +static int Recovery_PGXCNodeBackendDisconnect(GTM_PGXCNodeType type, char *nodename, int socket) { GTM_PGXCNodeInfo *nodeinfo = pgxcnode_find_info(type, nodename); diff --git a/src/include/gtm/gtm.h b/src/include/gtm/gtm.h index 7b494fb6a2..f069477736 100644 --- a/src/include/gtm/gtm.h +++ b/src/include/gtm/gtm.h @@ -87,22 +87,17 @@ typedef struct GTM_RestoreContext { 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 @@ -138,14 +133,6 @@ extern GTM_ThreadID TopMostThreadID; #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) \ diff --git a/src/include/gtm/gtm_backup.h b/src/include/gtm/gtm_backup.h index 4e6893344a..c8135ea5e2 100644 --- a/src/include/gtm/gtm_backup.h +++ b/src/include/gtm/gtm_backup.h @@ -23,7 +23,6 @@ extern GTM_RWLock gtm_bkup_lock; #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); diff --git a/src/include/gtm/gtm_client.h b/src/include/gtm/gtm_client.h index 021bf512b2..744118f236 100644 --- a/src/include/gtm/gtm_client.h +++ b/src/include/gtm/gtm_client.h @@ -167,7 +167,6 @@ typedef struct GTM_Result * 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 *); diff --git a/src/include/gtm/gtm_gxid.h b/src/include/gtm/gtm_gxid.h index 7fe3cf732c..4afa05b38c 100644 --- a/src/include/gtm/gtm_gxid.h +++ b/src/include/gtm/gtm_gxid.h @@ -12,8 +12,6 @@ * 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) @@ -23,8 +21,6 @@ */ #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) \ @@ -34,12 +30,6 @@ (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); diff --git a/src/include/gtm/gtm_lock.h b/src/include/gtm/gtm_lock.h index 26e8faee49..94e9908346 100644 --- a/src/include/gtm/gtm_lock.h +++ b/src/include/gtm/gtm_lock.h @@ -55,16 +55,13 @@ extern bool GTM_RWLockAcquire(GTM_RWLock *lock, GTM_LockMode mode); 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); diff --git a/src/include/gtm/gtm_seq.h b/src/include/gtm/gtm_seq.h index e619d6964c..6b34fba573 100644 --- a/src/include/gtm/gtm_seq.h +++ b/src/include/gtm/gtm_seq.h @@ -67,33 +67,8 @@ typedef struct GTM_SeqInfo /* 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); diff --git a/src/include/gtm/gtm_serialize.h b/src/include/gtm/gtm_serialize.h index 4f8cecdf5c..4f09db18a7 100644 --- a/src/include/gtm/gtm_serialize.h +++ b/src/include/gtm/gtm_serialize.h @@ -22,14 +22,6 @@ #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); diff --git a/src/include/gtm/gtm_standby.h b/src/include/gtm/gtm_standby.h index e9fa57f6bf..57a55fa6af 100644 --- a/src/include/gtm/gtm_standby.h +++ b/src/include/gtm/gtm_standby.h @@ -23,9 +23,6 @@ /* * 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); @@ -40,20 +37,15 @@ int gtm_standby_activate_self(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 */ diff --git a/src/include/gtm/gtm_txn.h b/src/include/gtm/gtm_txn.h index f175062b00..c8b1fdc855 100644 --- a/src/include/gtm/gtm_txn.h +++ b/src/include/gtm/gtm_txn.h @@ -29,32 +29,24 @@ typedef int XidStatus; #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, @@ -77,6 +69,7 @@ typedef enum GTM_TransactionStates #define GTM_MAX_SESSION_ID_LEN 64 +/* Information about a global transaction tracked by the GTM */ typedef struct GTM_TransactionInfo { GTM_TransactionHandle gti_handle; @@ -102,13 +95,13 @@ typedef struct GTM_TransactionInfo 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; @@ -145,75 +138,29 @@ typedef struct GTM_Transactions 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); @@ -228,18 +175,8 @@ void ProcessBeginTransactionGetGXIDAutovacuumCommand(Port *myport, StringInfo me 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); @@ -249,7 +186,6 @@ void ProcessBkupBeginTransactionGetGXIDCommandMulti(Port *myport, StringInfo mes */ 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); diff --git a/src/include/gtm/gtm_utils.h b/src/include/gtm/gtm_utils.h index c40f4c912d..4d50f3e82d 100644 --- a/src/include/gtm/gtm_utils.h +++ b/src/include/gtm/gtm_utils.h @@ -17,8 +17,6 @@ #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 */ diff --git a/src/include/gtm/register.h b/src/include/gtm/register.h index 332a4c89dd..661a286c57 100644 --- a/src/include/gtm/register.h +++ b/src/include/gtm/register.h @@ -98,9 +98,7 @@ int Recovery_PGXCNodeUnregister(GTM_PGXCNodeType type, 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); |