Skip to content

Commit dc59786

Browse files
committed
Update raftable README.
1 parent 87d5a0d commit dc59786

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

contrib/raftable/README

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
11
This extension allows you to have a key-value table replicated between several
22
Postgres instances over Raft protocol.
33

4+
Each 'postgres' instance starts a background worker 'raftable' and creates a
5+
shared memory segment for storing the 'state'. All 'raftable' workers are
6+
communicating Raft protocol over UDP.
7+
8+
When 'frontend' issues a read command, the 'backend' returns the data from the
9+
local replica of the 'state' which is in the shared memory of current instance.
10+
11+
When 'frontend' issues a write command, the 'backend' connects to the current
12+
'raftable' leader directly through TCP. Raftable leader returns the state
13+
version number V after the update gets applied (acked by the majority of
14+
'raftable' workers). Then the backend waits until the local state version
15+
number becomes at least V and returns 'ok' to the frontend.
16+
17+
The backend can also issue commands to itself through C API.
18+
19+
fork ┏━━━━━━━━━┓ sql ┏━━━━━━━━━━┓
20+
┌─────────────┨ backend ┠───────┨ frontend ┃
21+
│ ┗┯━━━━━━━┯┛ ┗━━━━━━━━━━┛
22+
│ │shm │
23+
┏━━━━┷━━━━━┓ ┏━━━┷━━━┓ │
24+
┃ postgres ┠────┨ state ┃ │
25+
┗━━━━┯━━━━━┛ ┗━━━┯━━━┛ │ tcp
26+
│ │shm │
27+
│ fork ┏━━━━┷━━━━━┓ │
28+
└─────────┨ raftable ┃ │
29+
┗━┯━┯━┯━┯━┯┛ │
30+
│ raft│ │ │
31+
┏━┷━┷━┷━┷━┷┓ │
32+
┏┻━━━━━━━━━┓┠─┘
33+
┏┻━━━━━━━━━┓┣┛
34+
┃ raftable ┣┛
35+
┗━━━━━━━━━━┛
36+
437
C API:
538
/* Gets value by key. Returns the value or NULL if not found. */
639
char *raftable_get(int key);
740

841
/*
9-
* Adds/updates value by key. Returns when the value gets replicated.
10-
* Storing NULL will delete the item from the table.
42+
* Adds/updates value by key. Returns when the value gets replicated on
43+
* current machine. Storing NULL will delete the item from the table.
1144
*/
1245
void raftable_set(int key, char *value);
1346

0 commit comments

Comments
 (0)