Skip to content

feat(search-index): add command to clean up unused indices#391

Open
cancan101 wants to merge 7 commits into
pimcore:2026.xfrom
cancan101:feature/cleaup
Open

feat(search-index): add command to clean up unused indices#391
cancan101 wants to merge 7 commits into
pimcore:2026.xfrom
cancan101:feature/cleaup

Conversation

@cancan101

Copy link
Copy Markdown
Contributor
  • 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

Changes in this pull request

Resolves #382

Additional info

@sonarqubecloud

sonarqubecloud Bot commented Feb 8, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-indices command with --dry-run mode.
  • Implemented UnusedIndexCleanupService to 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.

Comment thread src/Command/CleanupUnusedIndicesCommand.php
Comment thread src/Command/CleanupUnusedIndicesCommand.php Outdated
Comment thread src/Command/CleanupUnusedIndicesCommand.php
Comment thread src/Service/SearchIndex/UnusedIndexCleanupService.php
Comment thread src/Service/SearchIndex/UnusedIndexCleanupService.php
Comment thread doc/02_Configuration/03_Index_Management.md
Comment thread src/Command/CleanupUnusedIndicesCommand.php
cancan101 and others added 4 commits June 29, 2026 15:48
- 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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/Service/SearchIndex/UnusedIndexCleanupService.php Outdated
Comment thread src/Service/SearchIndex/UnusedIndexCleanupService.php
- 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

…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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/SearchIndexAdapter/SearchIndexServiceInterface.php
@kingjia90 kingjia90 modified the milestones: 2026.2.1, 2026.3.0 Jul 2, 2026
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
@sonarqubecloud

sonarqubecloud Bot commented Jul 2, 2026

Copy link
Copy Markdown

@kingjia90

Copy link
Copy Markdown
Contributor

@cancan101 could you please have a look on the latest changes and see if it's still working as intended? TIA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Duplicate Indices (even vs odd) - not cleaned up on reindex

7 participants