Skip to content

Commit

Permalink
Fix not supported syntax in v4.2.1 and backup policy mismatch names o…
Browse files Browse the repository at this point in the history
…f OBTenant resource (#103)

* fix(backup): v4.2.1 does not support select UNION ALL select syntax
* fix: get tenant CR with tenantName
* fix: get tenant CR when spec.tenantCRName is empty
* fix: standby does not replay log when restore without any limit
* fix(distribution): obproxy start scripts parameter error
  • Loading branch information
powerfooI authored Nov 17, 2023
1 parent a9b97ae commit 6b5c7e4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
4 changes: 2 additions & 2 deletions distribution/obproxy/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ fi

if [ ! -z $CONFIG_URL ]; then
echo "use config server"
cd /home/admin/obproxy && /home/admin/obproxy/bin/obproxy -p 2883 -n ${APP_NAME} -o observer_sys_password=${PROXYRO_PASSWORD_HASH},obproxy_config_server_url="${CONFIG_URL}",prometheus_sync_interval=1,prometheus_listen_port=2884,enable_metadb_used=false,skip_proxy_sys_private_check=true,log_dir_size_threshold=10G,enable_proxy_scramble=true,enable_strict_kernel_release=false --nodaemon
cd /home/admin/obproxy && /home/admin/obproxy/bin/obproxy -p 2883 -l 2884 -n ${APP_NAME} -o observer_sys_password=${PROXYRO_PASSWORD_HASH},obproxy_config_server_url="${CONFIG_URL}",prometheus_sync_interval=1,enable_metadb_used=false,skip_proxy_sys_private_check=true,log_dir_size_threshold=10G,enable_proxy_scramble=true,enable_strict_kernel_release=false --nodaemon
elif [ ! -z $RS_LIST ]; then
echo "use rslist"
cd /home/admin/obproxy && /home/admin/obproxy/bin/obproxy -p 2883 -n ${APP_NAME} -c ${OB_CLUSTER} -r\"${RS_LIST}\" -o observer_sys_password=${PROXYRO_PASSWORD_HASH},prometheus_sync_interval=1,prometheus_listen_port=2884,enable_metadb_used=false,skip_proxy_sys_private_check=true,log_dir_size_threshold=10G,enable_proxy_scramble=true,enable_strict_kernel_release=false --nodaemon
cd /home/admin/obproxy && /home/admin/obproxy/bin/obproxy -p 2883 -l 2884 -n ${APP_NAME} -c ${OB_CLUSTER} -r "${RS_LIST}" -o observer_sys_password=${PROXYRO_PASSWORD_HASH},prometheus_sync_interval=1,enable_metadb_used=false,skip_proxy_sys_private_check=true,log_dir_size_threshold=10G,enable_proxy_scramble=true,enable_strict_kernel_release=false --nodaemon
else
echo "no config server or rs list"
exit 1
Expand Down
3 changes: 2 additions & 1 deletion pkg/oceanbase/const/sql/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const (
QueryLatestBackupJobOfTypeAndPath = "SELECT " + backupJobFields + " FROM DBA_OB_BACKUP_JOBS WHERE backup_type = ? and path = ? order by job_id DESC LIMIT 1"
QueryLatestBackupJobHistoryOfTypeAndPath = "SELECT " + backupJobFields + " FROM DBA_OB_BACKUP_JOB_HISTORY WHERE backup_type = ? and path = ? order by job_id DESC LIMIT 1"
QueryLatestRunningBackupJob = "SELECT " + backupJobFields + " FROM DBA_OB_BACKUP_JOBS order by job_id DESC LIMIT 1"
QueryLatestCleanJob = "SELECT " + cleanJobFields + " FROM DBA_OB_BACKUP_DELETE_JOBS ORDER BY job_id DESC LIMIT 1 UNION ALL SELECT " + cleanJobFields + " FROM DBA_OB_BACKUP_DELETE_JOB_HISTORY ORDER BY job_id DESC LIMIT 1"
QueryLatestCleanJob = "SELECT " + cleanJobFields + " FROM DBA_OB_BACKUP_DELETE_JOBS ORDER BY job_id DESC LIMIT 1"
QueryLatestCleanJobHistory = "SELECT " + cleanJobFields + " FROM DBA_OB_BACKUP_DELETE_JOB_HISTORY ORDER BY job_id DESC LIMIT 1"
QueryLatestArchiveLogJob = "SELECT " + logArchiveJobFields + " FROM DBA_OB_ARCHIVELOG_SUMMARY ORDER BY round_id DESC LIMIT 1"

QueryBackupJobWithId = "SELECT " + backupJobFields + " FROM DBA_OB_BACKUP_JOBS WHERE job_id = ?"
Expand Down
7 changes: 7 additions & 0 deletions pkg/oceanbase/operation/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ func (m *OceanbaseOperationManager) GetLatestBackupCleanJob() (*model.OBBackupCl
if len(jobs) != 0 {
return jobs[0], nil
}
err = m.QueryList(&jobs, sql.QueryLatestCleanJobHistory)
if err != nil {
return nil, err
}
if len(jobs) != 0 {
return jobs[0], nil
}
return nil, nil
}

Expand Down
29 changes: 15 additions & 14 deletions pkg/resource/obtenantbackuppolicy_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ func (m *ObTenantBackupPolicyManager) CheckAndUpdateFinalizers() error {
// the tenant is being deleted
finalizerFinished = true
}
} else {
finalizerFinished = m.BackupPolicy.Status.Status == constants.BackupPolicyStatusStopped
}
finalizerFinished = finalizerFinished || m.BackupPolicy.Status.Status == constants.BackupPolicyStatusStopped
}

