Skip to content

CMR-11271: Fix Cascade collection delete does not delete from index-set when index is separate from small_collections - #2474

Open
jaortega527 wants to merge 9 commits into
masterfrom
CMR-11271
Open

CMR-11271: Fix Cascade collection delete does not delete from index-set when index is separate from small_collections#2474
jaortega527 wants to merge 9 commits into
masterfrom
CMR-11271

Conversation

@jaortega527

Copy link
Copy Markdown
Contributor

Overview

What is the objective?

Ensure that deleting a collection with a separate granule index also removes the corresponding mapping from the index set, avoiding recreation of deleted indexes and preventing invalid rebalancing attempts.

What are the changes?

  • Added HTTP status information for individual granule-index deletions in delete-granule-index. Added unit tests to confirm behavior.
  • Updated cascade-collection-delete to remove the index-set mapping only when ES returns 200 or 404. If the underlying index deletion in ES fails, the index-set is not updated. Added unit tests to confirm behavior.
  • Added remove-collection-granule-index-if-exists to remove and persist the deletion of the of the separate granule-index mapping. It also handles missing mappings and collections included in small_collections. Added unit tests to confirm behavior.
  • Added integration test to verify that separate index is deleted when cascade-collection-delete is called
  • Added integration test to verify that a deleted collection does not rebalance after its separate index mapping is removed

What areas of the application does this impact?

  • indexer-app
  • system-int-test

Required Checklist

  • New and existing unit and int tests pass locally and remotely
  • clj-kondo has been run locally and all errors in changed files are corrected
  • I have commented my code, particularly in hard-to-understand areas
  • I have made changes to the documentation (if necessary)
  • My changes generate no new warnings

Additional Checklist

  • I have removed unnecessary/dead code and imports in files I have changed
  • I have cleaned up integration tests by doing one or more of the following:
    • migrated any are2 tests to are3 in files I have changed
    • de-duped, consolidated, removed dead int tests
    • transformed applicable int tests into unit tests
    • reduced number of system state resets by updating fixtures. Ex) (use-fixtures :each (ingest/reset-fixture {})) to be :once instead of :each

@codecov-commenter

codecov-commenter commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 4.16667% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.52%. Comparing base (ec7813e) to head (d5b4003).

Files with missing lines Patch % Lines
...app/src/cmr/indexer/services/index_set_service.clj 8.33% 11 Missing ⚠️
...xer-app/src/cmr/indexer/services/index_service.clj 0.00% 7 Missing ⚠️
indexer-app/src/cmr/indexer/data/elasticsearch.clj 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2474      +/-   ##
==========================================
- Coverage   27.28%   25.52%   -1.77%     
==========================================
  Files        1013     1013              
  Lines       71208    71226      +18     
  Branches     1139     1047      -92     
==========================================
- Hits        19426    18177    -1249     
- Misses      50645    52002    +1357     
+ Partials     1137     1047      -90     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

(is (= @validate-arg (:index-set @update-args)))
(is (= 33 (:revision-id @update-args))))))))

(deftest delete-index-set-indices-gates-index-set-doc-delete-on-200-status

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.

this wording confuses me

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. These tests weren't intended to be included. The change to the delete-index-set-indices method is not necessary for CMR-11271 and was an artifact of an early attempt to address CMR-11271. the change to delete-index-set-indices has been removed.

(is (= 33 (:revision-id @update-args))))))))

(deftest delete-index-set-indices-gates-index-set-doc-delete-on-200-status
(testing "deletes index-set document when all index deletes return 200"

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.

what does this mean? What is an index-set document? Only ES has documents

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changes were reverted.

es/delete-index (fn [_ _] {:status 200})
es/delete-document (fn [& _] (reset! delete-document-called? true))]
(#'svc/delete-index-set-indices {} 1 es-config/elastic-name)
(is (true? @delete-document-called?)))))

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.

are you double checking that the elastid delete-document is called when we delete-index?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changes were reverted

config/idx-cfg-for-index-sets (fn [_] {:index-name "index-sets" :mapping {:index-set {}}})
indexer-util/context->es-store (fn [_ _] {})
es/delete-index (fn [_ index-name]
(if (= index-name "1_c123_prov")

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.

this test will have one valid and one non-valid deletion? Since 1_c123_prov will return 200 and that's a deletion

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changes were reverted

java.lang.Exception
#"index delete operation failed"
(#'svc/delete-index-set-indices {} 1 es-config/elastic-name)))
(is (false? @delete-document-called?)))))) No newline at end of file

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.

new line needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changes were reverted

{:status 200})

:else
(let [updated-gran-index-set (remove-granule-index-from-index-set gran-index-set concept-id)]

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.

if we fall into this case, will it return a status similar to the other cases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

change was reverted

- collection has no explicit granule index mapping in the index-set
- collection currently maps to the small_collections index"
[context concept-id]
(let [index-set-id index-set/index-set-id

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.

we have the ability to create index-sets with other id numbers, if so, then this func will not work on them. I suggest we put the index-set-id as a func param to make this more flexible

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated remove-collection-granule-index-if-exists adding index-set-id as a parameter. When the function is called it uses the index-set-service/index-set-id as the value for the index-set-id.

(info (format "No separate granule index mapping found for collection [%s]; skipping index-set cleanup." concept-id))
{:status 200})

(= mapped-index small-collections-index)

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.

I don't think this will ever happen. IF concept-id is truly only a concept-id, it will be c_1234 format, therefore collection-key = :c_1234 and then mapped-index will look for that key

ALSO, the format translation between concept-id and the actual key used in concepts granule map is DIFFERENT and changes based on resharded vs orig index AND orig index and mapped index.

Please look at PROD's index-set to get an example of how these formats are different

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated remove-collection-granule-index-if-exists to use the collection-ids-from-granule-indexes helper to determine if the collection has a separate index configuration. Also removed the check on whether the mapped-index is the small-collection-index.

(dorun (map #(es/delete-index (indexer-util/context->es-store context es-cluster-name) %) index-names))
(es/delete-document context index-name idx-mapping-type index-set-id es-cluster-name)))
idx-mapping-type (first (keys mapping))
delete-responses (keep #(es/delete-index (indexer-util/context->es-store context es-cluster-name) %) index-names)

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.

es/delete-index already check for 200 status and throws an internal-error, why are we doing the check here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This change to the delete-index-set-indices method is not necessary for CMR-11271 and was an artifact of an early attempt to address CMR-11271. the change to delete-index-set-indices has been removed.

(let [resp (es/delete-granule-index context index)
status (get resp :status)]
(if (contains? #{200 404} status)
(vreset! deleted-separate-index? true)

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.

why do we have this new additional step here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Modified to call remove-collection-granule-index-if-exists immediately after the status of the delete-granule-index call is confirmed to be 200 or 404.

…anule index from index-set if it is a separate index and not in small_cllections
…llections-test to expect the 400 error returned because the deleted index no longer has an entry in the index-set
… the existing delete-index-set-indices behavior and remove its associated tests. These changes were unintentionally included and are outside the scope of the collection granule index-set cleanup.
…on-granule-index-if-exists once we confirm the status from the call to delete-granule-index is 200 or 404
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants