Skip to content

CASSANALYTICS-142 : SidecarCdcClient should be passed as a constructor parameter for SidecarCdc to avoid thread/resource leaks#188

Merged
jyothsnakonisa merged 4 commits intoapache:trunkfrom
jyothsnakonisa:resource-leak
Mar 31, 2026
Merged

CASSANALYTICS-142 : SidecarCdcClient should be passed as a constructor parameter for SidecarCdc to avoid thread/resource leaks#188
jyothsnakonisa merged 4 commits intoapache:trunkfrom
jyothsnakonisa:resource-leak

Conversation

@jyothsnakonisa
Copy link
Copy Markdown
Contributor

No description provided.

…r parameter for SidecarCdc to avoid thread/resource leaks
Comment on lines 59 to 64
super(jobId, partitionId, eventConsumer, schemaSupplier);
this.clusterConfigProvider = clusterConfigProvider;
this.sidecarCdcClient = new SidecarCdcClient(clientConfig, sidecarInstancesProvider, secretsProvider, cdcStats);
withCdcOptions(cdcOptions);
withTokenRangeSupplier(tokenRangeSupplier);
}
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.

You should be able to reuse the other constructor.

        this(jobId, partitionId, cdcOptions, clusterConfigProvider, eventConsumer, schemaSupplier, tokenRangeSupplier, 
             new SidecarCdcClient(clientConfig, sidecarInstancesProvider, secretsProvider, cdcStats), 
             cdcStats);

However, the real question is: why do we need the constructor that creates SidecarCdcClient? We want to share the global SidecarCdcClient instance.

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.

We want the SidecarCdcClient object to be singleton created in the Sidecar process and it should be shared across all the SidecarCdc instances which are CDC iterators.

I have added this new constructor to take sidecarCdcClient object as parameter so that we can have singleton object and can pass it to all iterators to avoid creating one sidecarCdcClient instance per iterator.

If we have the SidecarCdcClient creation inside the constructor, then on token range change when new iterator is created a new SidecarCdcClient is created, which we want to avoid.

Comment on lines 53 to 76
@@ -75,6 +75,27 @@ public static SidecarCdcBuilder builder(@NotNull String jobId,
cdcStats);
}
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.

Do we still need this build? Please remove it if it is no longer needed. One reason for removal is that the builder path creates a new sidecar cdc client.

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.

good catch, this is no longer needed and we should remove it as the builder path creates new SidecarCdcClient.

I also think, we should remove the constructor which creates new SidecarCdcClient in the constructor.

@jyothsnakonisa jyothsnakonisa merged commit dfface1 into apache:trunk Mar 31, 2026
90 of 95 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