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: implement kafka topic create/delete api #315

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

vchandela
Copy link
Collaborator

@vchandela vchandela commented Nov 17, 2024

Fixes #285

@purplefox purplefox marked this pull request as draft November 20, 2024 18:20
@vchandela vchandela marked this pull request as ready for review November 22, 2024 10:20
@vchandela vchandela force-pushed the vchandela-kafka-topic-create-delete-api branch 2 times, most recently from 493b990 to 2dca2ea Compare November 22, 2024 15:28
agent/create_delete_topics_test.go Show resolved Hide resolved
agent/create_delete_topics_test.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
agent/utils.go Outdated Show resolved Hide resolved
control/controller.go Outdated Show resolved Hide resolved
agent/create_delete_topics_test.go Show resolved Hide resolved
agent/create_delete_topics_test.go Outdated Show resolved Hide resolved
agent/create_delete_topics_test.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
topicmeta/manager.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
common/errors.go Outdated Show resolved Hide resolved
@vchandela vchandela force-pushed the vchandela-kafka-topic-create-delete-api branch 2 times, most recently from 044853d to 5660915 Compare November 24, 2024 19:13
@vchandela vchandela force-pushed the vchandela-kafka-topic-create-delete-api branch from 5660915 to bec6a1d Compare November 24, 2024 19:24
agent/conf.go Outdated Show resolved Hide resolved
agent/create_delete_topics_test.go Show resolved Hide resolved
agent/create_delete_topics_test.go Outdated Show resolved Hide resolved
var resp kafkaprotocol.CreateTopicsResponse
r, err := conn.SendRequest(&req, kafkaprotocol.APIKeyCreateTopics, 5, &resp)
require.NoError(t, err)
createResp, ok := r.(*kafkaprotocol.CreateTopicsResponse)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be coordinator not available?

agent/kafka_handler.go Outdated Show resolved Hide resolved
agent/kafka_handler.go Outdated Show resolved Hide resolved
Responses: make([]kafkaprotocol.DeleteTopicsResponseDeletableTopicResult, len(req.TopicNames)),
}
for tidx, topicName := range req.TopicNames {
var errMsg string
Copy link
Contributor

Choose a reason for hiding this comment

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

should be *string otherwise we are setting err message to pointer to empty string even when there is no error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this comment is outdated as the code has changed a bit. Please let me know if this is still needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

The same issue is there

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

got it. Done.

common/errors.go Outdated Show resolved Hide resolved
kafkagen/genproto.go Show resolved Hide resolved
return common.UnknownError
}

func detectInvalidTopic(name string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking... it would be better to do this check in topicmeta.CreateTopic(), not here, can you move it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this is outdated.

GroupCoordinatorConf: group.NewConf(),
TxCoordinatorConf: tx.NewConf(),
MaxControllerClients: DefaultMaxControllerClients,
DefaultDefaultTopicRetentionTime: DefaultDefaultTopicRetentionTime,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the member called "DefaultDefaultTopicRetentionTime"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ahhh...the member should be DefaultTopicRetentionTime and the constant should be DefaultDefaultTopicRetentionTime.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the constant is the default of the default

{"Invalid special characters", "topic@", int16(kafkaprotocol.ErrorCodeInvalidTopicException)},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's nicer if you put this in a separate method

return kafkaprotocol.ErrorCodeUnknownServerError
}

func isInvalidTopicName(name string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned in a previous comment, this check should be done in topicmeta.Manager

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but Agent doesn't have topicmeta.Manager

type Agent struct {
	lock                     sync.RWMutex
	cfg                      Conf
	started                  bool
	transportServer          transport.Server
	kafkaServer              *kafkaserver2.KafkaServer
	tablePusher              *pusher.TablePusher
	batchFetcher             *fetcher.BatchFetcher
	controller               *control.Controller
	controlClientCache       *control.ClientCache
	membership               ClusterMembership
	compactionWorkersService *lsm.CompactionWorkerService
	partitionHashes          *parthash.PartitionHashes
	fetchCache               *fetchcache.Cache
	groupCoordinator         *group.Coordinator
	txCoordinator            *tx.Coordinator
	topicMetaCache           *topicmeta.LocalCache
	manifold                 *membershipChangedManifold
	partitionLeaders         map[string]map[int]map[int]int32
	clusterMembershipFactory ClusterMembershipFactory
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand what you mean.
I am suggesting the check that the topic name is valid should be in topicmeta.manager.CreateTopic - do you not think that is a better place?

Copy link
Contributor

Choose a reason for hiding this comment

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

But don't worry about this - I will do it in a later PR

Responses: make([]kafkaprotocol.DeleteTopicsResponseDeletableTopicResult, len(req.TopicNames)),
}
for tidx, topicName := range req.TopicNames {
var errMsg string
Copy link
Contributor

Choose a reason for hiding this comment

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

The same issue is there

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.

Implement create/delete topic Kafka API
2 participants