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

topic manager wait #348

Merged
merged 3 commits into from
Sep 23, 2021
Merged

topic manager wait #348

merged 3 commits into from
Sep 23, 2021

Conversation

frairon
Copy link
Contributor

@frairon frairon commented Sep 20, 2021

This PR adds a simple polling mechanism for the TopicManager after creating a topic to be fully populated in the cluster.

topic_manager.go Outdated
return nil
}

start := time.Now()

Choose a reason for hiding this comment

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

Another approach

// or better get ctx passed as param in waitForCreated instead of using .Background()
ctx, cancel := context.WithTimeout(context.Background, m.topicManagerConfig.CreateTopicTimeout)
defer cancel()

for ctx.Err() == nil {
	_, err := m.Partitions(topic)
	switch err {
	case nil: 
		return nil
	case errTopicNotFound:
		time.Sleep(time.Second)
	default: 
		return fmt.Errorf("error checking topic: %w", err)
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking of adding the context as a param, but that would mean changing the whole api.
But the timeout context is definitely an improvement, didn't think of this. so Thanks :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@paulhenke fixed.

@frairon frairon merged commit 2859fe3 into master Sep 23, 2021
@frairon frairon deleted the topic_manager_wait branch September 23, 2021 07:27
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.

None yet

3 participants