Merge pull request #1022 from citusdata/feature/2PCBUMPISM

Make prepared transactions available if not configured.
pull/1025/merge
Andres Freund 2016-12-08 20:04:00 -08:00 committed by GitHub
commit 4bea1f621a
2 changed files with 38 additions and 1 deletions

View File

@ -17,11 +17,13 @@
#include "miscadmin.h"
#include "access/twophase.h"
#include "access/xact.h"
#include "distributed/connection_management.h"
#include "distributed/hash_helpers.h"
#include "distributed/transaction_management.h"
#include "utils/hsearch.h"
#include "utils/guc.h"
CoordinatedTransactionState CurrentCoordinatedTransactionState = COORD_TRANS_NONE;
@ -41,6 +43,9 @@ static void CoordinatedTransactionCallback(XactEvent event, void *arg);
static void CoordinatedSubTransactionCallback(SubXactEvent event, SubTransactionId subId,
SubTransactionId parentSubid, void *arg);
/* remaining functions */
static void AdjustMaxPreparedTransactions(void);
void
InitializeTransactionManagement(void)
@ -48,6 +53,8 @@ InitializeTransactionManagement(void)
/* hook into transaction machinery */
RegisterXactCallback(CoordinatedTransactionCallback, NULL);
RegisterSubXactCallback(CoordinatedSubTransactionCallback, NULL);
AdjustMaxPreparedTransactions();
}
@ -142,3 +149,34 @@ CoordinatedSubTransactionCallback(SubXactEvent event, SubTransactionId subId,
subXactAbortAttempted = true;
}
}
/*
* AdjustMaxPreparedTransactions configures the number of available prepared
* transaction slots at startup.
*/
static void
AdjustMaxPreparedTransactions(void)
{
/*
* As Citus uses 2PC internally, there always should be some available. As
* the default is 0, we increase it to something appropriate
* (connections * 2 currently). If the user explicitly configured 2PC, we
* leave the configuration alone - there might have been intent behind the
* decision.
*/
if (max_prepared_xacts == 0)
{
char newvalue[12];
snprintf(newvalue, sizeof(newvalue), "%d", MaxConnections * 2);
SetConfigOption("max_prepared_transactions", newvalue, PGC_POSTMASTER,
PGC_S_OVERRIDE);
ereport(LOG, (errmsg("number of prepared transactions has not been "
"configured, overriding"),
errdetail("max_prepared_transactions is now set to %s",
newvalue)));
}
}

View File

@ -129,7 +129,6 @@ push(@pgOptions, '-c', "listen_addresses='${host}'");
push(@pgOptions, '-c', "unix_socket_directories=");
push(@pgOptions, '-c', "fsync=off");
push(@pgOptions, '-c', "shared_preload_libraries=citus");
push(@pgOptions, '-c', "max_prepared_transactions=100");
# Citus options set for the tests
push(@pgOptions, '-c', "citus.shard_max_size=300kB");