if finalizerFinished {
Expand All @@ -125,15 +124,17 @@ func (m *ObTenantBackupPolicyManager) InitStatus() {
}

func (m *ObTenantBackupPolicyManager) syncTenantInformation() error {
tenant := &v1alpha1.OBTenant{}
err := m.Client.Get(m.Ctx, types.NamespacedName{
Namespace: m.BackupPolicy.Namespace,
Name: m.BackupPolicy.Spec.TenantName,
}, tenant)
if err != nil {
return err
if m.BackupPolicy.Spec.TenantCRName != "" {
tenant := &v1alpha1.OBTenant{}
err := m.Client.Get(m.Ctx, types.NamespacedName{
Namespace: m.BackupPolicy.Namespace,
Name: m.BackupPolicy.Spec.TenantCRName,
}, tenant)
if err != nil {
return err
}
m.BackupPolicy.Status.TenantCR = tenant
}
m.BackupPolicy.Status.TenantCR = tenant

tenantRecord, err := m.getTenantRecord(false)
if err != nil {
Expand Down Expand Up @@ -166,7 +167,7 @@ func (m *ObTenantBackupPolicyManager) UpdateStatus() error {
m.BackupPolicy.Status.OperationContext = nil
} else if !m.BackupPolicy.Spec.Suspend && m.BackupPolicy.Status.Status == constants.BackupPolicyStatusPaused {
m.BackupPolicy.Status.Status = constants.BackupPolicyStatusResuming
} else if m.IsDeleting() && m.BackupPolicy.Status.Status != constants.BackupPolicyStatusDeleting {
} else if m.IsDeleting() && m.BackupPolicy.Status.Status == constants.BackupPolicyStatusRunning {
m.BackupPolicy.Status.Status = constants.BackupPolicyStatusDeleting
m.BackupPolicy.Status.OperationContext = nil
} else if m.BackupPolicy.Status.Status == constants.BackupPolicyStatusRunning {
Expand Down Expand Up @@ -393,15 +394,15 @@ func (m *ObTenantBackupPolicyManager) getOBTenantCR() (*v1alpha1.OBTenant, error
Resource: "obtenantbackuppolicies",
}, m.BackupPolicy.Spec.TenantCRName)
}
tenantName := m.BackupPolicy.Spec.TenantCRName
tenantCRName := m.BackupPolicy.Spec.TenantCRName
tenant := &v1alpha1.OBTenant{}
err := m.Client.Get(m.Ctx, types.NamespacedName{
Namespace: m.BackupPolicy.Namespace,
Name: tenantName,
Name: tenantCRName,
}, tenant)
if err != nil {
if !kubeerrors.IsNotFound(err) {
m.Logger.Error(err, "get obtenant failed", "tenantName", tenantName, "namespaced", m.BackupPolicy.Namespace)
m.Logger.Error(err, "get obtenant failed", "tenantCRName", tenantCRName, "namespaced", m.BackupPolicy.Namespace)
}
return nil, err
}
Expand Down
14 changes: 11 additions & 3 deletions pkg/resource/obtenantbackuppolicy_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,16 @@ func (m *ObTenantBackupPolicyManager) StopBackup() error {
if err != nil {
return err
}

_ = con.DisableArchiveLogForTenant()
tenantInfo, err := m.getTenantRecord(false)
if err != nil {
return err
}
if tenantInfo.LogMode != "NOARCHIVELOG" {
err = con.DisableArchiveLogForTenant()
if err != nil {
return err
}
}

err = con.StopBackupJobOfTenant()
if err != nil {
Expand Down Expand Up @@ -471,7 +479,7 @@ func (m *ObTenantBackupPolicyManager) getOperationManager() (*operation.Oceanbas
tenantCR := &v1alpha1.OBTenant{}
err = m.Client.Get(m.Ctx, types.NamespacedName{
Namespace: m.BackupPolicy.Namespace,
Name: m.BackupPolicy.Spec.TenantName,
Name: m.BackupPolicy.Spec.TenantCRName,
}, tenantCR)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/resource/obtenantrestore_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func (m *ObTenantRestoreManager) checkRestoreProgress() error {
if restoreHistory != nil && restoreHistory.Status == "SUCCESS" {
m.Recorder.Event(m.Resource, corev1.EventTypeNormal, "Restore job finished", "Restore job finished")
if m.Resource.Spec.RestoreRole == constants.TenantRoleStandby {
if m.Resource.Spec.Source.ReplayEnabled && !m.Resource.Spec.Source.Until.Unlimited {
// Only if replay is enabled and restore until is not unlimited, start log replay
if m.Resource.Spec.Source.ReplayEnabled {
// Only if replay is enabled start log replay
m.Resource.Status.Status = constants.RestoreJobStatusReplaying
} else {
m.Resource.Status.Status = constants.RestoreJobSuccessful
Expand Down

0 comments on commit 6b5c7e4

Please sign in to comment.