Get the App
SLTechnology News&Howtos  ›  Database  › 

Trove upgrade source code reading

Shulou Source: shulou.com Published: 2022-06-01 10:44:38 10月30日 Update

Trove upgrade is used to update the database from one version to another, such as changing mysql5.5 to mysql5.6

Trove/taskmanager/manager.py line 368

Def upgrade (self, context, instance_id, datastore_version_id): instance_tasks = models.BuiltInstanceTasks.load (context, instance_id) datastore_version = DatastoreVersion.load_by_uuid (datastore_version_id) with EndNotification (context): instance_tasks.upgrade (datastore_version)

Instance_tasks.upgrade (datastore_version) call

Trove/taskmanager/models.py 1501 lines

Def upgrade (self, datastore_version):... Try: upgrade_info = self.guest.pre_upgrade ()... Self.server.rebuild (datastore_version.p_w_picpath_id, files=injected_files)... If volume: upgrade_info ['device'] = volume_device self.guest.post_upgrade (upgrade_info) self.reset_task_status ()...

Upgrade instance is mainly completed in the following steps:

Self.guest.pre_upgrade: some actions before updating, mainly to save the configuration file of mysql in cinder volume

Self.server.rebuild: rebuilds the nova instance of trove with the new database base mirror

Self.guest.post_upgrade: some actions after rebuilding the nova instance, the main operation is to restore the mysql configuration file from the cinder volume and start the mysql

Self.guest.pre_upgrade,self.guest.post_upgrade calls the corresponding method of trove-guestagent running on nova instance through rcp.

Trove/guestagent/datastore/mysql/_common/manager.py 245 Lin

Def pre_upgrade (self, context): app = self.mysql_app (self.mysql_app_status.get ()) data_dir = app.get_data_dir () mount_point _ data = os.path.split (data_dir) save_dir = "% s/etc_mysql"% mount_point save_etc_dir = "% s/etc"% mount_point home_save = "% s/trove_user"% mount_point app.status.begin_restart () app.stop_db () if operating_system.exists ("/ etc/my.cnf" As_root=True): operating_system.create_directory (save_etc_dir, as_root=True) operating_system.copy ("/ etc/my.cnf", save_etc_dir, preserve=True, as_root=True) operating_system.copy ("/ etc/mysql/.", save_dir, preserve=True As_root=True) operating_system.copy ("% mount_point': mount_point."% os.path.expanduser ('~'), home_save, preserve=True, as_root=True) self.unmount_volume (context, mount_point=data_dir) return {'mount_point': mount_point,' save_dir': save_dir 'save_etc_dir': save_etc_dir, 'home_save': home_save}

Pre_upgrade backup database configuration file, guestagent configuration information located in the trove home directory, and returns a dictionary containing backup information

Trove/guestagent/datastore/mysql/_common/manager.py 275 lines

Def post_upgrade (self, context, upgrade_info): app = self.mysql_app (self.mysql_app_status.get ()) app.stop_db () if 'device' in upgrade_info: self.mount_volume (context, mount_point=upgrade_info [' mount_point'], device_path=upgrade_info ['device'] Write_to_fstab=True) if operating_system.exists (upgrade_info ['save_etc_dir'], is_directory=True, as_root=True): operating_system.copy ("% s etc."% upgrade_info [' save_etc_dir'], "/ etc", preserve=True As_root=True) operating_system.copy ("% s home_save'."% upgrade_info ['save_dir'], "/ etc/mysql", preserve=True, as_root=True) operating_system.copy ("% s as_root=True."% upgrade_info [' home_save'], os.path.expanduser ('~') Preserve=True, as_root=True) self.configuration_manager.refresh_cache () app.start_mysql ()

Post_upgrade restores the configuration files in the backup, does not modify any files of the old database, and directly uses the configuration files and data files of the old database to start the database.

Tags: Data file database configuration backup information version update no foundation dictionary instance method method directory mirror run source code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker macOS MySQL NVidia