Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7a6bd55

Browse files
committed
fixes for adding nodes using pg_basebackup
1 parent b3e7cbd commit 7a6bd55

10 files changed

+379
-267
lines changed

Cluster.pm

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ sub init
2828

2929
foreach my $node (@$nodes)
3030
{
31+
# $node->{_host} = '127.0.0.1';
3132
$node->init(allows_streaming => 'logical');
3233
$node->append_conf('postgresql.conf', q{
33-
unix_socket_directories = ''
34+
# unix_socket_directories = ''
3435
listen_addresses = '127.0.0.1'
3536
max_connections = 50
3637
@@ -114,18 +115,44 @@ sub add_node()
114115

115116
push(@{$self->{nodes}}, get_new_node("node@{[$#{$self->{nodes}} + 2]}"));
116117

117-
# $self->{nodes}->[0]->backup("backup_for_$new_node_id");
118-
# $new_node->init_from_backup($self->{nodes}->[0], "backup_for_$new_node_id");
119-
120118
return $#{$self->{nodes}};
121119
}
122120

123-
sub backup()
121+
sub command_output
124122
{
125-
my ($self, $from, $to) = @_;
123+
my ($cmd) = @_;
124+
my ($stdout, $stderr);
125+
print("# Running: " . join(" ", @{$cmd}) . "\n");
126+
my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr;
127+
ok($result, "@$cmd: exit code 0");
128+
# bb writes to stderr
129+
return $stderr;
130+
}
131+
132+
sub backup_and_init()
133+
{
134+
my ($self, $from, $to, $to_mmid) = @_;
135+
136+
my $node = $self->{nodes}->[$from];
137+
my $backup_name = "backup_for_$to";
138+
my $backup_path = $node->backup_dir . '/' . $backup_name;
139+
my $port = $node->port;
140+
my $name = $node->name;
141+
142+
print "# Taking pg_basebackup $backup_name from node \"$name\"\n";
143+
my $dumpres = command_output(['pg_basebackup', '-D', $backup_path, '-p', $port,
144+
'--no-sync', '-v', '-S', "mtm_recovery_slot_$to_mmid"]);
145+
146+
print "# Backup finished\n";
147+
148+
note($dumpres);
149+
150+
(my $end_lsn) = $dumpres =~ /end point: (.+)/m;
151+
note($end_lsn);
152+
153+
$self->{nodes}->[$to]->init_from_backup($node, $backup_name);
126154

127-
$self->{nodes}->[$from]->backup("backup_for_$to");
128-
$self->{nodes}->[$to]->init_from_backup($self->{nodes}->[$from], "backup_for_$to");
155+
return $end_lsn;
129156
}
130157

131158
sub await_nodes()
@@ -141,7 +168,7 @@ sub await_nodes()
141168
}
142169
else
143170
{
144-
print("Pleed node$i");
171+
print("Polled node$i\n");
145172
}
146173
}
147174
}

multimaster--1.0.sql

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ $$
104104
$$
105105
LANGUAGE sql;
106106

107-
CREATE OR REPLACE FUNCTION mtm.add_node(connstr text) RETURNS void AS
107+
CREATE OR REPLACE FUNCTION mtm.add_node(connstr text) RETURNS int AS
108108
$$
109109
DECLARE
110110
new_node_id int;
@@ -117,6 +117,7 @@ BEGIN
117117
SELECT id FROM mtm.cluster_nodes
118118
) unused_ids
119119
RETURNING id INTO new_node_id;
120+
RETURN new_node_id;
120121
END
121122
$$
122123
LANGUAGE plpgsql;
@@ -127,7 +128,7 @@ DELETE FROM mtm.cluster_nodes WHERE id = $1;
127128
$$
128129
LANGUAGE sql;
129130

130-
CREATE FUNCTION mtm.join_node(node_id int)
131+
CREATE FUNCTION mtm.join_node(node_id int, backup_end pg_lsn)
131132
RETURNS VOID
132133
AS 'MODULE_PATHNAME','mtm_join_node'
133134
LANGUAGE C;
@@ -159,6 +160,17 @@ CREATE TABLE mtm.referee_decision(
159160
node_id int
160161
);
161162

163+
-- possible tuples:
164+
-- 'basebackup' : source node_id and end lsn of basebackup
165+
-- XXX: move my_node_id here?
166+
-- XXX: move referee_decision here?
167+
CREATE TABLE mtm.config(
168+
key text primary key not null,
169+
value jsonb
170+
);
171+
172+
CREATE CAST (pg_lsn AS bigint) WITHOUT FUNCTION;
173+
162174
CREATE TABLE mtm.syncpoints(
163175
node_id int not null,
164176
origin_lsn bigint not null,

src/include/multimaster.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ typedef struct
162162

163163
typedef struct
164164
{
165-
int n_nodes;
166-
int my_node_id;
165+
int n_nodes;
166+
int my_node_id;
167+
int backup_node_id;
168+
XLogRecPtr backup_end_lsn;
167169
MtmNode nodes[MTM_MAX_NODES];
168170
} MtmConfig;
169171

0 commit comments

Comments
 (0)