| 1 |
|
%% Copyright (c) 2022 Peter Morgan <peter.james.morgan@gmail.com> |
| 2 |
|
%% |
| 3 |
|
%% Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
|
%% you may not use this file except in compliance with the License. |
| 5 |
|
%% You may obtain a copy of the License at |
| 6 |
|
%% |
| 7 |
|
%% http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
|
%% |
| 9 |
|
%% Unless required by applicable law or agreed to in writing, software |
| 10 |
|
%% distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
|
%% See the License for the specific language governing permissions and |
| 13 |
|
%% limitations under the License. |
| 14 |
|
|
| 15 |
|
|
| 16 |
|
-module(pgmp_rep_log). |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
-export([slot_name/1]). |
| 20 |
|
|
| 21 |
|
|
| 22 |
|
-optional_callbacks([begin_transaction/1]). |
| 23 |
|
-optional_callbacks([commit/1]). |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
-type relation() :: #{namespace := binary(), name := binary()}. |
| 27 |
|
-type request_id_collection() :: gen_statem:request_id_collection(). |
| 28 |
|
-type server_ref() :: gen_statem:server_ref(). |
| 29 |
|
-type snapshot_id() :: binary(). |
| 30 |
|
-type x_log() :: #{clock := integer(), |
| 31 |
|
start_wal := integer(), |
| 32 |
|
end_wal := integer()}. |
| 33 |
|
|
| 34 |
|
-type crud_collection_req() :: #{server_ref := server_ref(), |
| 35 |
|
label := any(), |
| 36 |
|
relation := relation(), |
| 37 |
|
tuple := tuple(), |
| 38 |
|
x_log := x_log(), |
| 39 |
|
requests := request_id_collection()}. |
| 40 |
|
|
| 41 |
|
-type snapshot_collection_req() :: #{server_ref := server_ref(), |
| 42 |
|
label := any(), |
| 43 |
|
id := snapshot_id(), |
| 44 |
|
requests := request_id_collection()}. |
| 45 |
|
|
| 46 |
|
-type lsn_collection_req() :: #{server_ref := server_ref(), |
| 47 |
|
label := any(), |
| 48 |
|
requests := request_id_collection()}. |
| 49 |
|
|
| 50 |
|
-type truncate_collection_req() :: #{server_ref := server_ref(), |
| 51 |
|
label := any(), |
| 52 |
|
relations := [relation()], |
| 53 |
|
x_log := x_log(), |
| 54 |
|
requests := request_id_collection()}. |
| 55 |
|
|
| 56 |
|
-type begin_transaction_req() :: #{server_ref := server_ref(), |
| 57 |
|
label := any(), |
| 58 |
|
commit_timestamp := integer(), |
| 59 |
|
final_lsn := integer(), |
| 60 |
|
xid := integer(), |
| 61 |
|
requests := request_id_collection()}. |
| 62 |
|
|
| 63 |
|
-type commit_req() :: #{server_ref := server_ref(), |
| 64 |
|
label := any(), |
| 65 |
|
commit_lsn := integer(), |
| 66 |
|
commit_timestamp := integer(), |
| 67 |
|
end_lsn := integer(), |
| 68 |
|
requests := request_id_collection()}. |
| 69 |
|
|
| 70 |
|
|
| 71 |
|
-callback begin_transaction(begin_transaction_req()) -> request_id_collection(). |
| 72 |
|
-callback commit(commit_req()) -> request_id_collection(). |
| 73 |
|
-callback delete(crud_collection_req()) -> request_id_collection(). |
| 74 |
|
-callback insert(crud_collection_req()) -> request_id_collection(). |
| 75 |
|
-callback lsn(lsn_collection_req()) -> request_id_collection(). |
| 76 |
|
-callback snapshot(snapshot_collection_req()) -> request_id_collection(). |
| 77 |
|
-callback truncate(truncate_collection_req()) -> request_id_collection(). |
| 78 |
|
-callback update(crud_collection_req()) -> request_id_collection(). |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
slot_name(Publication) -> |
| 82 |
10 |
lists:join( |
| 83 |
|
"_", |
| 84 |
|
[pgmp_config:replication(logical, slot_prefix), Publication]). |