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

Create unique ids even for random conflicts #476

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions esrally/track/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,16 @@ def number_of_bulks(corpora, partition_index, total_partitions, bulk_size):
return bulks


def build_conflicting_ids(conflicts, docs_to_index, offset, rand=random.randint):
def build_conflicting_ids(conflicts, docs_to_index, offset, shuffle=random.shuffle):
if conflicts is None or conflicts == IndexIdConflict.NoConflicts:
return None
logger.info("building ids with id conflicts of type [%s]" % conflicts)
all_ids = [0] * docs_to_index
for i in range(docs_to_index):
# always consider the offset as each client will index its own range and we don't want uncontrolled conflicts across clients
if conflicts == IndexIdConflict.SequentialConflicts:
all_ids[i] = "%10d" % (offset + i)
else: # RandomConflicts
all_ids[i] = "%10d" % rand(offset, offset + docs_to_index)
all_ids[i] = "%10d" % (offset + i)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sticking to % as we are in the hot code path right? (instead of "{:>10d}".format(offset+i)?)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

if conflicts == IndexIdConflict.RandomConflicts:
shuffle(all_ids)
return all_ids


Expand Down
18 changes: 10 additions & 8 deletions tests/track/params_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,24 @@ def test_sequential_conflicts(self):
)

def test_random_conflicts(self):
predictable_shuffle = list.reverse

self.assertEqual(
[
" 3",
" 3",
" 3"
" 2",
" 1",
" 0"
],
params.build_conflicting_ids(params.IndexIdConflict.RandomConflicts, 3, 0, rand=lambda x, y: y)
params.build_conflicting_ids(params.IndexIdConflict.RandomConflicts, 3, 0, shuffle=predictable_shuffle)
)

self.assertEqual(
[
" 8",
" 8",
" 8"
" 7",
" 6",
" 5"
],
params.build_conflicting_ids(params.IndexIdConflict.RandomConflicts, 3, 5, rand=lambda x, y: y)
params.build_conflicting_ids(params.IndexIdConflict.RandomConflicts, 3, 5, shuffle=predictable_shuffle)
)


Expand Down