Skip to content

Commit 9d293c4

Browse files
committed
Merge branch 'xtm' of gitlab.postgrespro.ru:pgpro-dev/postgrespro into xtm
2 parents 776e0cb + 7a3c1f2 commit 9d293c4

File tree

4 files changed

+84
-136
lines changed

4 files changed

+84
-136
lines changed

contrib/pg_xtm/dtmd/src/main.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -352,21 +352,21 @@ static char *onnoise(void *client, cmd_t *cmd) {
352352
return strdup("-");
353353
}
354354

355-
static float now_s() {
356-
// current time in seconds
357-
struct timespec t;
358-
if (clock_gettime(CLOCK_MONOTONIC, &t) == 0) {
359-
return t.tv_sec + t.tv_nsec * 1e-9;
360-
} else {
361-
printf("Error while clock_gettime()\n");
362-
exit(0);
363-
}
364-
}
355+
// static float now_s() {
356+
// // current time in seconds
357+
// struct timespec t;
358+
// if (clock_gettime(CLOCK_MONOTONIC, &t) == 0) {
359+
// return t.tv_sec + t.tv_nsec * 1e-9;
360+
// } else {
361+
// printf("Error while clock_gettime()\n");
362+
// exit(0);
363+
// }
364+
// }
365365

366366
static char *oncmd(void *client, cmd_t *cmd) {
367367
//shout_cmd(client, cmd);
368368

369-
float started = now_s();
369+
// float started = now_s();
370370
char *result = NULL;
371371
switch (cmd->cmd) {
372372
case CMD_BEGIN:
@@ -387,8 +387,8 @@ static char *oncmd(void *client, cmd_t *cmd) {
387387
default:
388388
return onnoise(client, cmd);
389389
}
390-
float elapsed = now_s() - started;
391-
shout("cmd '%c' processed in %0.4f sec\n", cmd->cmd, elapsed);
390+
// float elapsed = now_s() - started;
391+
// shout("cmd '%c' processed in %0.4f sec\n", cmd->cmd, elapsed);
392392
return result;
393393
}
394394

contrib/pg_xtm/libdtm/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
CC=clang -DTEST -DNODELAY
22
CFLAGS=-g -Wall -I"../../../src/include"
33

4-
5-
all: lib/libdtm.a bin/example bin/bench
4+
all: lib/libdtm.a bin/example bin/bench bin/redbench
65

76
bin/bench: bindir lib/libdtm.a src/bench.c
87
$(CC) $(CFLAGS) -o bin/bench -Iinclude -Llib src/bench.c -ldtm
98

9+
bin/redbench: bindir lib/libdtm.a src/redbench.c
10+
$(CC) $(CFLAGS) -o bin/redbench -Iinclude -Llib src/redbench.c -ldtm -lhiredis -I"/usr/local/include/hiredis/"
11+
1012
bin/example: bindir lib/libdtm.a src/example.c
1113
$(CC) $(CFLAGS) -o bin/example -Iinclude -Llib src/example.c -ldtm
1214

contrib/pg_xtm/libdtm/src/bench.c

Lines changed: 22 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -4,149 +4,50 @@
44

55
#include "libdtm.h"
66

7-
#define NODES 1
7+
#define unless(x) if (!(x))
88

9-
#ifdef WIN32
10-
#include <windows.h>
11-
static float li2f(LARGE_INTEGER x) {
12-
float result = ((float)x.HighPart) * 4.294967296E9 + (float)((x).LowPart);
13-
return result;
14-
}
9+
#define NODES 1
1510

16-
static float now_s() {
17-
LARGE_INTEGER freq, count;
18-
QueryPerformanceFrequency(&freq);
19-
QueryPerformanceCounter(&count);
20-
return li2f(count) / li2f(freq);
21-
}
22-
#else
23-
static float now_s() {
24-
// current time in seconds
25-
struct timespec t;
26-
if (clock_gettime(CLOCK_MONOTONIC, &t) == 0) {
27-
return t.tv_sec + t.tv_nsec * 1e-9;
28-
} else {
29-
printf("Error while clock_gettime()\n");
30-
exit(0);
31-
}
32-
}
33-
#endif
3411

35-
static void start_transaction(DTMConn conn, TransactionId base) {
12+
int main(int argc, char **argv) {
3613
GlobalTransactionId gtid;
14+
TransactionId base = 42;
15+
int transactions = 10000;
16+
int i;
3717
gtid.nNodes = NODES;
3818
gtid.xids = malloc(sizeof(TransactionId) * gtid.nNodes);
3919
gtid.nodes = malloc(sizeof(NodeId) * gtid.nNodes);
4020

41-
int n;
42-
for (n = 0; n < gtid.nNodes; n++) {
43-
gtid.xids[n] = base + n;
44-
gtid.nodes[n] = n;
45-
}
46-
47-
if (!DtmGlobalStartTransaction(conn, &gtid)) {
48-
fprintf(stdout, "global transaction not started\n");
49-
exit(EXIT_FAILURE);
21+
DTMConn conn = DtmConnect("localhost", 5431);
22+
if (!conn) {
23+
exit(1);
5024
}
51-
//fprintf(stdout, "global transaction started\n");
5225

53-
free(gtid.xids);
54-
free(gtid.nodes);
55-
}
26+
for (i = 0; i < transactions; i++) {
5627

57-
static void commit_transaction(DTMConn conn, TransactionId base) {
58-
int n;
59-
for (n = 0; n < NODES; n++) {
60-
if (!DtmGlobalSetTransStatus(conn, n, base + n, TRANSACTION_STATUS_COMMITTED)) {
61-
fprintf(stdout, "global transaction not committed\n");
62-
exit(EXIT_FAILURE);
28+
int n;
29+
for (n = 0; n < gtid.nNodes; n++) {
30+
gtid.xids[n] = base + n;
31+
gtid.nodes[n] = n;
6332
}
64-
}
65-
//fprintf(stdout, "global transaction committed\n");
66-
}
6733

68-
static void abort_transaction(DTMConn conn, TransactionId base) {
69-
if (!DtmGlobalSetTransStatus(conn, 0, base + 0, TRANSACTION_STATUS_ABORTED)) {
70-
fprintf(stdout, "global transaction not aborted\n");
71-
exit(EXIT_FAILURE);
72-
}
73-
//fprintf(stdout, "global transaction aborted\n");
74-
}
75-
76-
static void show_snapshots(DTMConn conn, TransactionId base) {
77-
int i, n;
78-
for (n = 0; n < NODES; n++) {
79-
Snapshot s = malloc(sizeof(SnapshotData));
80-
s->xip = NULL;
81-
82-
if (!DtmGlobalGetSnapshot(conn, n, base + n, s)) {
83-
fprintf(stdout, "failed to get a snapshot[%d]\n", n);
34+
if (!DtmGlobalStartTransaction(conn, &gtid)) {
35+
fprintf(stdout, "global transaction not started\n");
8436
exit(EXIT_FAILURE);
8537
}
86-
//fprintf(stdout, "snapshot[%d, %#x]: xmin = %#x, xmax = %#x, active =", n, base + n, s->xmin, s->xmax);
87-
//for (i = 0; i < s->xcnt; i++) {
88-
// fprintf(stdout, " %#x", s->xip[i]);
89-
//}
90-
//fprintf(stdout, "\n");
91-
92-
free(s->xip);
93-
free(s);
94-
}
95-
}
9638

97-
static void show_status(DTMConn conn, TransactionId base) {
98-
int n;
99-
for (n = 0; n < NODES; n++) {
100-
XidStatus s = DtmGlobalGetTransStatus(conn, n, base + n);
101-
if (s == -1) {
102-
fprintf(stdout, "failed to get transaction status [%d, %#x]\n", n, base + n);
39+
if (!DtmGlobalSetTransStatus(conn, 0, base + 0, TRANSACTION_STATUS_COMMITTED)) {
40+
fprintf(stdout, "global transaction not committed\n");
10341
exit(EXIT_FAILURE);
10442
}
105-
//fprintf(stdout, "status[%d, %#x]: ", n, base + n);
106-
//switch (s) {
107-
// case TRANSACTION_STATUS_COMMITTED:
108-
// fprintf(stdout, "committed\n");
109-
// break;
110-
// case TRANSACTION_STATUS_ABORTED:
111-
// fprintf(stdout, "aborted\n");
112-
// break;
113-
// case TRANSACTION_STATUS_IN_PROGRESS:
114-
// fprintf(stdout, "in progress\n");
115-
// break;
116-
// default:
117-
// fprintf(stdout, "(error)\n");
118-
// break;
119-
//}
120-
}
121-
}
12243

123-
int main(int argc, char **argv) {
124-
DTMConn conn = DtmConnect("localhost", 5431);
125-
if (!conn) {
126-
exit(1);
127-
}
128-
129-
TransactionId base = 42;
44+
unless (i%10) {
45+
printf("Commited %u txs.\n", i+1);
46+
}
13047

131-
int transactions = atoi(argv[1]);
132-
int i;
133-
float started = now_s();
134-
for (i = 0; i < transactions; i++) {
135-
printf("-------- %d, base = %d -------- %0.6f sec \n", i, base, now_s() - started);
136-
start_transaction(conn, base);
137-
//show_snapshots(conn, base);
138-
//show_status(conn, base);
139-
commit_transaction(conn, base);
140-
base += NODES;
48+
base++;
14149
}
142-
float elapsed = now_s() - started;
14350

144-
printf(
145-
"%d transactions in %0.2f sec -> %0.2f tps\n",
146-
transactions,
147-
elapsed,
148-
transactions / elapsed
149-
);
15051

15152
DtmDisconnect(conn);
15253
return EXIT_SUCCESS;

contrib/pg_xtm/libdtm/src/redbench.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <hiredis.h>
2+
#include <execinfo.h>
3+
#include <stdio.h>
4+
5+
static redisContext *c = NULL;
6+
static redisReply *reply;
7+
const char *hostname = "127.0.0.1";
8+
static int port = 6379;
9+
static struct timeval timeout = { 1, 500000 }; // 1.5 seconds
10+
11+
12+
int main(){
13+
char buf[100];
14+
int xid;
15+
int i;
16+
17+
18+
if (c == NULL) {
19+
c = redisConnectWithTimeout(hostname, port, timeout);
20+
if (c->err) {
21+
printf("Connection error: %s\n", c->errstr);
22+
redisFree(c);
23+
} else {
24+
printf("Connected to redis \n");
25+
}
26+
}
27+
28+
for (i=0; i<100000; i++){
29+
reply = redisCommand(c,"INCR pgXid");
30+
xid = reply->integer;
31+
freeReplyObject(reply);
32+
33+
// sprintf(buf, "HSET pgXids tx%u 0", xid);
34+
// reply = redisCommand(c, buf);
35+
// freeReplyObject(reply);
36+
37+
// sprintf(buf, "HSET pgXids tx%u 1", xid);
38+
// reply = redisCommand(c, buf);
39+
// freeReplyObject(reply);
40+
}
41+
42+
43+
44+
}
45+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy