Skip to content

Commit

Permalink
Wait for a yellow status when setting up indexes.
Browse files Browse the repository at this point in the history
Before, I would get random errors about shards not being available. Erik
Rose told me that this is because I made an index, but then didn't wait
for it to propogate to the shards. He gave me a line of code to wait for
the sync.

I noticed I had to add it in several places, always right after a call
to `setup_indexes()`. So I made that function do that. I also removed
the refresh calls right after any `setup_index()` calls, because refresh
is called in that function.

The old way of working around this was to sleep a bit during refreshes.
That isn't as good as this way, so I nuked the old way, including the
docs for it.
  • Loading branch information
mythmon committed Jan 24, 2013
1 parent 8ba7265 commit a2fe60d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 22 deletions.
12 changes: 0 additions & 12 deletions docs/es.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,6 @@ override any of the settings, do so in your
See ``fjord/settings/base.py`` for the list of settings and what they
do.

.. Note::

If you're running Input in a vm, you'll want to set
``ES_TEST_SLEEP_DURATION``. This causes the test harness to sleep a
bit between indexing things and querying the index. This gives
ElasticSearch a chance to catch up.

For example, this sets it to 1 second::

ES_TEST_SLEEP_DURATION = 1


Command line tools
==================

Expand Down
6 changes: 4 additions & 2 deletions fjord/search/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def refresh(self, timesleep=0):
if timesleep > 0:
time.sleep(timesleep)

def setup_indexes(self, empty=False):
def setup_indexes(self, empty=False, wait=True):
"""(Re-)create ES indexes."""
from fjord.search.index import es_reindex_cmd

Expand All @@ -79,7 +79,9 @@ def setup_indexes(self, empty=False):
# existing data into it.
es_reindex_cmd()

self.refresh(settings.ES_TEST_SLEEP_DURATION)
self.refresh()
if wait:
get_indexing_es().health(wait_for_status='yellow')

def teardown_indexes(self):
es = get_indexing_es()
Expand Down
2 changes: 0 additions & 2 deletions fjord/search/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ def test_index_chunk_task(self):
# start with so we delete and recreate it.
self.setup_indexes(empty=True)

self.refresh()

# Verify there's nothing in the index.
eq_(len(SimpleIndex.search()), 0)

Expand Down
6 changes: 0 additions & 6 deletions fjord/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@
# The indexing timeout to use. 30s is good.
ES_INDEXING_TIMEOUT = 30

# The sleep duration between indexing and querying. If you're using a
# VM then setting this to a positive integer like 1 or 2 might
# alleviate problems with tests failing because ElasticSearch can't
# keep up.
ES_TEST_SLEEP_DURATION = 0

# When True, objects that belong in the index will get automatically indexed
# and deindexed when created and destroyed.
ES_LIVE_INDEX = True

0 comments on commit a2fe60d

Please sign in to comment.