use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class SearchRequestProcessor method getVirtualFields.
/**
* Parses any virtualFields, which define dynamic (expression) fields for this one request.
*
* @throws IllegalArgumentException if there are multiple virtual fields with the same name
*/
private static Map<String, FieldDef> getVirtualFields(ShardState shardState, SearchRequest searchRequest) {
if (searchRequest.getVirtualFieldsList().isEmpty()) {
return new HashMap<>();
}
IndexState indexState = shardState.indexState;
Map<String, FieldDef> virtualFields = new HashMap<>();
for (VirtualField vf : searchRequest.getVirtualFieldsList()) {
if (virtualFields.containsKey(vf.getName())) {
throw new IllegalArgumentException("Multiple definitions of Virtual field: " + vf.getName());
}
ScoreScript.Factory factory = ScriptService.getInstance().compile(vf.getScript(), ScoreScript.CONTEXT);
Map<String, Object> params = ScriptParamsUtils.decodeParams(vf.getScript().getParamsMap());
FieldDef virtualField = new VirtualFieldDef(vf.getName(), factory.newFactory(params, indexState.docLookup));
virtualFields.put(vf.getName(), virtualField);
}
return virtualFields;
}
use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class BackendGlobalState method getIndex.
@Override
public IndexState getIndex(String name, boolean hasRestore) throws IOException {
IndexState state = immutableState.indexStateMap.get(name);
if (state != null) {
return state;
}
synchronized (this) {
state = immutableState.indexStateMap.get(name);
if (state == null) {
if (!immutableState.persistentGlobalState.getIndices().containsKey(name)) {
throw new IllegalArgumentException("index \"" + name + "\" was not saved or committed");
}
Path rootPath = getIndexDir(name);
state = new IndexState(this, name, rootPath, false, hasRestore);
// nocommit we need to also persist which shards are here?
state.addShard(0, false);
Map<String, IndexState> updatedIndexStateMap = new HashMap<>(immutableState.indexStateMap);
updatedIndexStateMap.put(name, state);
immutableState = new ImmutableState(immutableState.persistentGlobalState, updatedIndexStateMap);
}
return state;
}
}
use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class LegacyGlobalState method getIndex.
@Override
public IndexState getIndex(String name, boolean hasRestore) throws IOException {
synchronized (indices) {
IndexState state = indices.get(name);
if (state == null) {
String rootPath = null;
JsonElement indexJsonName = indexNames.get(name);
if (indexJsonName == null) {
throw new IllegalArgumentException("index " + name + " was not saved or commited");
}
String indexName = indexJsonName.getAsString();
if (indexName != null) {
rootPath = getIndexDir(name).toString();
}
if (rootPath != null) {
if (rootPath.equals(NULL)) {
state = new IndexState(this, name, null, false, hasRestore);
} else {
state = new IndexState(this, name, Paths.get(rootPath), false, hasRestore);
}
// nocommit we need to also persist which shards are here?
state.addShard(0, false);
indices.put(name, state);
} else {
throw new IllegalArgumentException("index \"" + name + "\" was not yet created");
}
}
return state;
}
}
use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class TimeoutTest method queryWithFunction.
private TopDocs queryWithFunction(SearchRequest request, Function<SearchContext, TopDocs> func) throws Exception {
SearcherTaxonomyManager.SearcherAndTaxonomy s = null;
IndexState indexState = getGlobalState().getIndex(TEST_INDEX);
ShardState shardState = indexState.getShard(0);
try {
s = shardState.acquire();
SearchContext context = SearchRequestProcessor.buildContextForRequest(request, indexState, shardState, s, ProfileResult.newBuilder());
return func.apply(context);
} finally {
if (s != null) {
shardState.release(s);
}
}
}
use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.
the class BackendGlobalStateTest method testGetCreatedIndex.
@Test
public void testGetCreatedIndex() throws IOException {
StateBackend mockBackend = mock(StateBackend.class);
PersistentGlobalState initialState = new PersistentGlobalState();
when(mockBackend.loadOrCreateGlobalState()).thenReturn(initialState);
MockBackendGlobalState.stateBackend = mockBackend;
BackendGlobalState backendGlobalState = new MockBackendGlobalState(getConfig(), null);
backendGlobalState.createIndex("test_index");
assertEquals(1, backendGlobalState.getIndexNames().size());
assertTrue(backendGlobalState.getIndexNames().contains("test_index"));
IndexState createdState = backendGlobalState.getIndex("test_index");
assertNotNull(createdState);
IndexState getIndexState = backendGlobalState.getIndex("test_index");
assertSame(createdState, getIndexState);
verify(mockBackend, times(1)).loadOrCreateGlobalState();
ArgumentCaptor<PersistentGlobalState> stateArgumentCaptor = ArgumentCaptor.forClass(PersistentGlobalState.class);
verify(mockBackend, times(1)).commitGlobalState(stateArgumentCaptor.capture());
PersistentGlobalState committedState = stateArgumentCaptor.getValue();
assertEquals(1, committedState.getIndices().size());
assertNotNull(committedState.getIndices().get("test_index"));
verifyNoMoreInteractions(mockBackend);
}
Aggregations