def reindex(session, es, request): """Reindex all annotations into a new index, and update the alias.""" current_index = get_aliased_index(es) if current_index is None: raise RuntimeError('cannot reindex if current index is not aliased') settings = request.find_service(name='settings') # Preload userids of shadowbanned users. nipsa_svc = request.find_service(name='nipsa') nipsa_svc.fetch_all_flagged_userids() new_index = configure_index(es) log.info('configured new index {}'.format(new_index)) setting_name = 'reindex.new_index' if es.version < (2, ): setting_name = 'reindex.new_index' try: settings.put(setting_name, new_index) request.tm.commit() log.info('reindexing annotations into new index {}'.format(new_index)) indexer = BatchIndexer(session, es, request, target_index=new_index, op_type='create') errored = indexer.index() if errored: log.debug('failed to index {} annotations, retrying...'.format( len(errored))) errored = indexer.index(errored) if errored: log.warn('failed to index {} annotations: {!r}'.format( len(errored), errored)) log.info('making new index {} current'.format(new_index)) update_aliased_index(es, new_index) log.info('removing previous index {}'.format(current_index)) delete_index(es, current_index) finally: settings.delete(setting_name) request.tm.commit()
def reindex(session, es, request): """Reindex all annotations into a new index, and update the alias.""" current_index = get_aliased_index(es) if current_index is None: raise RuntimeError("cannot reindex if current index is not aliased") settings = request.find_service(name="settings") # Preload userids of shadowbanned users. nipsa_svc = request.find_service(name="nipsa") nipsa_svc.fetch_all_flagged_userids() new_index = configure_index(es) log.info("configured new index {}".format(new_index)) setting_name = "reindex.new_index" try: settings.put(setting_name, new_index) request.tm.commit() log.info("reindexing annotations into new index {}".format(new_index)) indexer = BatchIndexer( session, es, request, target_index=new_index, op_type="create" ) errored = indexer.index() if errored: log.debug( "failed to index {} annotations, retrying...".format(len(errored)) ) errored = indexer.index(errored) if errored: log.warning( "failed to index {} annotations: {!r}".format(len(errored), errored) ) log.info("making new index {} current".format(new_index)) update_aliased_index(es, new_index) log.info("removing previous index {}".format(current_index)) delete_index(es, current_index) finally: settings.delete(setting_name) request.tm.commit()
def reindex(session, es, request): """Reindex all annotations into a new index, and update the alias.""" current_index = get_aliased_index(es) if current_index is None: raise RuntimeError("cannot reindex if current index is not aliased") settings = request.find_service(name="settings") # Preload userids of shadowbanned users. nipsa_svc = request.find_service(name="nipsa") nipsa_svc.fetch_all_flagged_userids() new_index = configure_index(es) log.info("configured new index %s", new_index) setting_name = "reindex.new_index" try: settings.put(setting_name, new_index) request.tm.commit() log.info("reindexing annotations into new index %s", new_index) indexer = BatchIndexer( session, es, request, target_index=new_index, op_type="create" ) errored = indexer.index() if errored: log.debug("failed to index %d annotations, retrying...", len(errored)) errored = indexer.index(errored) if errored: log.warning("failed to index %d annotations: %r", len(errored), errored) log.info("making new index %s current", new_index) update_aliased_index(es, new_index) log.info("removing previous index %s", current_index) delete_index(es, current_index) finally: settings.delete(setting_name) request.tm.commit()
def test_deletes_index(self, client): delete_index(client, 'unused-index') client.conn.indices.delete.assert_called_once_with(index='unused-index')
def test_ignores_NotFound_error(self, client): client.conn.indices.delete.side_effect = elasticsearch1.exceptions.NotFoundError('IndexMissingException', '') delete_index(client, 'unused-index')
def test_deletes_index(self, mock_es_client): delete_index(mock_es_client, "unused-index") mock_es_client.conn.indices.delete.assert_called_once_with(index="unused-index")