Skip to content

Commit

Permalink
Create unique ids even for random conflicts
Browse files Browse the repository at this point in the history
With this commit we ensure that generated ids are always unique, even
when generating random conflicts for bulk requests. The general strategy
to simulate conflicts is as follows:

1. Generate a list of ids upfront.
2. Iterate through this list and pick a duplicate in 25% of all cases.

In order to avoid accidentally creating more conflicts than expected,
the list of ids generated in step one, needs to contain unique ids.
However, we create ids at random without considering which ids have
already been generated. This is now changed by first generating all ids
and then shuffling them.

Relates #476
  • Loading branch information
danielmitterdorfer authored Apr 25, 2018
1 parent 581b7b1 commit 8ed15c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
9 changes: 4 additions & 5 deletions esrally/track/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,17 +581,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)
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 @@ -80,22 +80,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

0 comments on commit 8ed15c4

Please sign in to comment.