Skip to content

Commit 99a60ea

Browse files
committed
Undo replacement of TransactionIdIsInProgress
2 parents c28682f + 26db353 commit 99a60ea

File tree

17 files changed

+102
-23
lines changed

17 files changed

+102
-23
lines changed

contrib/pg_gtm/dtmd/bin/dtmd

-21.4 KB
Binary file not shown.

contrib/pg_gtm/dtmd/src/clog.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ cid_t clog_advance(clog_t clog) {
215215
shout("failed to store the fresh gcid value\n");
216216
return INVALID_GCID;
217217
}
218+
#ifdef SYNC
218219
fsync(clog->fresh_fd);
220+
#endif
219221

220222
int oldf = GCID_TO_FILEID(old_gcid);
221223
int newf = GCID_TO_FILEID(clog->fresh_gcid);

contrib/pg_gtm/dtmd/src/clogfile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ bool clogfile_set_status(clogfile_t *clogfile, cid_t gcid, int status) {
9999
char *p = ((char*)clogfile->data + offset);
100100
*p &= ~(COMMIT_MASK << (BITS_PER_COMMIT * suboffset)); // AND-out the old status
101101
*p |= status << (BITS_PER_COMMIT * suboffset); // OR-in the new status
102+
#ifdef SYNC
102103
if (msync(clogfile->data, BYTES_PER_FILE, MS_SYNC)) {
103104
shout("cannot msync clog file '%s': %s\n", clogfile->path, strerror(errno));
104105
return false;
105106
}
107+
#endif
106108
return true;
107109
}

contrib/pg_gtm/dtmd/src/eventwrap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static void on_connect(uv_stream_t *server, int status) {
7070
free(client);
7171
return;
7272
}
73+
uv_tcp_nodelay(client, 1);
7374
onconnect_cb(&client->data);
7475
uv_read_start((uv_stream_t*)client, on_alloc, on_read);
7576
}

contrib/pg_gtm/dtmd/src/main.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define DEFAULT_LISTENHOST "0.0.0.0"
1313
#define DEFAULT_LISTENPORT 5431
1414

15-
#define MAX_PREPARES_PER_CLIENT 1024
15+
#define MAX_PREPARES_PER_CLIENT 1024*100
1616

