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

feat(remote_wal): make meta srv able to alloc kafka topics #2753

Closed

Conversation

niebayes
Copy link
Contributor

@niebayes niebayes commented Nov 15, 2023

I hereby agree to the terms of the GreptimeDB CLA

What's changed and what's your intention?

This PR is part of the Kafka remote wal project.
It adds Kafka stuff to meta srv which is now able to allocate Kafka topics for regions while handling create table requests.

Details

There resides a WalMetaAllocator in MetaSrvTablemetadataAllocator. When the create inferface of the MetaSrvTablemetadataAllocator is invoked, a number of topics will be allocated by WalMetaAllocator. Those topics will be assigned to regions when executing CreateTableProcedure by the procedure manager.
A region's topic is stored in RegionOptions so that it could be used in opening and creating regions by datanode.

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.

Refer to a related PR or issue link (optional)

@niebayes niebayes requested review from fengjiachun, MichaelScofield, v0y4g3r and evenyag and removed request for fengjiachun November 15, 2023 10:24
Copy link

codecov bot commented Nov 16, 2023

Codecov Report

Merging #2753 (6087d92) into develop (102e43a) will decrease coverage by 0.43%.
Report is 1 commits behind head on develop.
The diff coverage is 50.79%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2753      +/-   ##
===========================================
- Coverage    84.68%   84.25%   -0.43%     
===========================================
  Files          730      735       +5     
  Lines       113711   113960     +249     
===========================================
- Hits         96291    96012     -279     
- Misses       17420    17948     +528     

Cargo.toml Outdated Show resolved Hide resolved
src/common/meta/src/ddl.rs Outdated Show resolved Hide resolved
src/common/meta/src/ddl/create_table.rs Outdated Show resolved Hide resolved
src/common/meta/src/wal/kafka/topic_manager.rs Outdated Show resolved Hide resolved
src/common/meta/src/wal/kafka/topic_manager.rs Outdated Show resolved Hide resolved
src/common/meta/src/wal/kafka/topic_manager.rs Outdated Show resolved Hide resolved
src/common/meta/src/wal/kafka/topic_manager.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@MichaelScofield MichaelScofield left a comment

Choose a reason for hiding this comment

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

Tests are too few, especially the cases for kafka. I think it's a must to do it first.

Cargo.toml Outdated Show resolved Hide resolved
src/common/meta/src/ddl/create_table.rs Outdated Show resolved Hide resolved
src/common/meta/src/wal/kafka.rs Outdated Show resolved Hide resolved
src/common/meta/src/wal/kafka/topic_manager.rs Outdated Show resolved Hide resolved
src/common/meta/src/wal/kafka/topic_manager.rs Outdated Show resolved Hide resolved
return None;
}

Some(kafka_ctrl_client.create_topic(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does rskafka return an error if the topic already exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a TopicAlreadyExists Error in rskafka, but it's never used except in one test.
See: https://github.com/influxdata/rskafka/blob/a9a16d51eba40dbce7a5d976f2a7094dfc0a7e17/src/protocol/error.rs#L48

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to further determine how rskafka handles an already-exist topic.

@niebayes niebayes self-assigned this Nov 20, 2023
@niebayes niebayes force-pushed the feat/remote_wal_meta_srv branch from a8a0f7e to e77f0fa Compare November 23, 2023 07:35
@niebayes
Copy link
Contributor Author

niebayes commented Nov 24, 2023

Waiting for #2816 to be merged.
There're alternative ways to store the kafka topics. This PR shall be merged when the scheme is finally determined.

Copy link
Member

@WenyXu WenyXu left a comment

Choose a reason for hiding this comment

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

  1. For metadata, we need to consider the ability of backward compatibility; it's not easy to make breaking changes in the production environment.
  2. I think Kafka WAL will be replaced with our own WAL service in the future. The code should be more general, and we can migrate to the new WAL service easily.

src/common/meta/src/ddl/create_table.rs Show resolved Hide resolved
src/common/meta/src/ddl/create_table.rs Show resolved Hide resolved
Comment on lines +280 to +292
#[snafu(display("Failed to deserialize Kafka topics"))]
DeserKafkaTopics {
location: Location,
#[snafu(source)]
error: JsonError,
},

#[snafu(display("Failed to serialize Kafka topics"))]
SerKafkaTopics {
location: Location,
#[snafu(source)]
error: JsonError,
},
Copy link
Member

Choose a reason for hiding this comment

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

How about using DecodeJson and EncodeJson?

src/common/meta/src/ddl/create_table.rs Show resolved Hide resolved
src/common/meta/src/wal/meta.rs Show resolved Hide resolved
src/common/meta/src/wal/meta.rs Show resolved Hide resolved
src/meta-srv/src/table_meta_alloc.rs Show resolved Hide resolved
config/metasrv.example.toml Show resolved Hide resolved
src/common/meta/src/ddl.rs Show resolved Hide resolved
src/common/meta/src/ddl.rs Show resolved Hide resolved
src/common/meta/src/ddl/create_table.rs Show resolved Hide resolved
src/common/meta/src/ddl/create_table.rs Show resolved Hide resolved
src/common/meta/src/wal.rs Show resolved Hide resolved
.await
.context(CreateKafkaTopicSnafu)?;

persist_created_topics(&topics, kv_backend).await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add some info logs for creating topics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do so.

src/common/meta/src/wal/meta.rs Show resolved Hide resolved
@killme2008
Copy link
Contributor

@niebayes There are some comments, are u currently working on addressing them? Let's discuss if you have any problems.

@niebayes niebayes marked this pull request as draft December 14, 2023 02:48
@niebayes niebayes closed this Dec 15, 2023
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.

5 participants