Skip to content

fix: Handle CDC race condition when vertex deleted before event processed - #17

Merged
pallakartheekreddy merged 1 commit into
Sunbird-Knowlg:developfrom
aimansharief:fix/cdc-race-condition-vertex-deletion
May 26, 2026
Merged

fix: Handle CDC race condition when vertex deleted before event processed#17
pallakartheekreddy merged 1 commit into
Sunbird-Knowlg:developfrom
aimansharief:fix/cdc-race-condition-vertex-deletion

Conversation

@aimansharief

@aimansharief aimansharief commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a CDC race condition during the second publish cycle where updateProcessingNode transaction events are processed after the image node (.img) has been deleted by a subsequent deleteNode transaction.

Problem

During publish, two transactions execute in quick succession on the image node:

  1. updateProcessingNode — writes status Review → Processing (full property rewrite)
  2. deleteNode — removes the .img vertex entirely

CDC processes transaction log entries asynchronously. When it processes the updateProcessingNode event after the vertex is already deleted:

  • vertex.properties() returns defaults (vertex gone)
  • vertex.label() returns "vertex" (TinkerPop default)
  • vertex.id().toString() returns internal graph ID (e.g. "1024004192") instead of do_xxx.img

This produces garbage events with objectType: "vertex" and numeric nodeUniqueId, causing the downstream transaction-event-processor to crash with:

FileNotFoundException: schemas/local/vertex/1.0/schema.json

Fix

For UPDATE events, derived fields (objectType, nodeUniqueId, channel, nodeType, label, userId) are now read from propertiesMap (transaction log data) first, falling back to vertex state only if not present in the transaction.

  • propertiesMap is built from ChangeState (immutable transaction log) — always accurate regardless of current vertex state
  • Added getFromPropertiesOrVertex() helper and refactored getLabelFromPropertiesOrVertex() / getUserIdFromPropertiesOrVertex() to reuse it
  • Extracted LABEL_KEYS and USER_ID_KEYS as static constants

Safety net: Events with objectType="vertex" (no IL_FUNC_OBJECT_TYPE set) are filtered out and return null — CDC skips them entirely.

Event flow (before vs after fix)

Before:  updateProcessingNode TX → vertex deleted → CDC reads vertex → objectType="vertex", nodeUniqueId="1024004192" → CRASH
After:   updateProcessingNode TX → vertex deleted → CDC reads propertiesMap → objectType="CollectionImage", nodeUniqueId from TX log → OK

Note: A companion fix in knowledge-platform-jobs (ObjectUpdater.scala) adds IL_UNIQUE_ID to the updateProcessingNode metadata map, ensuring nodeUniqueId is always available in propertiesMap even when the vertex is deleted.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Deployed to test environment and ran full second publish cycle (Create → Review → Publish → Update → Review → Publish)
  • Verified CDC events have correct objectType and nodeUniqueId for image node transactions
  • Verified transaction-event-processor no longer crashes with vertex schema error
  • Verified first publish cycle (no image node) unaffected

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

…ssed

  For UPDATE events, read derived fields (objectType, nodeUniqueId, channel,
  etc.) from transaction log (propertiesMap) first, falling back to vertex
  state. Prevents garbage "vertex" events when image node is deleted by
  publish job before CDC processes the updateProcessingNode transaction.

  Also filters events with objectType="vertex" (no IL_FUNC_OBJECT_TYPE set)
  to prevent downstream transaction processor crashes on missing schema.
@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0a4f275f-bdf1-4404-a859-d28a9d6c73a7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pallakartheekreddy
pallakartheekreddy merged commit 67a923f into Sunbird-Knowlg:develop May 26, 2026
1 of 2 checks passed
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.

2 participants