feat(search-index): add command to clean up unused indices#391
feat(search-index): add command to clean up unused indices#391cancan101 wants to merge 7 commits into
Conversation
|
There was a problem hiding this comment.
Pull request overview
This PR introduces a new CLI command and supporting service to identify and remove stale Generic Data Index -odd/-even indices that are no longer referenced by any alias, addressing the duplicate-index buildup described in #382.
Changes:
- Added
generic-data-index:cleanup:unused-indicescommand with--dry-runmode. - Implemented
UnusedIndexCleanupServiceto compute unused managed indices via prefix filtering + alias diff and optionally delete them. - Added unit tests for selection logic and dry-run vs execute behavior; documented the new command.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
tests/Unit/Service/SearchIndex/UnusedIndexCleanupServiceTest.php |
Adds unit tests for unused-index discovery and dry-run/execute deletion behavior. |
src/Service/SearchIndex/UnusedIndexCleanupService.php |
Implements discovery and deletion of unused managed (-odd/-even) indices based on stats + alias list. |
src/Command/CleanupUnusedIndicesCommand.php |
Adds a new console command to run cleanup and optionally dry-run output. |
doc/02_Configuration/03_Index_Management.md |
Documents the new cleanup command and --dry-run option. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- add generic-data-index:cleanup:unused-indices command - default behavior deletes unmanaged stale -odd/-even indices not referenced by aliases - add --dry-run option to preview deletions without changes - implement UnusedIndexCleanupService to detect candidates via prefix + alias diff - add unit tests for selection, dry-run, and execute behavior - document new cleanup command in index management docs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: JiaJia Ji <kingjia90@gmail.com>
Add generic-data-index:cleanup:unused-indices to the console commands overview table and document the command under a new "Cleaning Up Unused Indices" section in Deployment and Index Management. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
e5963ba to
3a95672
Compare
- Register UnusedIndexCleanupService in config/services/search/index.yaml so the cleanup command can be instantiated by the container (services are registered explicitly; src/Service/* is not auto-registered). - Stop swallowing exceptions from SearchIndexServiceInterface::getStats() in getAllManagedIndices(); let them propagate so a search-engine outage is reported as a failure instead of looking like "no unused indices found". - Warn (command help + docs) that the command must not run during a reindex, since the new -odd/-even index is created and populated before it is attached to its alias and would otherwise be classified as unused and deleted. - Add unit tests covering exception propagation and the empty-prefix guard. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HerStxf8JeBW5Y3Lb63Sbz
…use index version constants, lighter index listing - Protect against deleting an index that a concurrent reindex is actively building: indices younger than --min-age seconds (default 86400) or with an unknown creation date are never considered unused. --min-age=0 disables the guard. - Build the -odd/-even suffix pattern from DefaultSearchService::INDEX_VERSION_ODD/EVEN instead of hardcoding it. - List managed indices via a new SearchIndexServiceInterface::getIndexSettings() (wildcard _settings call, which also provides creation dates) instead of the heavier _stats API. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Split the --min-age option description, the command description, and the help text across concatenated string literals so no line exceeds 120 characters. The resulting strings are byte-identical, so command output is unchanged. Fixes the four SonarCloud "Split this long line" major issues on src/Command/CleanupUnusedIndicesCommand.php (lines 57, 61, 64, 65). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HerStxf8JeBW5Y3Lb63Sbz
|
|
@cancan101 could you please have a look on the latest changes and see if it's still working as intended? TIA |



Changes in this pull request
Resolves #382
Additional info