This repository was archived by the owner on Mar 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Tests for SimpleConsumer.reset_offsets #213
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
562e20e
test_simpleconsumer: use random topic name
yungchin b0c7065
test_simpleconsumer: use consumer.held_offsets
yungchin 50561ee
Revert "fix broken retry logic for failed offset resets"
yungchin 3cea51c
simpleconsumer: revisit 4cbe0a16
yungchin 3e76c15
simpleconsumer: more on reset_offsets retry logic
yungchin 345e4ae
test_simpleconsumer: tests for reset_offsets (WIP)
yungchin d18c584
test_simpleconsumer: more on reset_offsets
yungchin 17d4aa6
test_simpleconsumer: reset_offsets encore
yungchin 5892104
simpleconsumer: sync semaphore when flushing queue
yungchin cbdbfa3
test_simpleconsumer: relax reset_offsets requirements
yungchin d33736f
Merge remote-tracking branch 'parsely/master' into feature/test_reset…
yungchin 45d9943
simpleconsumer: revisit queue flushing
yungchin 8668f02
Merge branch 'master' into feature/test_reset_offsets
emmettbutler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -497,9 +497,6 @@ def _handle_success(parts): | |
partition.flush() | ||
by_leader[partition.partition.leader].append((partition, offset)) | ||
|
||
# reset this dict to prepare it for next retry | ||
owned_partition_offsets = {} | ||
|
||
# get valid offset ranges for each partition | ||
for broker, offsets in by_leader.iteritems(): | ||
reqs = [owned_partition.build_offset_request(offset) | ||
|
@@ -511,7 +508,11 @@ def _handle_success(parts): | |
success_handler=_handle_success, | ||
partitions_by_id=self._partitions_by_id) | ||
|
||
if len(parts_by_error) == 1 and 0 in parts_by_error: | ||
if 0 in parts_by_error: | ||
# drop successfully reset partitions for next retry | ||
successful = [part for part, _ in parts_by_error.pop(0)] | ||
map(owned_partition_offsets.pop, successful) | ||
if not parts_by_error: | ||
continue | ||
log.error("Error resetting offsets for topic %s (errors: %s)", | ||
self._topic.name, | ||
|
@@ -520,24 +521,16 @@ def _handle_success(parts): | |
|
||
time.sleep(i * (self._offsets_channel_backoff_ms / 1000)) | ||
|
||
if 0 in parts_by_error: | ||
parts_by_error.pop(0) | ||
errored_partitions = { | ||
part: owned_partition_offsets[part] | ||
for errcode, parts in parts_by_error.iteritems() | ||
for part, _ in parts} | ||
owned_partition_offsets.update(errored_partitions) | ||
|
||
for errcode, owned_partitions in parts_by_error.iteritems(): | ||
if errcode != 0: | ||
for owned_partition in owned_partitions: | ||
owned_partition.fetch_lock.release() | ||
for errcode, owned_partitions in parts_by_error.iteritems(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good catch, though I'm surprised it wasn't already fixed. I could've sworn I made this exact change somewhere else. |
||
if errcode != 0: | ||
for owned_partition in owned_partitions: | ||
owned_partition.fetch_lock.release() | ||
|
||
if len(parts_by_error) == 1 and 0 in parts_by_error: | ||
if not owned_partition_offsets: | ||
break | ||
log.debug("Retrying offset reset") | ||
|
||
if any([a != 0 for a in parts_by_error]): | ||
if owned_partition_offsets: | ||
raise OffsetRequestFailedError("reset_offsets failed after %d " | ||
"retries", | ||
self._offsets_reset_max_retries) | ||
|
@@ -643,7 +636,16 @@ def message_count(self): | |
return self._messages.qsize() | ||
|
||
def flush(self): | ||
"""Flush internal queue""" | ||
# Swap out _messages so a concurrent consume/enqueue won't interfere | ||
tmp = self._messages | ||
self._messages = Queue() | ||
while True: | ||
try: | ||
tmp.get_nowait() | ||
self._messages_arrived.acquire(blocking=False) | ||
except Empty: | ||
break | ||
log.info("Flushed queue for partition %d", self.partition.id) | ||
|
||
def set_offset(self, last_offset_consumed): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a much better way to do what I was trying to do.