# Remove BR Legacy Code: migrate_log_backup + infraapi

## Problem Statement

BR has fully migrated to the 3-layer architecture (regional API via `regionalapi.NewBackupFacade` / `regionalapi.NewRestoreFacade`). Two legacy subsystems remain:

1. **migrate_log_backup** — The one-time migration DAG that moved running log backups from cloud-native (global k8s apiserver) to 3-layer architecture. All ~42 log backups are migrated; the migration code is now dead.
2. **infraapi.GetInfraAPI()-based BR logic** — The global infra API facade (`BackupInfraFacade`, `RestoreInfraFacade`, `InfraAPIClient` for BR) and associated conditional `On3LayerArch` branching. Since all BR operations now use regional facades, the global path is dead code.

## Approach

Two separate commits:
- **Commit 1**: Remove `migrate_log_backup` feature entirely
- **Commit 2**: Remove `infraapi.GetInfraAPI()` based BR logic (the global facade path)

---

## Commit 1: Remove migrate_log_backup

### Analysis

The migrate_log_backup feature consists of:
- A 5-step DAG workflow (validate → mark_migrating → create_regional_cr → isolate_global_cr → finish_migration)
- A model interface + implementation (`LogBackupMigrator`)
- A CLI command (`migrate-log-backup`)
- Entity field (`LogBackupExtra.Migrating`)
- Migration guard checks in 3 action files
- Workflow constants (DAG name, action names, variable keys)

### Files to DELETE

| File | Reason |
|------|--------|
| `app/models/backup/impl/migrate_log_backup.go` | Main implementation |
| `app/models/backup/mock/log_backup_migrator.go` | Generated mock |
| `app/workflow/dag/backup/pit/migrate.go` | DAG definition |
| `app/workflow/action/backup/pit/migrate/params.go` | Shared params |
| `app/workflow/action/backup/pit/migrate/validate_migration.go` | Action |
| `app/workflow/action/backup/pit/migrate/mark_migrating.go` | Action |
| `app/workflow/action/backup/pit/migrate/create_regional_cr.go` | Action |
| `app/workflow/action/backup/pit/migrate/isolate_global_cr.go` | Action |
| `app/workflow/action/backup/pit/migrate/finish_migration.go` | Action |
| `internal/cmd/job_migrate_log_backup.go` | CLI command |
| `docs/coding-with-agents/log-backup-migration-plan.md` | Design doc |

### Files to MODIFY

| File | Change | Verification |
|------|--------|-------------|
| `app/models/backup/interface.go` | Remove `LogBackupMigrator` interface (lines 141-154) | Compile: no references left |
| `app/container/container.go` | Remove `LogBackupMigrator` field (line 182) and initialization (lines 907-910) | Compile: no references left |
| `app/workflow/dag/register.go` | Remove `GetMigrateDag()` registration (lines 101-103) | Compile: import `dag_backup_pit` still needed for other DAGs |
| `app/workflow/constants.go` | Remove: `BusinessActionMigrateLogBackup` (line 43), action names (lines 145-150), `DagMigrateLogBackup` (line 233), `KeyIgnoredStatusFields` (line 256) | Compile: `KeyLogBackupID` (line 255) MUST stay — used by delete/clean_storage DAGs |
| `app/repo/entity/entity.go` | Remove `Migrating` field from `LogBackupExtra` struct (lines 1141-1145) | Compile + verify `On3LayerArch` field stays |
| `app/models/backup/impl/sync_log_backup_from_infra.go` | Remove Migrating guard check (lines 102-105) and TODO + reconciler-migrated skip logic (lines 116-123) | Compile: ensure syncOneLogBackup still works |
| `app/workflow/action/backup/pit/disable/stop_log_backup.go` | Remove Migrating guard check (lines 55-60) | Compile: stopLogBackup continues normally |
| `app/workflow/action/backup/pit/del/delete_log_backup_workload.go` | Remove Migrating guard check (lines 41-45) | Compile: delete continues normally |

### Assumptions (Verifiable)

1. **All log backups are migrated** — The `Migrating` field should be empty for all records in production. Removing it is safe because no migration DAGs are running.
2. **`KeyLogBackupID` is used outside migration** — Verified: used in `pit_backup.go:595`, `delete.go:38`, `clean_storage.go:39`. MUST NOT be removed.
3. **`BusinessTypeLogBackup` is used outside migration** — Verified: used in `pit_backup.go:599`. MUST NOT be removed.
4. **`dag_backup_pit` import in register.go is still needed** — Verified: used for `GetEnableDag`, `GetDisableDag`, `GetDeleteDag`, `GetRestartDag`.
5. **`IsolateLogBackup` method on BackupFacade interface** — Only used in `migrate/isolate_global_cr.go`. Will be cleaned in Commit 2 along with the interface method.
6. **`RawCreateBackupCR`/`RawGetBackupCR` methods** — Only used in `migrate/create_regional_cr.go`. Will be cleaned in Commit 2.

### Steps

1. Delete the 11 files listed above
2. Edit the 8 files listed above
3. Run `make generate-entity` (if entity changed)
4. Run `make generate4test` (to regenerate mocks without LogBackupMigrator)
5. Run `make app-unit-test-local` to verify
6. Commit

---

## Commit 2: Remove infraapi.GetInfraAPI()-based BR Logic

### Analysis

After Commit 1, the remaining `infraapi` usage in BR code is:
- `BackupInfraFacade` (global backup facade) — used as fallback when `On3LayerArch == false`
- `RestoreInfraFacade` (global restore facade) — same pattern
- `InfraAPIClient` for BR health checker (ListNodeGroup/ListNodePool)
- `pkg/regional-api/br.go` ListLogBackups merging global + regional results
- `BackupFacade` interface methods only used by global infra: `IsolateLogBackup`, `RawCreateBackupCR`, `RawGetBackupCR`

**IMPORTANT**: `InfraAPIClient` is also used by non-BR code (Dumpling, event_bus consumers, DM/Import in `internal/`). Only BR-related usage should be cleaned.

### Files to MODIFY

| File | Change | Verification |
|------|--------|-------------|
| **Container & Initialization** | | |
| `app/container/container.go` | Remove `BackupInfraFacade` field (line 264), `RestoreInfraFacade` field (line 266). Remove their initialization in `initInternalHelper` (lines 412, 414). Remove `InfraAPIClient` from `BackupHealthChecker` constructor call (line 905). Update `SyncLogBackupFromInfra` constructor call to remove `backupInfraFacade` param (line 948). | Compile |
| **Backup Base Action** | | |
| `app/workflow/action/backup/base/base.go` | Remove `BackupFacade` field (the global one). Rename `BackupRegionalFacade` → `BackupFacade`. Update `NewBaseAction` constructor. | Compile + all callers updated |
| **7 Backup DAG files** | | |
| `app/workflow/dag/backup/snapshot/create.go` | Remove `BackupInfraFacade` parameter, pass only `BackupRegionalFacade` | Compile |
| `app/workflow/dag/backup/snapshot/delete.go` | Same | Compile |
| `app/workflow/dag/backup/snapshot/clean_storage.go` | Same | Compile |
| `app/workflow/dag/backup/pit/enbale.go` | Same | Compile |
| `app/workflow/dag/backup/pit/disable.go` | Same | Compile |
| `app/workflow/dag/backup/pit/delete.go` | Same | Compile |
| `app/workflow/dag/backup/pit/restart.go` | Same | Compile |
| **Backup actions with On3LayerArch branching** | | |
| `app/workflow/action/backup/snapshot/create/create_infra_cr.go` | Remove `On3LayerArch` conditional — always use regional facade. Remove `BackupFacade` (global) usage. | Compile + logic verification |
| `app/workflow/action/backup/pit/enable/start_log_backup.go` | Remove `On3LayerArch` conditional if present | Compile |
| `app/workflow/action/backup/pit/disable/stop_log_backup.go` | Remove `On3LayerArch` conditional if present | Compile |
| `app/workflow/action/backup/pit/del/delete_log_backup_workload.go` | Remove `On3LayerArch` conditional if present | Compile |
| `app/workflow/action/backup/snapshot/del/delete_*.go` | Remove `On3LayerArch` conditional if present | Compile |
| `app/workflow/action/backup/snapshot/create/sync_cr_status.go` | Remove `On3LayerArch` conditional if present | Compile |
| **Restore actions** | | |
| `app/workflow/action/restore/create/base_running_restore.go` | Remove `RestoreFacade` (global) field. Rename `RestoreRegionalFacade` → `RestoreFacade`. Remove `On3LayerArch` conditional. | Compile |
| `app/workflow/action/restore/snapshot/create/running_restore.go` | Remove `On3LayerArch` conditional | Compile |
| `app/workflow/action/restore/pitr/create/running_restore.go` | Remove `On3LayerArch` conditional | Compile |
| `app/workflow/action/restore/del/delete_restore_in_infra.go` | Remove `restoreFacade` (global) field. Use only `restoreRegionalFacade`. | Compile |
| **5 Restore DAG files** | | |
| `app/workflow/dag/restore/restore_snapshot.go` | Remove `RestoreInfraFacade` parameter | Compile |
| `app/workflow/dag/restore/restore_pitr.go` | Same | Compile |
| `app/workflow/dag/restore/recycle_restore_snapshot.go` | Same | Compile |
| `app/workflow/dag/restore/recycle_restore_pitr.go` | Same | Compile |
| **Sync log backup** | | |
| `app/models/backup/impl/sync_log_backup_from_infra.go` | Remove `backupInfraFacade` field. Remove `On3LayerArch` conditional in `ExecTruncate` (use only regional). | Compile |
| **Health checker** | | |
| `app/models/backup/impl/backup_health_checker.go` | Remove `infraAPIClient` field and `ListNodeGroup`/`ListNodePool` calls in `CheckBackupNodeGroupAndNodePoolCleanUp`. This function becomes a no-op or should be removed. | Compile. Verify: is this health check still needed? |
| **Regional API** | | |
| `pkg/regional-api/br.go` | Remove `infraapi.GetInfraAPI().ListLogBackups()` call in `ListLogBackups()`. Only list from regional. Remove `IsolateLogBackup` no-op. Remove `RawCreateBackupCR` and `RawGetBackupCR` if only used by migration (BUT these are still on the BackupFacade interface and have regional impls — keep them). | Compile |
| **BackupFacade interface** | | |
| `pkg/infra-api/api.go` | Remove `IsolateLogBackup` from `BackupFacade` interface (line 162-164). Consider removing `RawCreateBackupCR`/`RawGetBackupCR` ONLY if no non-migration callers exist (verified: no other callers — but regional-api implements them, so keep for future use). | Compile |
| **BackupFacade global impl** | | |
| `pkg/infra-api/backup.go` | Remove `IsolateLogBackup` implementation. | Compile |
| **Model files** | | |
| `app/models/backup/impl/pit_backup.go` | Remove `On3LayerArch` flag setting (always true now) | Compile |
| `app/models/backup/impl/snapshot_backup.go` | Remove `On3LayerArch` flag setting (always true now) | Compile |
| `app/models/restore/impl/restore_base.go` | Remove `On3LayerArch` flag setting (always true now) | Compile |

