Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUMULUS-3243:Updated granule delete logic #3338

Merged
merged 4 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## Unreleased

## [v15.0.x]

- **CUMULUS-3243**
- Updated granule delete logic to delete granule which is not in DynamoDB

## [v15.0.0] 2023-03-10

### Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion example/lambdas/python-reference-task/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cp ./*.py ./dist/

cd ./dist || exit 1

find . -type f -print0 | xargs -0 node ../../../../bin/zip.js lambda.zip $(ls | grep -v lambda.zip)
node ../../../../bin/zip.js lambda.zip $(ls | grep -v lambda.zip)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The change is already in master branch


cd .. || exit 1

Expand Down
4 changes: 2 additions & 2 deletions packages/api/lib/granule-remove-from-cmr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { GranuleNotPublished } = require('@cumulus/errors');
const { CMR } = require('@cumulus/cmr-client');
const log = require('@cumulus/common/log');
const {
Expand Down Expand Up @@ -29,7 +28,8 @@ const models = require('../models');
const _removeGranuleFromCmr = async (granule, collectionId) => {
log.info(`granules.removeGranuleFromCmrByGranule granule_id: ${granule.granule_id}, colletion_id: ${collectionId}`);
if (!granule.published || !granule.cmr_link) {
throw new GranuleNotPublished(`Granule ${granule.granule_id} in Collection ${collectionId} is not published to CMR, so cannot be removed from CMR`);
log.info(`Granule ${granule.granule_id} in Collection ${collectionId} is not published to CMR, so cannot be removed from CMR`);
return;
}

const cmrSettings = await cmrjsCmrUtils.getCmrSettings();
Expand Down
14 changes: 14 additions & 0 deletions packages/api/models/granules.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
DeletePublishedGranule,
ValidationError,
} = require('@cumulus/errors');
const { RecordDoesNotExist } = require('@cumulus/errors');
const {
generateMoveFileParams,
} = require('@cumulus/ingest/granule');
Expand Down Expand Up @@ -482,6 +483,19 @@ class Granule extends Manager {
}
return executionDescription;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When granule is not in dynamoDB, unpublish has error:
2023-04-18T15:46:33.756Z 489c96c9-fec7-411c-84b4-eac0df058c41 ERROR
{ "error": { "name": "RecordDoesNotExist", "message": "No record found for {"granuleId":"MOD09GQ.A7614271.S4rfYb.006.4748017559580"} in jl-tf-GranulesTable", "stack": [ "RecordDoesNotExist: No record found for {"granuleId":"MOD09GQ.A7614271.S4rfYb.006.4748017559580"} in jl-tf-GranulesTable", " at Object.get (/var/task/webpack:/src/DynamoDb.ts:63:9)", " at processTicksAndRejections (node:internal/process/task_queues:96:5)", " at Granule.get (/var/task/webpack:/models/base.js:228:12)", " at Granule.get (/var/task/webpack:/models/granules.js:88:29)", " at Granule.update (/var/task/webpack:/models/base.js:372:25)", " at /var/task/webpack:/lib/granule-remove-from-cmr.js:95:29" ] }, "level": "error", "message": "No record found for {"granuleId":"MOD09GQ.A7614271.S4rfYb.006.4748017559580"} in jl-tf-GranulesTable", "sender": "@cumulus/api", "timestamp": "2023-04-18T15:46:33.756Z" }

async update(itemKeys, updates = {}, fieldsToDelete = []) {
let granule;
try {
granule = await super.update(itemKeys, updates, fieldsToDelete);
} catch (error) {
if (!(error instanceof RecordDoesNotExist)) {
throw error;
}
logger.info(`Granule record ${JSON.stringify(itemKeys)} does not exist.`);
}
return granule;
}
}

module.exports = Granule;
10 changes: 6 additions & 4 deletions packages/api/src/lib/granule-delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ const deleteGranuleAndFiles = async (params: {
await granulePgModel.delete(trx, {
cumulus_id: pgGranule.cumulus_id,
});
await granuleModelClient.delete(dynamoGranule);
if (dynamoGranule) {
await granuleModelClient.delete(dynamoGranule);
}
await deleteGranule({
esClient,
granuleId: dynamoGranule.granuleId,
collectionId: dynamoGranule.collectionId,
granuleId: pgGranule.granule_id,
collectionId: granuleToPublishToSns.collectionId,
index: process.env.ES_INDEX,
ignore: [404],
});
Expand All @@ -145,7 +147,7 @@ const deleteGranuleAndFiles = async (params: {
deletedFiles: files,
};
} catch (error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When granule is not in dynamoDB, delete has error:
{ "error": { "name": "TypeError", "message": "Cannot read properties of undefined (reading 'files')", "stack": [ "TypeError: Cannot read properties of undefined (reading 'files')", " at deleteGranuleAndFiles (/var/task/webpack:/granule-delete.ts:148:119)", " at processTicksAndRejections (node:internal/process/task_queues:96:5)", " at del (/var/task/webpack:/endpoints/granules.js:551:27)" ] }, "level": "error", "message": "Cannot read properties of undefined (reading 'files')", "sender": "@cumulus/api", "timestamp": "2023-04-18T20:35:10.277Z" }

logger.debug(`Error deleting granule with ID ${pgGranule.granule_id} or S3 files ${JSON.stringify(dynamoGranule.files)}: ${JSON.stringify(error)}`);
logger.debug(`Error deleting granule with ID ${pgGranule.granule_id} or S3 files ${JSON.stringify(files)}: ${JSON.stringify(error)}`);
// Delete is idempotent, so there may not be a DynamoDB
// record to recreate
if (dynamoGranule) {
Expand Down