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

Find a consistent, non-surprising way to handle replication factor and partition amount for new and existing topics #44

Merged
merged 17 commits into from
Sep 12, 2019

Conversation

MrTrustworthy
Copy link
Contributor

Closes #43

@MrTrustworthy
Copy link
Contributor Author

This PR is a bigger than intended, since I've had to refactor the entire Diff logic to make a consistent check possible, and I ran in some unexpected difficulties (ex. the config values we get from the cluster are always strings, but for local topics we can provide values as either string or integers).

We now have a TopicDiff class with some more utility functions to keep the validation logic etc. in one place. This should also make integrating #45 into esque apply a little easier to implement and test.

@MrTrustworthy
Copy link
Contributor Author

Weird failure in the travis tests that doesn't show up on local tests...

<TopicDiff[{'replication_factor': <AttributeDiff[remote:0, local:1]>}>

How the F is it possible to have a replication factor of 0 on a remote topic o_O

Copy link
Contributor

@hfjn hfjn left a comment

Choose a reason for hiding this comment

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

LGTM. Black and flake are broken though.

esque/cli/commands.py Show resolved Hide resolved
scripts/init.sh Show resolved Hide resolved
@hfjn
Copy link
Contributor

hfjn commented Sep 12, 2019

LGTM. Black and flake are broken though.

Already ran black. Should be fine now.

@MrTrustworthy MrTrustworthy merged commit 8eb78ce into master Sep 12, 2019
@MrTrustworthy MrTrustworthy deleted the 43-replication-and-partition-numbers branch September 12, 2019 12:46
esque/cli/commands.py Show resolved Hide resolved

# TODO: this should be handled correctly by checking the cluster defaults, like
# if remote == cluster_default(name) and local is None: return
# currently, if an attribute that was set get's un-set, it's ignored
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# currently, if an attribute that was set get's un-set, it's ignored
# currently, if an attribute is set remotely but supposed to be unset now, that won't happen because it's ignored

@classmethod
def from_dict(cls, diff_dict: Dict[str, AttributeDiff]) -> "TopicDiff":
td = TopicDiff()
td._diffs = diff_dict
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
td._diffs = diff_dict
td._diffs = diff_dict.copy()

if self.is_only_local:
return self.__replication_factor
partition_replication_factors = set(len(p.partition_replicas) for p in self.partitions)
assert len(partition_replication_factors) == 1, "Different replication factors for partitions!"
Copy link
Contributor

Choose a reason for hiding this comment

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

That might actually happen during partition reassignment... We could either try to find the most occurring value or tell the user to try again later.

PyKafka = "PyKafka"


ClientType = Union[ConfluentTopic, PyKafkaTopic]
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe ClientTopicType? This one is easy to confuse with ClientTypes.

elif client_type == ClientTypes.PyKafka:
# at least PyKafka does it's own caching, so we don't have to bother
pykafka_topics = self.cluster.pykafka_client.cluster.topics
# PyKafka will try to auto-create the topic if you use `topic[random_name]`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# PyKafka will try to auto-create the topic if you use `topic[random_name]`
# PyKafka will try to auto-create the topic if you use `topic[topic_name]`, so we check first if it exists in `confluent_topics`, we can't check if it exists in `pykafka_topics` since that one lazily evaluated and won't contain it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants