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

[#3051] fix(kafka-catalog): Make the catalog creation failure exception more accurate #3060

Merged
merged 3 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
import org.apache.kafka.clients.admin.NewPartitions;
import org.apache.kafka.clients.admin.NewTopic;
import org.apache.kafka.clients.admin.TopicDescription;
import org.apache.kafka.common.KafkaException;
import org.apache.kafka.common.Uuid;
import org.apache.kafka.common.config.ConfigException;
import org.apache.kafka.common.config.ConfigResource;
import org.apache.kafka.common.errors.InvalidConfigurationException;
import org.apache.kafka.common.errors.InvalidReplicationFactorException;
Expand Down Expand Up @@ -132,8 +134,16 @@ public void initialize(Map<String, String> config, CatalogInfo info) throws Runt
AdminClientConfig.CLIENT_ID_CONFIG,
String.format(CLIENT_ID_TEMPLATE, config.get(ID_KEY), info.namespace(), info.name()));

try {
adminClient = AdminClient.create(adminClientConfig);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the timeout? The web page has hang here for a long time if I use a wrong broker address.
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a UI problem or a backend problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

Backend. From the backend log, the list opearation block(retry) for a long time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because you are listing all the topics, the default API timeout is 1 minute, should I set it to a shorter time?

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer to shorten the time here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we create a new issue to track this? Since is already a list topics operation, not a create catalog issue

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we create a new issue to track this? Since is already a list topics operation, not a create catalog issue

Agree, a separate issue may be better.

} catch (KafkaException e) {
if (e.getCause() instanceof ConfigException) {
throw new IllegalArgumentException(
"Invalid configuration for Kafka AdminClient: " + e.getCause().getMessage(), e);
}
throw new RuntimeException("Failed to create Kafka AdminClient", e);
}
createDefaultSchemaIfNecessary();
adminClient = AdminClient.create(adminClientConfig);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,35 @@ public void testCatalog() throws ExecutionException, InterruptedException {
Assertions.assertFalse(adminClient.listTopics().names().get().isEmpty());
}

@Test
public void testCatalogException() {
String catalogName = GravitinoITUtils.genRandomName("test-catalog");
Exception exception =
Assertions.assertThrows(
IllegalArgumentException.class,
() ->
metalake.createCatalog(
NameIdentifier.of(METALAKE_NAME, catalogName),
Catalog.Type.MESSAGING,
PROVIDER,
"comment",
ImmutableMap.of(BOOTSTRAP_SERVERS, "2")));
Assertions.assertTrue(exception.getMessage().contains("Invalid url in bootstrap.servers: 2"));

exception =
Assertions.assertThrows(
IllegalArgumentException.class,
() ->
metalake.createCatalog(
NameIdentifier.of(METALAKE_NAME, catalogName),
Catalog.Type.MESSAGING,
PROVIDER,
"comment",
ImmutableMap.of("abc", "2")));
Assertions.assertTrue(
exception.getMessage().contains("Missing configuration: bootstrap.servers"));
}

@Test
public void testDefaultSchema() {
NameIdentifier[] schemas =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ public Catalog createCatalog(
} catch (Exception e3) {
catalogCache.invalidate(ident);
LOG.error("Failed to create catalog {}", ident, e3);
if (e3 instanceof RuntimeException) {
throw (RuntimeException) e3;
}
throw new RuntimeException(e3);
} finally {
if (!createSuccess) {
Expand Down
Loading