Skip to content

Commit

Permalink
add refresh on backfill complete
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Apr 10, 2023
1 parent 78a9820 commit 26eedf9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions share/admin/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ def _pls_stop_keeping_live(specific_indexname):
def _pls_start_backfill(specific_indexname):
specific_index = IndexStrategy.get_specific_index(specific_indexname)
assert specific_index.is_current
specific_index.index_strategy.get_or_create_backfill().pls_start(specific_index)
specific_index.index_strategy.pls_start_backfill()


def _pls_mark_backfill_complete(specific_indexname):
specific_index = IndexStrategy.get_specific_index(specific_indexname)
specific_index.index_strategy.get_or_create_backfill().pls_mark_complete()
specific_index.index_strategy.pls_mark_backfill_complete()


def _pls_make_default_for_searching(specific_indexname):
Expand Down
10 changes: 5 additions & 5 deletions share/models/index_backfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ def mutex(self):
with IndexBackfill.objects.get_with_mutex(pk=self.pk) as index_backfill:
yield index_backfill

def pls_start(self, specific_index):
def pls_start(self, index_strategy):
with self.mutex() as locked_self:
assert specific_index.is_current
assert locked_self.index_strategy_name == specific_index.index_strategy.name
if locked_self.specific_indexname == specific_index.indexname:
assert locked_self.index_strategy_name == index_strategy.name
current_index = index_strategy.for_current_index()
if locked_self.specific_indexname == current_index.indexname:
# what is "current" has not changed -- should already be INITIAL
assert locked_self.backfill_status == IndexBackfill.INITIAL
else:
# what is "current" has changed! disregard backfill_status
locked_self.specific_indexname = specific_index.indexname
locked_self.specific_indexname = current_index.indexname
locked_self.backfill_status = IndexBackfill.INITIAL
locked_self.__update_error(None)
try:
Expand Down
6 changes: 6 additions & 0 deletions share/search/index_strategy/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ def get_or_create_backfill(self):
(index_backfill, _) = IndexBackfill.objects.get_or_create(index_strategy_name=self.name)
return index_backfill

def pls_start_backfill(self):
self.get_or_create_backfill().pls_start(self)

def pls_mark_backfill_complete(self):
self.get_or_create_backfill().pls_mark_complete()

@property
@abc.abstractmethod
def supported_message_types(self) -> typing.Iterable[messages.MessageType]:
Expand Down
6 changes: 6 additions & 0 deletions share/search/index_strategy/elastic8.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ def pls_get_default_for_searching(self) -> 'SpecificIndex':
# will error if you try to invoke lifecycle hooks
return self.for_specific_index(self._alias_for_searching)

# override from IndexStrategy
def pls_mark_backfill_complete(self):
super().pls_mark_backfill_complete()
# explicit refresh after bulk operation
self.es8_client.indices.refresh(index=self.current_indexname)

@property
def _alias_for_searching(self):
return f'{self.indexname_prefix}search'
Expand Down
9 changes: 1 addition & 8 deletions share/search/index_strategy/sharev2_elastic8.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Sharev2Elastic8IndexStrategy(Elastic8IndexStrategy):
CURRENT_STRATEGY_CHECKSUM = ChecksumIri(
checksumalgorithm_name='sha-256',
salt='Sharev2Elastic8IndexStrategy',
hexdigest='5ef50fba9311fd5c5413509d00134991517955697dd7dc7e1bf212e052ceb04f',
hexdigest='bcaa90e8fa8a772580040a8edbedb5f727202d1fca20866948bc0eb0e935e51f',
)

# abstract method from IndexStrategy
Expand All @@ -29,13 +29,6 @@ def supported_message_types(self):
def index_settings(self):
return {
'analysis': {
'filter': {
'autocomplete_filter': {
'type': 'edge_ngram',
'min_gram': 1,
'max_gram': 20,
}
},
'analyzer': {
'default': {
# same as 'standard' analyzer, plus html_strip
Expand Down
4 changes: 3 additions & 1 deletion templates/admin/search-indexes.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ <h3>current index: <i>{{indexes.current.status.specific_indexname}}</i></h3>
{{ indexes.current.backfill.backfill_status }}
({{ indexes.current.backfill.backfill_modified }})
</a>
<p>({{ indexes.current.backfill.backfill_queue_depth }} in nonurgent queue)</p>
{% if not indexes.current.backfill.is_complete %}
<p>({{ indexes.current.backfill.backfill_queue_depth }} in nonurgent queue)</p>
{% endif %}
{% else %}
--
{% endif %}
Expand Down

0 comments on commit 26eedf9

Please sign in to comment.