Skip to content

KAFKA-4794: Add access to OffsetStorageReader from SourceConnector#2604

Merged
rhauch merged 5 commits intoapache:trunkfrom
fhussonnois:KAFKA-4794
May 25, 2020
Merged

KAFKA-4794: Add access to OffsetStorageReader from SourceConnector#2604
rhauch merged 5 commits intoapache:trunkfrom
fhussonnois:KAFKA-4794

Conversation

@fhussonnois
Copy link
Copy Markdown
Contributor

@fhussonnois fhussonnois commented Feb 27, 2017

This a first attempt to implement Add access to OffsetStorageReader from Source Connector.
I am not sure if I did it right so I prefer to ask you your feedback. I still need to write some tests.

@asfbot
Copy link
Copy Markdown

asfbot commented Feb 27, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.11/1867/
Test PASSed (JDK 8 and Scala 2.11).

@asfbot
Copy link
Copy Markdown

asfbot commented Feb 27, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk7-scala2.10/1864/
Test PASSed (JDK 7 and Scala 2.10).

@asfbot
Copy link
Copy Markdown

asfbot commented Feb 27, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/kafka-pr-jdk8-scala2.12/1865/
Test PASSed (JDK 8 and Scala 2.12).

@hleb-albau
Copy link
Copy Markdown

Will this path be merged?

@fhussonnois
Copy link
Copy Markdown
Contributor Author

Hi @rhauch, this PR has been updated regarding the KIP-131

rhauch
rhauch previously requested changes Sep 5, 2017
Copy link
Copy Markdown
Contributor

@rhauch rhauch left a comment

Choose a reason for hiding this comment

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

Looks great, @fhussonnois! I do have a few specific requests, but all are pretty minor.

Comment thread connect/api/src/main/java/org/apache/kafka/connect/connector/Connector.java Outdated
Comment thread connect/api/src/main/java/org/apache/kafka/connect/sink/SinkConnector.java Outdated
Comment thread connect/api/src/main/java/org/apache/kafka/connect/source/SourceConnector.java Outdated
Comment thread connect/api/src/main/java/org/apache/kafka/connect/sink/SinkConnectorContext.java Outdated
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.

Is it possible to trigger infinite loop:

raiseError -> reconfig -> raiseError -> reconfig ...

@fhussonnois
Copy link
Copy Markdown
Contributor Author

fhussonnois commented Sep 5, 2017

Thank you @rhauch for your comments. I've updated the PR.

Comment thread connect/api/src/main/java/org/apache/kafka/connect/connector/Connector.java Outdated
@fhussonnois
Copy link
Copy Markdown
Contributor Author

@rhauch is there anything I should add or modify for the PR ?

@rhauch
Copy link
Copy Markdown
Contributor

rhauch commented Sep 7, 2017

@fhussonnois, I just submitted the KIP for a vote, which will be open for a few days. This can be merged once that is approved.

@frankcoutinho
Copy link
Copy Markdown

I also needed this feature. #feelsbad

@rhauch
Copy link
Copy Markdown
Contributor

rhauch commented Mar 5, 2020

@fhussonnois, would you mind updating this PR to eliminate the conflicts?

Also, while I hope to get this into AK 2.6, the KIP hasn't yet passed. I did make a suggestion on the vote thread, though, to consider making it much easier for connectors that want to also run in older versions of Connect to easily get the OffsetStorageReader when Connect supports it without jumping through a lot of ugly hoops.

@rhauch
Copy link
Copy Markdown
Contributor

rhauch commented May 6, 2020

ok to test

Copy link
Copy Markdown
Contributor

@rhauch rhauch left a comment

Choose a reason for hiding this comment

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

Thanks, @fhussonnois. I have a few more suggestions to clean up the implementation a bit more, to improve backward compatibility, and to ensure the new code is adequately tested.

Comment on lines 90 to 94
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.

At one point these were anonymous classes, and the delegation perhaps made a bit more sense. Now that they are inner classes, it seems like it would be a lot less confusing and simpler if the DelegateToWorkerConnectorContext class were extended by the DelegateSinkConnectorContext and DelegateSourceConnectorContext classes. Doing this has several advantages:

  1. removes nesting/delegation and eliminates the chance of getting into an infinite loop
  2. eliminates duplicate code in these classes
  3. simplifies the context classes quite a bit
  4. makes it more obvious that the sink connector context has nothing extra over the base
  5. makes it more obvious that the source connector context only adds the offset storage reader
  6. simplifies this code a bit (see below)

