diff options
author | Michael Paquier | 2012-09-10 18:23:09 +0000 |
---|---|---|
committer | Michael Paquier | 2012-09-10 18:32:19 +0000 |
commit | cba9458319a2778a6472586fff67c7bd38f79181 (patch) | |
tree | 2e6cd836dda540e74f0caf4bffdc7c1b11e1942d | |
parent | fc85368844d8b7bb212f8b87ac22b4509bf8f97c (diff) |
Change current value of sequences to make it consistent with vanilla
In Postgres-XC (since the beginning of the project in 2009?), the current
value of sequences was taken directly from GTM. However, in vanilla postgres
this is maintained at session level, meaning that the current value of a
sequence inside a session is updated based on the cache maintained in it and
this cache is updated only each time nextval is called inside session.
This resulted in having currval being managed not at session level but at
a cluster level.
The "fix" here just consists in removing the GTM code for current value
management of sequences on GTM. By the way, it does not make sense to manage
that in a centralized way on GTM just knowing that currval is related to a
unique session between nodes.
This inconsistent behavior has been reported by Nikhil Sontakke.
I just cleaned up the code at the necessary places...
-rw-r--r-- | src/backend/access/transam/gtm.c | 34 | ||||
-rw-r--r-- | src/backend/commands/sequence.c | 18 | ||||
-rw-r--r-- | src/gtm/client/fe-protocol.c | 2 | ||||
-rw-r--r-- | src/gtm/client/gtm_client.c | 41 | ||||
-rw-r--r-- | src/gtm/common/gtm_utils.c | 2 | ||||
-rw-r--r-- | src/gtm/main/gtm_seq.c | 89 | ||||
-rw-r--r-- | src/gtm/main/main.c | 5 | ||||
-rw-r--r-- | src/gtm/proxy/proxy_main.c | 2 | ||||
-rw-r--r-- | src/include/access/gtm.h | 5 | ||||
-rw-r--r-- | src/include/gtm/gtm_client.h | 5 | ||||
-rw-r--r-- | src/include/gtm/gtm_msg.h | 2 | ||||
-rw-r--r-- | src/include/gtm/gtm_seq.h | 2 |
12 files changed, 10 insertions, 197 deletions
diff --git a/src/backend/access/transam/gtm.c b/src/backend/access/transam/gtm.c index 7e9593aa1a..c15e0425b1 100644 --- a/src/backend/access/transam/gtm.c +++ b/src/backend/access/transam/gtm.c @@ -1,8 +1,8 @@ /*------------------------------------------------------------------------- * * gtm.c - * - * Module interfacing with GTM + * + * Module interfacing with GTM * * *------------------------------------------------------------------------- @@ -123,7 +123,7 @@ BeginTranGTM(GTM_Timestamp *timestamp) if (conn) xid = begin_transaction(conn, GTM_ISOLATION_RC, timestamp); - /* If something went wrong (timeout), try and reset GTM connection + /* If something went wrong (timeout), try and reset GTM connection * and retry. This is safe at the beginning of a transaction. */ if (!TransactionIdIsValid(xid)) @@ -171,7 +171,7 @@ CommitTranGTM(GlobalTransactionId gxid) ret = commit_transaction(conn, gxid); /* - * If something went wrong (timeout), try and reset GTM connection. + * If something went wrong (timeout), try and reset GTM connection. * We will close the transaction locally anyway, and closing GTM will force * it to be closed on GTM. */ @@ -229,7 +229,7 @@ RollbackTranGTM(GlobalTransactionId gxid) ret = abort_transaction(conn, gxid); /* - * If something went wrong (timeout), try and reset GTM connection. + * If something went wrong (timeout), try and reset GTM connection. * We will abort the transaction locally anyway, and closing GTM will force * it to end on GTM. */ @@ -279,7 +279,7 @@ PrepareTranGTM(GlobalTransactionId gxid) ret = prepare_transaction(conn, gxid); /* - * If something went wrong (timeout), try and reset GTM connection. + * If something went wrong (timeout), try and reset GTM connection. * We will close the transaction locally anyway, and closing GTM will force * it to be closed on GTM. */ @@ -364,28 +364,6 @@ AlterSequenceGTM(char *seqname, GTM_Sequence increment, GTM_Sequence minval, return conn ? alter_sequence(conn, &seqkey, increment, minval, maxval, startval, lastval, cycle, is_restart) : 0; } -/* - * get the current sequence value - */ - -GTM_Sequence -GetCurrentValGTM(char *seqname) -{ - GTM_Sequence ret = -1; - GTM_SequenceKeyData seqkey; - CheckConnection(); - seqkey.gsk_keylen = strlen(seqname) + 1; - seqkey.gsk_key = seqname; - - if (conn) - ret = get_current(conn, &seqkey); - if (ret < 0) - { - CloseGTM(); - InitGTM(); - } - return ret; -} /* * Get the next sequence value diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index 90ef06b162..7e66ac99c7 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -984,25 +984,7 @@ currval_oid(PG_FUNCTION_ARGS) errmsg("currval of sequence \"%s\" is not yet defined in this session", RelationGetRelationName(seqrel)))); -#ifdef PGXC - if (IS_PGXC_COORDINATOR && - seqrel->rd_backend != MyBackendId) - { - char *seqname = GetGlobalSeqName(seqrel, NULL, NULL); - - result = (int64) GetCurrentValGTM(seqname); - if (result < 0) - ereport(ERROR, - (errcode(ERRCODE_CONNECTION_FAILURE), - errmsg("GTM error, could not obtain sequence value"))); - pfree(seqname); - } - else { -#endif result = elm->last; -#ifdef PGXC - } -#endif relation_close(seqrel, NoLock); PG_RETURN_INT64(result); diff --git a/src/gtm/client/fe-protocol.c b/src/gtm/client/fe-protocol.c index 06c492fe5d..1bd9f41243 100644 --- a/src/gtm/client/fe-protocol.c +++ b/src/gtm/client/fe-protocol.c @@ -543,7 +543,6 @@ gtmpqParseSuccess(GTM_Conn *conn, GTM_Result *result) result->gr_status = GTM_RESULT_ERROR; break; - case SEQUENCE_GET_CURRENT_RESULT: case SEQUENCE_GET_NEXT_RESULT: case SEQUENCE_GET_LAST_RESULT: if (gtmpqReadSeqKey(&result->gr_resdata.grd_seq.seqkey, conn)) @@ -808,7 +807,6 @@ gtmpqFreeResultData(GTM_Result *result, GTM_PGXCNodeType remote_type) result->gr_resdata.grd_seqkey.gsk_key = NULL; break; - case SEQUENCE_GET_CURRENT_RESULT: case SEQUENCE_GET_NEXT_RESULT: case SEQUENCE_GET_LAST_RESULT: if (result->gr_resdata.grd_seq.seqkey.gsk_key != NULL) diff --git a/src/gtm/client/gtm_client.c b/src/gtm/client/gtm_client.c index 8e5aff4ab5..1a2170d890 100644 --- a/src/gtm/client/gtm_client.c +++ b/src/gtm/client/gtm_client.c @@ -1249,47 +1249,6 @@ send_failed: return -1; } -GTM_Sequence -get_current(GTM_Conn *conn, GTM_SequenceKey key) -{ - GTM_Result *res = NULL; - time_t finish_time; - - /* Start the message. */ - if (gtmpqPutMsgStart('C', true, conn) || - gtmpqPutInt(MSG_SEQUENCE_GET_CURRENT, sizeof (GTM_MessageType), conn) || - gtmpqPutInt(key->gsk_keylen, 4, conn) || - gtmpqPutnchar(key->gsk_key, key->gsk_keylen, conn)) - goto send_failed; - - /* Finish the message. */ - if (gtmpqPutMsgEnd(conn)) - goto send_failed; - - /* Flush to ensure backend gets it. */ - if (gtmpqFlush(conn)) - goto send_failed; - - finish_time = time(NULL) + CLIENT_GTM_TIMEOUT; - if (gtmpqWaitTimed(true, false, conn, finish_time) || - gtmpqReadData(conn) < 0) - goto receive_failed; - - if ((res = GTMPQgetResult(conn)) == NULL) - goto receive_failed; - - if (res->gr_status == GTM_RESULT_OK) - return res->gr_resdata.grd_seq.seqval; - else - return InvalidSequenceValue; - -receive_failed: -send_failed: - conn->result = makeEmptyResultIfIsNull(conn->result); - conn->result->gr_status = GTM_RESULT_COMM_ERROR; - return -1; -} - int set_val(GTM_Conn *conn, GTM_SequenceKey key, GTM_Sequence nextval, bool iscalled) { diff --git a/src/gtm/common/gtm_utils.c b/src/gtm/common/gtm_utils.c index 081660ec57..ea6988640d 100644 --- a/src/gtm/common/gtm_utils.c +++ b/src/gtm/common/gtm_utils.c @@ -71,7 +71,6 @@ static struct enum_name message_name_tab[] = {MSG_SNAPSHOT_GXID_GET, "MSG_SNAPSHOT_GXID_GET"}, {MSG_SEQUENCE_INIT, "MSG_SEQUENCE_INIT"}, {MSG_BKUP_SEQUENCE_INIT, "MSG_BKUP_SEQUENCE_INIT"}, - {MSG_SEQUENCE_GET_CURRENT, "MSG_SEQUENCE_GET_CURRENT"}, {MSG_SEQUENCE_GET_NEXT, "MSG_SEQUENCE_GET_NEXT"}, {MSG_BKUP_SEQUENCE_GET_NEXT, "MSG_BKUP_SEQUENCE_GET_NEXT"}, {MSG_SEQUENCE_GET_LAST, "MSG_SEQUENCE_GET_LAST"}, @@ -125,7 +124,6 @@ static struct enum_name result_name_tab[] = {SNAPSHOT_GET_MULTI_RESULT, "SNAPSHOT_GET_MULTI_RESULT"}, {SNAPSHOT_GXID_GET_RESULT, "SNAPSHOT_GXID_GET_RESULT"}, {SEQUENCE_INIT_RESULT, "SEQUENCE_INIT_RESULT"}, - {SEQUENCE_GET_CURRENT_RESULT, "SEQUENCE_GET_CURRENT_RESULT"}, {SEQUENCE_GET_NEXT_RESULT, "SEQUENCE_GET_NEXT_RESULT"}, {SEQUENCE_GET_LAST_RESULT, "SEQUENCE_GET_LAST_RESULT"}, {SEQUENCE_SET_VAL_RESULT, "SEQUENCE_SET_VAL_RESULT"}, diff --git a/src/gtm/main/gtm_seq.c b/src/gtm/main/gtm_seq.c index d3b2f3339a..b8d999b200 100644 --- a/src/gtm/main/gtm_seq.c +++ b/src/gtm/main/gtm_seq.c @@ -648,31 +648,6 @@ GTM_SeqRename(GTM_SequenceKey seqkey, GTM_SequenceKey newseqkey) return errcode; } -/* - * Get current value for the sequence without incrementing it - */ -GTM_Sequence -GTM_SeqGetCurrent(GTM_SequenceKey seqkey) -{ - GTM_SeqInfo *seqinfo = seq_find_seqinfo(seqkey); - GTM_Sequence value; - - if (seqinfo == NULL) - { - ereport(LOG, - (EINVAL, - errmsg("The sequence with the given key does not exist"))); - return InvalidSequenceValue; - } - - GTM_RWLockAcquire(&seqinfo->gs_lock, GTM_LOCKMODE_WRITE); - - value = seqinfo->gs_last_value; - - GTM_RWLockRelease(&seqinfo->gs_lock); - seq_release_seqinfo(seqinfo); - return value; -} /* * Set values for the sequence @@ -1147,70 +1122,6 @@ ProcessSequenceListCommand(Port *myport, StringInfo message) /* - * Process MSG_SEQUENCE_GET_CURRENT message - */ -void -ProcessSequenceGetCurrentCommand(Port *myport, StringInfo message) -{ - GTM_SequenceKeyData seqkey; - StringInfoData buf; - GTM_Sequence seqval; - - seqkey.gsk_keylen = pq_getmsgint(message, sizeof (seqkey.gsk_keylen)); - seqkey.gsk_key = (char *)pq_getmsgbytes(message, seqkey.gsk_keylen); - - seqval = GTM_SeqGetCurrent(&seqkey); - if (!SEQVAL_IS_VALID(seqval)) - ereport(ERROR, - (ERANGE, - errmsg("Can not get current value of the sequence"))); - - elog(LOG, "Getting current value %ld for sequence %s", seqval, seqkey.gsk_key); - - pq_beginmessage(&buf, 'S'); - pq_sendint(&buf, SEQUENCE_GET_CURRENT_RESULT, 4); - if (myport->remote_type == GTM_NODE_GTM_PROXY) - { - GTM_ProxyMsgHeader proxyhdr; - proxyhdr.ph_conid = myport->conn_id; - pq_sendbytes(&buf, (char *)&proxyhdr, sizeof (GTM_ProxyMsgHeader)); - } - pq_sendint(&buf, seqkey.gsk_keylen, 4); - pq_sendbytes(&buf, seqkey.gsk_key, seqkey.gsk_keylen); - pq_sendbytes(&buf, (char *)&seqval, sizeof (GTM_Sequence)); - pq_endmessage(myport, &buf); - - if (myport->remote_type != GTM_NODE_GTM_PROXY) - /* Don't flush to the standby because this does not change the status */ - pq_flush(myport); - - /* - * I don't think backup is needed here. It does not change internal state. - * 27th Dec., 2011, K.Suzuki - */ -#if 0 - if (GetMyThreadInfo->thr_conn->standby) - { - GTM_Sequence loc_seq; - GTM_Conn *oldconn = GetMyThreadInfo->thr_conn->standby; - int count = 0; - - elog(LOG, "calling get_current() for standby GTM %p.", GetMyThreadInfo->thr_conn->standby); - -retry: - loc_seq = get_current(GetMyThreadInfo->thr_conn->standby, &seqkey); - - if (gtm_standby_check_communication_error(&count, oldconn)) - goto retry; - - elog(LOG, "get_current() returns GTM_Sequence %ld.", loc_seq); - } -#endif - - /* FIXME: need to check errors */ -} - -/* * Process MSG_SEQUENCE_GET_NEXT/MSG_BKUP_SEQUENCE_GET_NEXT message * * is_backup indicates the message is MSG_BKUP_SEQUENCE_GET_NEXT diff --git a/src/gtm/main/main.c b/src/gtm/main/main.c index 10d452a3ae..6e61339fac 100644 --- a/src/gtm/main/main.c +++ b/src/gtm/main/main.c @@ -1253,7 +1253,6 @@ ProcessCommand(Port *myport, StringInfo input_message) case MSG_SEQUENCE_INIT: case MSG_BKUP_SEQUENCE_INIT: - case MSG_SEQUENCE_GET_CURRENT: case MSG_SEQUENCE_GET_NEXT: case MSG_BKUP_SEQUENCE_GET_NEXT: case MSG_SEQUENCE_GET_LAST: @@ -1621,10 +1620,6 @@ ProcessSequenceCommand(Port *myport, GTM_MessageType mtype, StringInfo message) ProcessSequenceAlterCommand(myport, message, true); break; - case MSG_SEQUENCE_GET_CURRENT: - ProcessSequenceGetCurrentCommand(myport, message); - break; - case MSG_SEQUENCE_GET_NEXT: ProcessSequenceGetNextCommand(myport, message, false); break; diff --git a/src/gtm/proxy/proxy_main.c b/src/gtm/proxy/proxy_main.c index ecf883938a..826140f33e 100644 --- a/src/gtm/proxy/proxy_main.c +++ b/src/gtm/proxy/proxy_main.c @@ -1581,7 +1581,6 @@ ProcessCommand(GTMProxy_ConnectionInfo *conninfo, GTM_Conn *gtm_conn, break; case MSG_SEQUENCE_INIT: - case MSG_SEQUENCE_GET_CURRENT: case MSG_SEQUENCE_GET_NEXT: case MSG_SEQUENCE_GET_LAST: case MSG_SEQUENCE_SET_VAL: @@ -1879,7 +1878,6 @@ ProcessResponse(GTMProxy_ThreadInfo *thrinfo, GTMProxy_CommandInfo *cmdinfo, case MSG_NODE_UNREGISTER: case MSG_SNAPSHOT_GXID_GET: case MSG_SEQUENCE_INIT: - case MSG_SEQUENCE_GET_CURRENT: case MSG_SEQUENCE_GET_NEXT: case MSG_SEQUENCE_GET_LAST: case MSG_SEQUENCE_SET_VAL: diff --git a/src/include/access/gtm.h b/src/include/access/gtm.h index dc83b6d6e6..e7ad25b2cd 100644 --- a/src/include/access/gtm.h +++ b/src/include/access/gtm.h @@ -1,7 +1,7 @@ /*------------------------------------------------------------------------- * * gtm.h - * + * * Module interfacing with GTM definitions * * @@ -41,10 +41,9 @@ extern int RegisterGTM(GTM_PGXCNodeType type, GTM_PGXCNodePort port, char *dataf extern int UnregisterGTM(GTM_PGXCNodeType type); /* Sequence interface APIs with GTM */ -extern GTM_Sequence GetCurrentValGTM(char *seqname); extern GTM_Sequence GetNextValGTM(char *seqname); extern int SetValGTM(char *seqname, GTM_Sequence nextval, bool iscalled); -extern int CreateSequenceGTM(char *seqname, GTM_Sequence increment, +extern int CreateSequenceGTM(char *seqname, GTM_Sequence increment, GTM_Sequence minval, GTM_Sequence maxval, GTM_Sequence startval, bool cycle); extern int AlterSequenceGTM(char *seqname, GTM_Sequence increment, diff --git a/src/include/gtm/gtm_client.h b/src/include/gtm/gtm_client.h index 60d4a8e761..e50701a7a7 100644 --- a/src/include/gtm/gtm_client.h +++ b/src/include/gtm/gtm_client.h @@ -53,8 +53,8 @@ typedef union GTM_ResultData { GTM_SequenceKeyData seqkey; GTM_Sequence seqval; - } grd_seq; /* SEQUENCE_GET_CURRENT - * SEQUENCE_GET_NEXT */ + } grd_seq; /* SEQUENCE_GET_NEXT */ + struct { int seq_count; @@ -268,7 +268,6 @@ int close_sequence(GTM_Conn *conn, GTM_SequenceKey key); int bkup_close_sequence(GTM_Conn *conn, GTM_SequenceKey key); int rename_sequence(GTM_Conn *conn, GTM_SequenceKey key, GTM_SequenceKey newkey); int bkup_rename_sequence(GTM_Conn *conn, GTM_SequenceKey key, GTM_SequenceKey newkey); -GTM_Sequence get_current(GTM_Conn *conn, GTM_SequenceKey key); GTM_Sequence get_next(GTM_Conn *conn, GTM_SequenceKey key); GTM_Sequence bkup_get_next(GTM_Conn *conn, GTM_SequenceKey key); int set_val(GTM_Conn *conn, GTM_SequenceKey key, GTM_Sequence nextval, bool is_called); diff --git a/src/include/gtm/gtm_msg.h b/src/include/gtm/gtm_msg.h index c2054d6f1b..64f27bfeeb 100644 --- a/src/include/gtm/gtm_msg.h +++ b/src/include/gtm/gtm_msg.h @@ -62,7 +62,6 @@ typedef enum GTM_MessageType MSG_SNAPSHOT_GXID_GET, /* Get GXID and snapshot together */ MSG_SEQUENCE_INIT, /* Initialize a new global sequence */ MSG_BKUP_SEQUENCE_INIT, /* Backup of MSG_SEQUENCE_INIT */ - MSG_SEQUENCE_GET_CURRENT,/* Get the current value of sequence */ MSG_SEQUENCE_GET_NEXT, /* Get the next sequence value of sequence */ MSG_BKUP_SEQUENCE_GET_NEXT, /* Backup of MSG_SEQUENCE_GET_NEXT */ MSG_SEQUENCE_GET_LAST, /* Get the last sequence value of sequence */ @@ -123,7 +122,6 @@ typedef enum GTM_ResultType SNAPSHOT_GET_MULTI_RESULT, SNAPSHOT_GXID_GET_RESULT, SEQUENCE_INIT_RESULT, - SEQUENCE_GET_CURRENT_RESULT, SEQUENCE_GET_NEXT_RESULT, SEQUENCE_GET_LAST_RESULT, SEQUENCE_SET_VAL_RESULT, diff --git a/src/include/gtm/gtm_seq.h b/src/include/gtm/gtm_seq.h index b6fcdc61a9..af92e6d873 100644 --- a/src/include/gtm/gtm_seq.h +++ b/src/include/gtm/gtm_seq.h @@ -71,13 +71,11 @@ int GTM_SeqAlter(GTM_SequenceKey seqkey, int GTM_SeqClose(GTM_SequenceKey seqkey); int GTM_SeqRename(GTM_SequenceKey seqkey, GTM_SequenceKey newseqkey); GTM_Sequence GTM_SeqGetNext(GTM_SequenceKey seqkey); -GTM_Sequence GTM_SeqGetCurrent(GTM_SequenceKey seqkey); int GTM_SeqSetVal(GTM_SequenceKey seqkey, GTM_Sequence nextval, bool iscalled); int GTM_SeqReset(GTM_SequenceKey seqkey); void ProcessSequenceInitCommand(Port *myport, StringInfo message, bool is_backup); -void ProcessSequenceGetCurrentCommand(Port *myport, StringInfo message); void ProcessSequenceGetNextCommand(Port *myport, StringInfo message, bool is_backup); void ProcessSequenceSetValCommand(Port *myport, StringInfo message, bool is_backup); void ProcessSequenceResetCommand(Port *myport, StringInfo message, bool is_backup); |