Skip to content

Comments

Introduce a default liveness-interval value when config is not present#27

Merged
ayeshLK merged 3 commits intoballerina-platform:mainfrom
ayeshLK:main
Feb 15, 2026
Merged

Introduce a default liveness-interval value when config is not present#27
ayeshLK merged 3 commits intoballerina-platform:mainfrom
ayeshLK:main

Conversation

@ayeshLK
Copy link
Member

@ayeshLK ayeshLK commented Feb 14, 2026

Purpose

$subject

Part of: ballerina-platform/ballerina-library#8589

Summary

This PR introduces a default liveness-interval value for the CDC listener when configuration is not explicitly provided, improving operational resilience and reducing the need for mandatory configuration.

Changes

Modified: native/src/main/java/io/ballerina/lib/cdc/Listener.java

  • Added a default liveness interval constant of 60 seconds (60000 milliseconds)
  • Updated the listener startup logic to use the default liveness interval when the configuration key is not present
  • Refactored configuration key visibility from public to private, reducing the public API surface while maintaining internal functionality
  • Net change: +17/-9 lines

Impact

The CDC listener now has sensible built-in defaults for liveness checks, ensuring consistent heartbeat behavior without requiring explicit configuration. This improves the usability and reliability of the module in typical deployment scenarios.

@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2026

📝 Walkthrough

Walkthrough

The Listener class constants are refactored to reduce public exposure. Four configuration-related keys and one config key are changed from public to private visibility, while retaining public access for shared state keys. A default liveness interval constant is introduced with conditional logic to apply defaults when configuration is missing.

Changes

Cohort / File(s) Summary
Listener Configuration Keys
native/src/main/java/io/ballerina/lib/cdc/Listener.java
Converted public constants CHANGE_CONSUMER_KEY, COMP_CALLBACK_KEY, LIVENESS_INTERVAL_KEY, LISTENER_START_TIME_KEY, and LIVENESS_INTERVAL_CONFIG_KEY to private visibility. Added private DEFAULT_LIVENESS_INTERVAL_MILLIS constant (60000ms) and updated start() method to apply default liveness interval when configuration key is absent. Retained public visibility for shared state constants (TABLE_TO_SERVICE_MAP_KEY, DEBEZIUM_ENGINE_KEY, EXECUTOR_SERVICE_KEY, IS_STARTED_KEY, HAS_ATTACHED_SERVICE_KEY, LISTENER_ID).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Constants tucked safely inside,
Private walls now provide
A cozy default to confide,
Clean encapsulation with pride! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 3
❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (1 file):

⚔️ native/src/main/java/io/ballerina/lib/cdc/Listener.java (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
Description check ❓ Inconclusive The description is incomplete. While it mentions the purpose and linked issue, it lacks details and several required template sections like Examples and Checklist are missing. Complete the description by filling the Examples section and adding the Checklist items, particularly noting if tests and changelog were updated.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: making liveness-interval configuration optional with a default value when not provided.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch main
  • Post resolved changes as copyable diffs in a comment

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@native/src/main/java/io/ballerina/lib/cdc/Listener.java`:
- Around line 167-175: The livenessInterval assignment in Listener (the block
reading LIVENESS_INTERVAL_CONFIG_KEY from config) must validate that
config.get(LIVENESS_INTERVAL_CONFIG_KEY) is non-null and an instance of BDecimal
before casting, and reject non-positive values; change the logic that sets
livenessInterval to first fetch Object val =
config.get(LIVENESS_INTERVAL_CONFIG_KEY), if val == null use
DEFAULT_LIVENESS_INTERVAL_MILLIS, else if val instanceof BDecimal convert via
((BDecimal) val).decimalValue().multiply(BigDecimal.valueOf(1000)).longValue()
and if the resulting long <= 0 throw an IllegalArgumentException (or
Ballerina-specific error) with a clear message referencing
LIVENESS_INTERVAL_CONFIG_KEY, otherwise assign it, and if val is not a BDecimal
throw a similar informative error instead of allowing a ClassCastException.

Comment on lines +167 to +175
Long livenessInterval;
if (config.containsKey(LIVENESS_INTERVAL_CONFIG_KEY)) {
livenessInterval = ((BDecimal) config.get(LIVENESS_INTERVAL_CONFIG_KEY))
.decimalValue()
.multiply(BigDecimal.valueOf(1000))
.longValue();
} else {
livenessInterval = DEFAULT_LIVENESS_INTERVAL_MILLIS;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Validate livenessInterval value before casting.

If the key exists but is null or not a BDecimal, this will throw at runtime. Also consider rejecting non‑positive values to avoid immediate liveness failures.

✅ Suggested guard with explicit error
-            Long livenessInterval;
-            if (config.containsKey(LIVENESS_INTERVAL_CONFIG_KEY)) {
-                livenessInterval = ((BDecimal) config.get(LIVENESS_INTERVAL_CONFIG_KEY))
-                        .decimalValue()
-                        .multiply(BigDecimal.valueOf(1000))
-                        .longValue();
-            } else {
-                livenessInterval = DEFAULT_LIVENESS_INTERVAL_MILLIS;
-            }
+            Long livenessInterval = DEFAULT_LIVENESS_INTERVAL_MILLIS;
+            if (config.containsKey(LIVENESS_INTERVAL_CONFIG_KEY)) {
+                Object rawInterval = config.get(LIVENESS_INTERVAL_CONFIG_KEY);
+                if (!(rawInterval instanceof BDecimal)) {
+                    return createCdcError("'livenessInterval' must be a decimal number");
+                }
+                long computedMillis = ((BDecimal) rawInterval).decimalValue()
+                        .multiply(BigDecimal.valueOf(1000))
+                        .longValue();
+                if (computedMillis <= 0) {
+                    return createCdcError("'livenessInterval' must be > 0");
+                }
+                livenessInterval = computedMillis;
+            }
🤖 Prompt for AI Agents
In `@native/src/main/java/io/ballerina/lib/cdc/Listener.java` around lines 167 -
175, The livenessInterval assignment in Listener (the block reading
LIVENESS_INTERVAL_CONFIG_KEY from config) must validate that
config.get(LIVENESS_INTERVAL_CONFIG_KEY) is non-null and an instance of BDecimal
before casting, and reject non-positive values; change the logic that sets
livenessInterval to first fetch Object val =
config.get(LIVENESS_INTERVAL_CONFIG_KEY), if val == null use
DEFAULT_LIVENESS_INTERVAL_MILLIS, else if val instanceof BDecimal convert via
((BDecimal) val).decimalValue().multiply(BigDecimal.valueOf(1000)).longValue()
and if the resulting long <= 0 throw an IllegalArgumentException (or
Ballerina-specific error) with a clear message referencing
LIVENESS_INTERVAL_CONFIG_KEY, otherwise assign it, and if val is not a BDecimal
throw a similar informative error instead of allowing a ClassCastException.

@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.56%. Comparing base (b60295c) to head (9fcef4d).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...e/src/main/java/io/ballerina/lib/cdc/Listener.java 71.42% 1 Missing and 1 partial ⚠️

❌ Your project status has failed because the head coverage (76.56%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##               main      #27      +/-   ##
============================================
- Coverage     76.70%   76.56%   -0.15%     
  Complexity      224      224              
============================================
  Files            30       30              
  Lines          1082     1084       +2     
  Branches        169      170       +1     
============================================
  Hits            830      830              
- Misses          175      176       +1     
- Partials         77       78       +1     

☔ View full report in Codecov by Sentry.
📢 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.

@ayeshLK ayeshLK merged commit c241584 into ballerina-platform:main Feb 15, 2026
4 of 6 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