Skip to content

Commit 776e0cb

Browse files
committed
Disable fsync in DTMD. Use TCP_NODELAY in libdtm. Do not use postgres parts in tests of libdtm.
1 parent c25adce commit 776e0cb

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

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 & 5 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,14 @@ bool DtmGlobalStartTransaction(DTMConn dtm, GlobalTransactionId *gtid) {
161167
return ok;
162168
}
163169

164-
void DtmInitSnapshot(Snapshot snapshot)
165-
{
166-
if (snapshot->xip == NULL)
167-
{
170+
void DtmInitSnapshot(Snapshot snapshot, int nactive) {
171+
#ifdef TEST
172+
if (snapshot->xip == NULL) {
173+
snapshot->xip = malloc(nactive * sizeof(TransactionId));
174+
// FIXME: is this enough for tests?
175+
}
176+
#else
177+
if (snapshot->xip == NULL) {
168178
/*
169179
* First call for this snapshot. Snapshot is same size whether or not
170180
* we are in recovery, see later comments.
@@ -183,6 +193,7 @@ void DtmInitSnapshot(Snapshot snapshot)
183193
(errcode(ERRCODE_OUT_OF_MEMORY),
184194
errmsg("out of memory")));
185195
}
196+
#endif
186197
}
187198

188199
// Asks DTM for a fresh snapshot. Returns 'true' on success, or 'false'
@@ -213,7 +224,7 @@ bool DtmGlobalGetSnapshot(DTMConn dtm, NodeId nodeid, TransactionId xid, Snapsho
213224
s->xcnt = number;
214225
Assert(s->xcnt == number); // the number should definitely fit into xcnt field size
215226

216-
DtmInitSnapshot(s);
227+
DtmInitSnapshot(s, s->xcnt);
217228
for (i = 0; i < s->xcnt; i++) {
218229
if (!dtm_read_hex16(dtm, &number)) return false;
219230
s->xip[i] = number;

contrib/pg_xtm/libdtm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ DTMConn DtmConnect(char *host, int port);
2020
// bad things will happen.
2121
void DtmDisconnect(DTMConn dtm);
2222

23-
void DtmInitSnapshot(Snapshot snapshot);
23+
void DtmInitSnapshot(Snapshot snapshot, int nactive);
2424

2525
typedef struct {
2626
TransactionId* xids;

contrib/pg_xtm/libdtm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CC=clang -DTEST
1+
CC=clang -DTEST -DNODELAY
22
CFLAGS=-g -Wall -I"../../../src/include"
33

44

0 commit comments

Comments
 (0)