1717
typedef struct client_data_t {
1818
int id;
@@ -83,13 +83,6 @@ static bool client_remove_prepare(void *client, cid_t gcid) {
8383
}
8484

8585
static char *onprepare(void *client, cmd_t *cmd) {
86-
if (CLIENT_PREPARES_NUM(client) >= MAX_PREPARES_PER_CLIENT) {
87-
shout(
88-
"[%d] cannot prepare any more commits\n",
89-
CLIENT_ID(client)
90-
);
91-
return strdup("-");
92-
}
9386

9487
cid_t gcid = clog_advance(clg);
9588
if (gcid == INVALID_GCID) {
@@ -101,48 +94,60 @@ static char *onprepare(void *client, cmd_t *cmd) {
10194
char buf[18];
10295
sprintf(buf, "+%016llx", gcid);
10396

97+
#ifdef VERBOSE
10498
shout(
10599
"[%d] prepare gcid %llx\n",
106100
CLIENT_ID(client), gcid
107101
);
102+
#endif
108103

109104
return strdup(buf);
110105
}
111106

112107
static char *oncommit(void *client, cmd_t *cmd) {
108+
#ifdef VERBOSE
113109
shout(
114110
"[%d] commit %016llx\n",
115111
CLIENT_ID(client),
116112
cmd->arg
117113
);
114+
#endif
115+
118116
if (clog_write(clg, cmd->arg, COMMIT_YES)) {
119117
if (client_remove_prepare(client, cmd->arg)) {
120118
return strdup("+");
121119
}
120+
#ifdef VERBOSE
122121
shout(
123122
"[%d] tried to commit an unprepared gcid %llu\n",
124123
CLIENT_ID(client),
125124
cmd->arg
126125
);
126+
#endif
127127
}
128128
return strdup("-");
129129
}
130130

131131
static char *onabort(void *client, cmd_t *cmd) {
132+
#ifdef VERBOSE
132133
shout(
133134
"[%d] abort %016llx\n",
134135
CLIENT_ID(client),
135136
cmd->arg
136137
);
138+
#endif
139+
137140
if (clog_write(clg, cmd->arg, COMMIT_NO)) {
138141
if (client_remove_prepare(client, cmd->arg)) {
139142
return strdup("+");
140143
}
144+
#ifdef VERBOSE
141145
shout(
142146
"[%d] tried to abort an unprepared gcid %016llx\n",
143147
CLIENT_ID(client),
144148
cmd->arg
145149
);
150+
#endif
146151
}
147152
return strdup("-");
148153
}

contrib/pg_gtm/libdtm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#include <unistd.h>
66
#include <stdlib.h>
77

8+
#ifdef __APPLE__
9+
#include <netinet/tcp.h>
10+
#endif
11+
812
#include "libdtm.h"
913

1014
typedef struct DTMConnData {
@@ -89,6 +93,9 @@ DTMConn DtmConnect(char *host, int port) {
8993
continue;
9094
}
9195

96+
int one = 1;
97+
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
98+
9299
if (connect(sock, a->ai_addr, a->ai_addrlen) == -1) {
93100
perror("failed to connect to an address");
94101
close(sock);

contrib/pg_gtm/libdtm/Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
CC=clang
22
CFLAGS=-g -Wall -I"../../../src/include"
33

4+
all: lib/libdtm.a bin/example bin/perf
45

5-
all: lib/libdtm.a bin/example
6+
bin/perf: bindir lib/libdtm.a src/perf.c
7+
$(CC) $(CFLAGS) -o bin/perf -Iinclude -Llib src/perf.c -ldtm
68

79
bin/example: bindir lib/libdtm.a src/example.c
810
$(CC) $(CFLAGS) -o bin/example -Iinclude -Llib src/example.c -ldtm
911

10-
lib/libdtm.a: libdir obj/dtm.o
11-
ar rcs lib/libdtm.a obj/dtm.o
12+
lib/libdtm.a: libdir obj/libdtm.o
13+
ar rcs lib/libdtm.a obj/libdtm.o
1214

13-
obj/dtm.o: objdir src/dtm.c
14-
$(CC) $(CFLAGS) -c -o obj/dtm.o -Iinclude src/dtm.c
15+
obj/libdtm.o: objdir src/libdtm.c
16+
$(CC) $(CFLAGS) -c -o obj/libdtm.o -Iinclude src/libdtm.c
1517

1618
libdir:
1719
mkdir -p lib

contrib/pg_gtm/libdtm/src/libdtm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../libdtm.c

contrib/pg_gtm/libdtm/src/libdtm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../libdtm.h

contrib/pg_gtm/libdtm/src/perf.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
#include "../../libdtm.h"
5+
6+
int main() {
7+
cid_t gcid;
8+
cid_t horizon;
9+
DTMConn conn;
10+
int i;
11+
12+
conn = DtmConnect("localhost", 5431);
13+
if (!conn) {
14+
fprintf(stderr, "failed to connect to dtmd\n");
15+
exit(1);
16+
}
17+
18+
19+
for (i=0; i<10000; i++) {
20+
horizon = DtmGlobalGetNextCid(conn);
21+
22+
gcid = DtmGlobalPrepare(conn);
23+
if (gcid == INVALID_GCID) {
24+
fprintf(stderr, "failed to prepare a commit\n");
25+
}
26+
27+
if (!DtmGlobalCommit(conn, gcid)) {
28+
fprintf(stderr, "failed to commit gcid = %llu\n", gcid);
29+
}
30+
31+
if (i%100 == 0){
32+
printf("Completed %u txs\n", i);
33+
}
34+
}
35+
36+
37+
DtmDisconnect(conn);
38+
39+
return 0;
40+
}
41+

contrib/pg_gtm/pg_dtm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ typedef struct
7171
TransactionId xid;
7272
} DtmTransId;
7373

74-
//#define DTM_TRACE(x)
74+
// #define DTM_TRACE(x)
7575
#define DTM_TRACE(x) elog x
7676

7777
static shmem_startup_hook_type prev_shmem_startup_hook;

contrib/pg_gtm/tests/transfers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
const (
1212
TRANSFER_CONNECTIONS = 4
1313
INIT_AMOUNT = 10000
14-
N_ITERATIONS = 10000
14+
N_ITERATIONS = 1000
1515
N_ACCOUNTS = 1//100000
1616
)
1717

contrib/pg_xtm/dtmd/src/clogfile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ bool clogfile_set_status(clogfile_t *clogfile, xid_t xid, int status) {
100100
char *p = ((char*)clogfile->data + offset);
101101
*p &= ~(COMMIT_MASK << (BITS_PER_COMMIT * suboffset)); // AND-out the old status
102102
*p |= status << (BITS_PER_COMMIT * suboffset); // OR-in the new status
103+
#ifdef SYNC
103104
if (msync(clogfile->data, BYTES_PER_FILE, MS_SYNC)) {
104105
shout("cannot msync clog file '%s': %s\n", clogfile->path, strerror(errno));
105106
return false;
106107
}
108+
#endif
107109
return true;
108110
}

contrib/pg_xtm/dtmd/src/eventwrap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static void on_connect(uv_stream_t *server, int status) {
7070
free(client);
7171
return;
7272
}
73+
uv_tcp_nodelay(client, 1);
7374
onconnect_cb(&client->data);
7475
uv_read_start((uv_stream_t*)client, on_alloc, on_read);
7576
}

contrib/pg_xtm/libdtm.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <sys/socket.h>
2+
#include <netinet/tcp.h>
23
#include <netdb.h>
34
#include <string.h>
45
#include <stdio.h>
@@ -96,6 +97,11 @@ DTMConn DtmConnect(char *host, int port) {
9697
continue;
9798
}
9899

100+
#ifdef NODELAY
101+
int one = 1;
102+
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
103+
#endif
104+
99105
if (connect(sock, a->ai_addr, a->ai_addrlen) == -1) {
100106
perror("failed to connect to an address");
101107
close(sock);
@@ -161,10 +167,15 @@ bool DtmGlobalStartTransaction(DTMConn dtm, GlobalTransactionId *gtid) {
161167
return ok;
162168
}
163169

164-
void DtmInitSnapshot(Snapshot snapshot)
170+
void DtmInitSnapshot(Snapshot snapshot)
165171
{
166-
if (snapshot->xip == NULL)
167-
{
172+
#ifdef TEST
173+
if (snapshot->xip == NULL) {
174+
snapshot->xip = malloc(snapshot->xcnt * sizeof(TransactionId));
175+
// FIXME: is this enough for tests?
176+
}
177+
#else
178+
if (snapshot->xip == NULL) {
168179
/*
169180
* First call for this snapshot. Snapshot is same size whether or not
170181
* we are in recovery, see later comments.
@@ -183,6 +194,7 @@ void DtmInitSnapshot(Snapshot snapshot)
183194
(errcode(ERRCODE_OUT_OF_MEMORY),
184195
errmsg("out of memory")));
185196
}
197+
#endif
186198
}
187199

188200
// Asks DTM for a fresh snapshot. Returns 'true' on success, or 'false'
@@ -214,6 +226,7 @@ bool DtmGlobalGetSnapshot(DTMConn dtm, NodeId nodeid, TransactionId xid, Snapsho
214226
Assert(s->xcnt == number); // the number should definitely fit into xcnt field size
215227

216228
DtmInitSnapshot(s);
229+
217230
for (i = 0; i < s->xcnt; i++) {
218231
if (!dtm_read_hex16(dtm, &number)) return false;
219232
s->xip[i] = number;

contrib/pg_xtm/libdtm/Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
CC=clang -DTEST
2-
CFLAGS=-g -Wall -I"../../../src/include"
3-
1+
CC=clang -DTEST -DNODELAY
2+
CFLAGS=-g -Wall -I"../../../src/include"
43

54
all: lib/libdtm.a bin/example bin/bench bin/redbench
65

install.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rm -rf install
77

88
make install
99

10-
cd contrib/pg_xtm/
10+
cd contrib/pg_gtm/
1111

1212
make clean
1313
make
@@ -20,13 +20,15 @@ cd ../..
2020

2121
sed -i '' 's/#port =.*/port = 5433/' ./install/data2/postgresql.conf
2222

23+
sed -i '' 's/#fsync =.*/fsync = off/' ./install/data1/postgresql.conf
24+
sed -i' ' 's/#fsync =.*/fsync = off/' ./install/data2/postgresql.conf
2325

2426

2527
./install/bin/pg_ctl -D ./install/data1 -l ./install/data1/log start
2628
./install/bin/pg_ctl -D ./install/data2 -l ./install/data2/log start
2729

2830

29-
cd contrib/pg_dtm/dtmd
31+
cd contrib/pg_gtm/dtmd
3032
make clean
3133
make
3234
./bin/dtmd

0 commit comments

Comments
 (0)