use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class BackendGlobalState method createIndex.
@Override
public synchronized IndexState createIndex(String name) throws IOException {
Path rootDir = getIndexDir(name);
if (immutableState.persistentGlobalState.getIndices().containsKey(name)) {
throw new IllegalArgumentException("index \"" + name + "\" already exists");
}
if (Files.exists(rootDir)) {
throw new IllegalArgumentException("rootDir \"" + rootDir + "\" already exists");
}
IndexState state = new IndexState(this, name, rootDir, true, false);
Map<String, IndexInfo> updatedIndexInfoMap = new HashMap<>(immutableState.persistentGlobalState.getIndices());
updatedIndexInfoMap.put(name, new IndexInfo());
PersistentGlobalState updatedState = immutableState.persistentGlobalState.asBuilder().withIndices(updatedIndexInfoMap).build();
stateBackend.commitGlobalState(updatedState);
Map<String, IndexState> updatedIndexStateMap = new HashMap<>(immutableState.indexStateMap);
updatedIndexStateMap.put(name, state);
immutableState = new ImmutableState(updatedState, updatedIndexStateMap);
return state;
}
use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class LegacyGlobalState method createIndex.
/**
* Create a new index.
*/
@Override
public IndexState createIndex(String name) throws IOException {
synchronized (indices) {
Path rootDir = getIndexDir(name);
if (indexNames.get(name) != null) {
throw new IllegalArgumentException("index \"" + name + "\" already exists");
}
if (rootDir == null) {
indexNames.addProperty(name, NULL);
} else {
if (Files.exists(rootDir)) {
throw new IllegalArgumentException("rootDir \"" + rootDir + "\" already exists");
}
indexNames.addProperty(name, name);
}
saveIndexNames();
IndexState state = new IndexState(this, name, rootDir, true, false);
indices.put(name, state);
return state;
}
}
use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class TerminateAfterWrapperTest method testDefaultTerminateAfter.
@Test
public void testDefaultTerminateAfter() throws IOException {
IndexState indexState = getGlobalState().getIndex(DEFAULT_TEST_INDEX);
try {
indexState.setDefaultTerminateAfter(15);
SearchResponse response = doQuery(0, 0.0, false);
assertEquals(15, response.getHitsCount());
assertTrue(response.getTerminatedEarly());
} finally {
indexState.setDefaultTerminateAfter(0);
}
}
use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class DocCollectorTest method testUsesDefaultTimeout.
@Test
public void testUsesDefaultTimeout() {
IndexState indexState = Mockito.mock(IndexState.class);
when(indexState.getDefaultSearchTimeoutSec()).thenReturn(3.0);
when(indexState.getDefaultSearchTimeoutCheckEvery()).thenReturn(0);
SearchRequest request = SearchRequest.newBuilder().setTopHits(10).build();
TestDocCollector docCollector = new TestDocCollector(request, indexState);
assertTrue(docCollector.getManager() instanceof TestDocCollector.TestCollectorManager);
assertTrue(docCollector.getWrappedManager() instanceof SearchCutoffWrapper);
SearchCutoffWrapper<?> cutoffWrapper = (SearchCutoffWrapper<?>) docCollector.getWrappedManager();
assertEquals(3.0, cutoffWrapper.getTimeoutSec(), 0.0);
assertEquals(0, cutoffWrapper.getCheckEvery());
}
use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class DocCollectorTest method testQueryOverridesDefaultTimeoutCheckEvery.
@Test
public void testQueryOverridesDefaultTimeoutCheckEvery() {
IndexState indexState = Mockito.mock(IndexState.class);
when(indexState.getDefaultSearchTimeoutSec()).thenReturn(0.0);
when(indexState.getDefaultSearchTimeoutCheckEvery()).thenReturn(20);
SearchRequest request = SearchRequest.newBuilder().setTopHits(10).setTimeoutSec(7.0).setTimeoutCheckEvery(30).build();
TestDocCollector docCollector = new TestDocCollector(request, indexState);
assertTrue(docCollector.getManager() instanceof TestDocCollector.TestCollectorManager);
assertTrue(docCollector.getWrappedManager() instanceof SearchCutoffWrapper);
SearchCutoffWrapper<?> cutoffWrapper = (SearchCutoffWrapper<?>) docCollector.getWrappedManager();
assertEquals(7.0, cutoffWrapper.getTimeoutSec(), 0.0);
assertEquals(30, cutoffWrapper.getCheckEvery());
}
Aggregations