|
1 | 1 | This extension allows you to have a key-value table replicated between several
|
2 | 2 | Postgres instances over Raft protocol.
|
3 | 3 |
|
| 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 | + |
4 | 37 | C API:
|
5 | 38 | /* Gets value by key. Returns the value or NULL if not found. */
|
6 | 39 | char *raftable_get(int key);
|
7 | 40 |
|
8 | 41 | /*
|
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. |
11 | 44 | */
|
12 | 45 | void raftable_set(int key, char *value);
|
13 | 46 |
|
|
0 commit comments