Skip to content

Commit 704539f

Browse files
committed
Add host and port parameters to libdtm and backend. Implement multiple connections and run-time parameters in 'transfers' test.
1 parent aaec649 commit 704539f

File tree

8 files changed

+309
-161
lines changed

8 files changed

+309
-161
lines changed

contrib/pg_dtm/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ dtm_get_snapshot() RETURNS void
3636
libdtm api
3737
----------
3838

39+
// Sets up the host and port for DTM connection.
40+
// The defaults are "127.0.0.1" and 5431.
41+
void TuneToDtm(char *host, int port);
42+
3943
void DtmInitSnapshot(Snapshot snapshot);
4044

4145
// Starts a new global transaction of nParticipants size. Returns the

contrib/pg_dtm/libdtm.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,20 @@ static bool dtm_query(DTMConn dtm, char cmd, int argc, ...)
235235
return true;
236236
}
237237

238+
static char *dtmhost = "127.0.0.1";
239+
static int dtmport = 5431;
240+
241+
void TuneToDtm(char *host, int port) {
242+
dtmhost = host;
243+
dtmport = port;
244+
}
245+
238246
static DTMConn GetConnection()
239247
{
240248
static DTMConn dtm = NULL;
241249
if (dtm == NULL)
242250
{
243-
// FIXME: add API for setting the host and port for dtm connection
244-
dtm = DtmConnect(DtmdHost, DtmdPort);
251+
dtm = DtmConnect(dtmhost, dtmport);
245252
if (dtm == NULL) {
246253
elog(ERROR, "Failed to connect to DTMD");
247254
}

contrib/pg_dtm/libdtm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
#define INVALID_XID 0
1010

11-
extern int DtmdPort;
12-
extern char* DtmdHost;
11+
// Sets up the host and port for DTM connection.
12+
// The defaults are "127.0.0.1" and 5431.
13+
void TuneToDtm(char *host, int port);
1314

1415
void DtmInitSnapshot(Snapshot snapshot);
1516

contrib/pg_dtm/pg_dtm.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ static int DtmCurcid;
8989
static Snapshot DtmLastSnapshot;
9090
static TransactionManager DtmTM = { DtmGetTransactionStatus, DtmSetTransactionStatus, DtmGetSnapshot, DtmGetNewTransactionId, DtmGetOldestXmin, PgTransactionIdIsInProgress, DtmGetGlobalTransactionId, PgXidInMVCCSnapshot };
9191

92+
static char *DtmHost;
93+
static int DtmPort;
94+
9295

9396
#define XTM_TRACE(fmt, ...)
9497
//#define XTM_INFO(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
@@ -713,11 +716,24 @@ _PG_init(void)
713716
NULL
714717
);
715718

719+
DefineCustomStringVariable(
720+
"dtm.host",
721+
"The host where DTM daemon resides",
722+
NULL,
723+
&DtmHost,
724+
"127.0.0.1",
725+
PGC_BACKEND, // context
726+
0, // flags,
727+
NULL, // GucStringCheckHook check_hook,
728+
NULL, // GucStringAssignHook assign_hook,
729+
NULL // GucShowHook show_hook
730+
);
731+
716732
DefineCustomIntVariable(
717-
"dtm.dtmd_port",
718-
"DTMD port",
733+
"dtm.port",
734+
"The port DTM daemon is listening",
719735
NULL,
720-
&DtmdPort,
736+
&DtmPort,
721737
5431,
722738
1,
723739
INT_MAX,
@@ -728,17 +744,7 @@ _PG_init(void)
728744
NULL
729745
);
730746

731-
DefineCustomStringVariable(
732-
"dtm.dtmd_host",
733-
"DTMD host name",
734-
NULL,
735-
&DtmdHost,
736-
"localhost",
737-
PGC_BACKEND,
738-
0,
739-
NULL,
740-
NULL,
741-
NULL);
747+
TuneToDtm(DtmHost, DtmPort);
742748

743749
/*
744750
* Install hooks.

contrib/pg_dtm/tests/daemons.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ func postgres(bin string, datadir string, port int, nodeid int, wg *sync.WaitGro
9292
"-D", datadir,
9393
"-p", strconv.Itoa(port),
9494
"-c", "dtm.node_id=" + strconv.Itoa(nodeid),
95+
"-c", "dtm.host=127.0.0.2",
96+
"-c", "dtm.port=" + strconv.Itoa(5431),
9597
"-c", "autovacuum=off",
9698
"-c", "fsync=off",
9799
"-c", "synchronous_commit=off",
@@ -146,7 +148,7 @@ func main() {
146148
"postgres": prefix + "/bin/postgres",
147149
}
148150

149-
datadirs := []string{"/tmp/data1", "/tmp/data2"}
151+
datadirs := []string{"/tmp/data1", "/tmp/data2", "/tmp/data3"}
150152

151153
check_bin(&bin);
152154

0 commit comments

Comments
 (0)