Make more transparence with variable name from replica snapshot

Task: #43152
Story: #2009162
Change-Id: I469ad8b44640118883c903accfef0349e9ecb880
This commit is contained in:
Bo Tran 2021-09-05 13:41:31 +07:00
parent f3459e2662
commit edd503976c
5 changed files with 22 additions and 17 deletions

View File

@ -882,7 +882,7 @@ class Manager(periodic_task.PeriodicTasks):
self.replication.enable_as_master(self.app, replica_source_config)
LOG.info('Enabled as replication master')
snapshot_id, log_position = self.replication.snapshot_for_replication(
snapshot_id, replica_conf = self.replication.snapshot_for_replication(
context, self.app, self.adm, None, snapshot_info)
volume_stats = self.get_filesystem_stats(context, None)
@ -896,7 +896,7 @@ class Manager(periodic_task.PeriodicTasks):
},
'replication_strategy': self.replication_strategy,
'master': self.replication.get_master_ref(self.app, snapshot_info),
'log_position': log_position
'replica_conf': replica_conf
}
return replication_snapshot

View File

@ -31,15 +31,16 @@ class MariaDBGTIDReplication(mysql_base.MysqlReplicationBase):
master_info = super(MariaDBGTIDReplication, self).get_replica_context(
service, adm)
replica_conf = master_info['replica_conf']
get_pos_cmd = 'SELECT @@global.gtid_binlog_pos;'
gtid_pos = service.execute_sql(get_pos_cmd).first()[0]
LOG.debug('gtid_binlog_pos: %s', gtid_pos)
master_info['log_position']['gtid_pos'] = gtid_pos
replica_conf['log_position']['gtid_pos'] = gtid_pos
return master_info
def connect_to_master(self, service, master_info):
logging_config = master_info['log_position']
replica_conf = master_info['replica_conf']
last_gtid = ''
if 'dataset' in master_info:
@ -59,8 +60,8 @@ class MariaDBGTIDReplication(mysql_base.MysqlReplicationBase):
{
'host': master_info['master']['host'],
'port': master_info['master']['port'],
'user': logging_config['replication_user']['name'],
'password': logging_config['replication_user']['password'],
'user': replica_conf['replication_user']['name'],
'password': replica_conf['replication_user']['password']
})
service.execute_sql(change_master_cmd)

View File

@ -92,10 +92,11 @@ class MysqlReplicationBase(base.Replication):
replication_user = self._create_replication_user(service, adm)
service.grant_replication_privilege(replication_user)
log_position = {
replica_conf = {
'log_position': {},
'replication_user': replication_user
}
return snapshot_info['id'], log_position
return snapshot_info['id'], replica_conf
def enable_as_master(self, service, master_config):
if not service.exists_replication_source_overrides():
@ -146,7 +147,8 @@ class MysqlReplicationBase(base.Replication):
service.grant_replication_privilege(replication_user)
return {
'master': self.get_master_ref(service, None),
'log_position': {
'replica_conf': {
'log_position': {},
'replication_user': replication_user
}
}

View File

@ -38,12 +38,12 @@ class MysqlGTIDReplication(mysql_base.MysqlReplicationBase):
set_gtid_cmd = "SET GLOBAL gtid_purged='%s'" % last_gtid
service.execute_sql(set_gtid_cmd)
logging_config = master_info['log_position']
replica_conf = master_info['replica_conf']
LOG.info(
"Configure the slave, master: %s:%s, replication user: %s",
master_info['master']['host'],
master_info['master']['port'],
logging_config['replication_user']['name']
replica_conf['replication_user']['name']
)
change_master_cmd = (
@ -57,8 +57,8 @@ class MysqlGTIDReplication(mysql_base.MysqlReplicationBase):
{
'host': master_info['master']['host'],
'port': master_info['master']['port'],
'user': logging_config['replication_user']['name'],
'password': logging_config['replication_user']['password']
'user': replica_conf['replication_user']['name'],
'password': replica_conf['replication_user']['password']
})
service.execute_sql(change_master_cmd)

View File

@ -136,10 +136,11 @@ class PostgresqlReplicationStreaming(base.Replication):
LOG.info('Getting or creating replication user')
replication_user = self._get_or_create_replication_user(service)
log_position = {
replica_conf = {
'log_position': {},
'replication_user': replication_user
}
return snapshot_info['id'], log_position
return snapshot_info['id'], replica_conf
def get_master_ref(self, service, snapshot_info):
master_ref = {
@ -158,7 +159,7 @@ class PostgresqlReplicationStreaming(base.Replication):
as_root=True)
LOG.debug("Standby signal file created")
user = snapshot['log_position']['replication_user']
user = snapshot['replica_conf']['replication_user']
conninfo = (f"host={snapshot['master']['host']} "
f"port={snapshot['master']['port']} "
f"dbname=postgres "
@ -189,8 +190,9 @@ class PostgresqlReplicationStreaming(base.Replication):
repl_user_info = self._get_or_create_replication_user(service)
return {
'log_position': {},
'master': self.get_master_ref(None, None),
'log_position': {'replication_user': repl_user_info}
'replica_conf': {'replication_user': repl_user_info}
}
def cleanup_source_on_replica_detach(self, admin_service, replica_info):