### Files NOT to touch

| File | Reason |
|------|--------|
| `internal/service/connprofile/service.go` | Non-BR (DM) code |
| `internal/service/import/service.go` | Non-BR (Import) code |
| `internal/model/connprofile/api.go` | Non-BR code |
| `internal/model/dm/model.go` | Non-BR code |
| `internal/common/utils.go` | Non-BR code |
| `internal/container/container.go` | Non-BR code |
| `pkg/import-config/import_config.go` | Non-BR code |
| `app/models/dumpling/dumpling.go` | Non-BR (Dumpling) code |
| `app/models/dumpling/dumpling_worker.go` | Non-BR code |
| `app/event_bus/consumer/common/create_namespace.go` | Non-BR code |
| `app/event_bus/consumer/common/create_provider_config.go` | Non-BR code |
| `app/container/container.go` — `InfraAPIClient` field | Still used by Dumpling, event_bus consumers |
| `app/container/container.go` — `infraapi.GetInfraAPI()` line 309 | Still used by DumplingModel/DumplingWorker |

### Assumptions (Verifiable)

1. **All new BR operations use regional facade** — Since `On3LayerArch` is always set true for new backups/restores, the regional path is always taken. Removing the global fallback is safe.
2. **`InfraAPIClient` is still needed for non-BR** — Verified: Dumpling model, Dumpling worker, event_bus consumers use it. Field stays in container.
3. **`CheckBackupNodeGroupAndNodePoolCleanUp` may still be needed** — Need to verify if node group/pool cleanup is done via regional API now or if this is still the only path. If still needed, this function needs regional equivalent.
4. **`RawCreateBackupCR`/`RawGetBackupCR` on regional-api** — Keep these methods; they have real implementations in regional-api and may be used for future operations.
5. **Entity `On3LayerArch` field** — Keep in entity. All records have it set to true. It's harmless and other code may still reference it during the transition period.

### Steps

1. Edit all files listed above
2. Run `make generate4test` to regenerate mocks for modified interfaces
3. Run `make app-unit-test-local` to verify
4. Commit

---

## Verification Plan

After both commits:
1. `make build` — Ensure all binaries compile
2. `make app-unit-test-local` — Ensure all existing tests pass
3. `make lint` — Ensure no linting issues
4. Manual review of diffs to ensure no functional logic was accidentally removed
