Skip to content

Commit 2e2c464

Browse files
committed
2 parents 4c57b00 + 1deed76 commit 2e2c464

File tree

11 files changed

+205
-120
lines changed

11 files changed

+205
-120
lines changed

contrib/mmts/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
MODULE_big = multimaster
2-
OBJS = multimaster.o raftable.o arbiter.o bytebuf.o bgwpool.o pglogical_output.o pglogical_proto.o pglogical_receiver.o pglogical_apply.o pglogical_hooks.o pglogical_config.o ddd.o bkb.o
2+
OBJS = multimaster.o arbiter.o bytebuf.o bgwpool.o pglogical_output.o pglogical_proto.o pglogical_receiver.o pglogical_apply.o pglogical_hooks.o pglogical_config.o ddd.o bkb.o
3+
4+
override CPPFLAGS += -I../raftable
5+
6+
EXTRA_INSTALL = contrib/raftable contrib/mmts
37

48
EXTENSION = multimaster
59
DATA = multimaster--1.0.sql

contrib/mmts/multimaster.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
#include "multimaster.h"
5959
#include "ddd.h"
60+
#include "raftable_wrapper.h"
6061
#include "raftable.h"
6162

6263
typedef struct {
@@ -2368,3 +2369,31 @@ MtmDetectGlobalDeadLock(PGPROC* proc)
23682369
}
23692370
return hasDeadlock;
23702371
}
2372+
2373+
void* RaftableGet(char const* key, int* size, RaftableTimestamp* ts, bool nowait)
2374+
{
2375+
size_t s;
2376+
char *value;
2377+
2378+
if (!MtmUseRaftable) return NULL;
2379+
2380+
Assert(ts == NULL); /* not implemented */
2381+
value = raftable_get(key, &s);
2382+
*size = s;
2383+
return value;
2384+
}
2385+
2386+
void RaftableSet(char const* key, void const* value, int size, bool nowait)
2387+
{
2388+
if (!MtmUseRaftable) return;
2389+
2390+
raftable_set(key, value, size, nowait ? 0 : -1);
2391+
}
2392+
2393+
bool RaftableCAS(char const* key, char const* value, bool nowait)
2394+
{
2395+
if (!MtmUseRaftable) return false;
2396+
2397+
Assert(false); /* not implemented */
2398+
return false;
2399+
}

contrib/mmts/raftable.h renamed to contrib/mmts/raftable_wrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __RAFTABLE_H__
2-
#define __RAFTABLE_H__
1+
#ifndef __RAFTABLE_WRAPPER_H__
2+
#define __RAFTABLE_WRAPPER_H__
33

44
typedef struct RaftableTimestamp {
55
time_t time; /* local time at master */

contrib/mmts/t/001_basic_recovery.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ sub PostgresNode::inet_connstr {
3636
max_wal_senders = 10
3737
max_replication_slots = 10
3838
wal_level = logical
39-
shared_preload_libraries = 'multimaster'
39+
shared_preload_libraries = 'raftable,multimaster'
4040
multimaster.workers=4
4141
multimaster.queue_size=10485760 # 10mb
4242
);

contrib/raftable/README

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,24 @@ The backend can also issue commands to itself through C API.
4040

4141
C API:
4242
/* Gets value by key. Returns the value or NULL if not found. */
43-
char *raftable_get(char *key);
43+
char *raftable_get(const char *key, size_t *vallen);
4444

4545
/*
46-
* Adds/updates value by key. Returns when the value gets replicated on
47-
* current machine. Storing NULL will delete the item from the table.
46+
* Adds/updates value by key. Returns when the value gets replicated.
47+
* Storing NULL will delete the item from the table. Gives up after
48+
* 'timeout_ms' milliseconds.
4849
*/
49-
void raftable_set(char *key, char *value);
50+
void raftable_set(const char *key, const char *value, size_t len, int timeout_ms);
5051

5152
/*
5253
* Iterates over all items in the table, calling func(key, value, arg)
5354
* for each of them.
5455
*/
55-
void raftable_every(void (*func)(char *, char *, void *), void *arg);
56+
void raftable_every(void (*func)(const char *, const char *, size_t, void *), void *arg);
5657

5758
SQL API:
5859
-- set
59-
raftable(key varchar(64), value text, tries int);
60+
raftable(key varchar(64), value text, timeout_ms int);
6061

6162
-- get
6263
raftable(key varchar(64)) returns text;

contrib/raftable/raftable--1.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ AS 'MODULE_PATHNAME','raftable_sql_get'
88
LANGUAGE C;
99

1010
-- set
11-
CREATE FUNCTION raftable(key varchar(64), value text, tries int)
11+
CREATE FUNCTION raftable(key varchar(64), value text, timeout_ms int)
1212
RETURNS void
1313
AS 'MODULE_PATHNAME','raftable_sql_set'
1414
LANGUAGE C;

0 commit comments

Comments
 (0)