By keeping DelegateToWorkerConnectorContext class non-abstract, we're actually able to maintain backward compatibility by calling initialize when the connector class is neither a source or sink connector:

This code becomes simpler, too:

Suggested change
final ConnectorContext delegateCtx = new DelegateToWorkerConnectorContext();
if (isSinkConnector()) {
SinkConnectorConfig.validate(config);
connector.initialize(new DelegateSinkConnectorContext(delegateCtx));
} else {
connector.initialize(new DelegateSourceConnectorContext(delegateCtx, offsetStorageReader));
}
if (isSinkConnector()) {
SinkConnectorConfig.validate(config);
connector.initialize(new DelegateSinkConnectorContext());
} else if (isSourceConnector()) {
connector.initialize(new DelegateSourceConnectorContext(offsetStorageReader));
} else {
connector.initialize(new DelegateToWorkerConnectorContext());
}

This seems a little strange, but we're actually not checking whether the Connector instance passed into this WorkerConnector is only an instance of SourceConnector or SinkConnector. If it is neither, prior to this change the framework would still initialize it, and I think we should maintain that arguably strange behavior just to maintain backward compatibility.

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.

Nit: let's avoid unrelated line additions.

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.

Nit: let's avoid unrelated line additions.

Comment thread connect/api/src/main/java/org/apache/kafka/connect/sink/SinkConnector.java Outdated
@rhauch
Copy link
Copy Markdown
Contributor

rhauch commented May 21, 2020

retest this please

@rhauch
Copy link
Copy Markdown
Contributor

rhauch commented May 21, 2020

ok to test

@rhauch rhauch dismissed their stale review May 21, 2020 23:14

Added commits to make the requested changes

Copy link
Copy Markdown
Contributor

@rhauch rhauch left a comment

Choose a reason for hiding this comment

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

@fhussonnois, thanks again for doing the brunt of the work on this feature. We're getting close to AK 2.6.0 feature freeze, and it'd be great to merge this feature now that KIP-131 has been adopted. Since my previous review was some time ago, I hope you don't mind that I pushed the remaining changes I suggested in my previous review. I've also dismissed my previous "Request Changes" review.

@kkonstantine would you mind taking a look? I'd like to have an independent review of my changes. Thanks!

@rhauch rhauch requested a review from kkonstantine May 21, 2020 23:16
@fhussonnois
Copy link
Copy Markdown
Contributor Author

@rhauch thank you very much for finalizing this PR; I apologize for not finding any free time to work on it these past few weeks.

@rhauch
Copy link
Copy Markdown
Contributor

rhauch commented May 23, 2020

retest this please

@rhauch
Copy link
Copy Markdown
Contributor

rhauch commented May 24, 2020

Just one failure in each of the 3 builds, and none were in Connect unit or integration tests.

Copy link
Copy Markdown
Contributor

@kkonstantine kkonstantine left a comment

Choose a reason for hiding this comment

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

Thanks for the original contribution and the KIP @fhussonnois

@rhauch thanks for completing this PR. Overall looks good. I have a few minor comments and then I think that maybe we shouldn't plan for a connector implementation that is not a sink or a source in the tests. The code would break elsewhere anyways, and this is not supported by they framework today. Wdyt?

Comment thread connect/api/src/test/java/org/apache/kafka/connect/connector/ConnectorTest.java Outdated
Comment thread connect/api/src/main/java/org/apache/kafka/connect/sink/SinkConnector.java Outdated
Comment thread connect/api/src/main/java/org/apache/kafka/connect/source/SourceConnector.java Outdated
fhussonnois and others added 5 commits May 24, 2020 11:34
Add two interfaces SinkConnectorContext/SourceConnectContext that extend ConnectorContext in order to expose an OffsetStorageReader instance.
@rhauch
Copy link
Copy Markdown
Contributor

rhauch commented May 24, 2020

Rebased to correct conflicts.

@rhauch
Copy link
Copy Markdown
Contributor

rhauch commented May 24, 2020

ok to test

@rhauch
Copy link
Copy Markdown
Contributor

rhauch commented May 24, 2020

retest this please

@rhauch
Copy link
Copy Markdown
Contributor

rhauch commented May 24, 2020

All 3 builds had test failures on known flaky Streams integration tests, but all Connect-related tests passed.

Copy link
Copy Markdown
Contributor

@kkonstantine kkonstantine left a comment

Choose a reason for hiding this comment

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

This looks great now. Happy to see this feature being added!
Thanks @rhauch
LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants