Search in sources :

Example 11 with IndexInfo

use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.

the class LocalStateBackendTest method testLoadsSavedState.

@Test
public void testLoadsSavedState() throws IOException {
    StateBackend stateBackend = new LocalStateBackend(getMockGlobalState());
    Path filePath = getStateFilePath();
    Map<String, IndexInfo> indicesMap = new HashMap<>();
    indicesMap.put("test_index", new IndexInfo());
    indicesMap.put("test_index_2", new IndexInfo());
    PersistentGlobalState initialState = new PersistentGlobalState(indicesMap);
    StateUtils.writeStateToFile(initialState, Paths.get(folder.getRoot().getAbsolutePath(), StateUtils.GLOBAL_STATE_FOLDER), StateUtils.GLOBAL_STATE_FILE);
    assertTrue(filePath.toFile().exists());
    assertTrue(filePath.toFile().isFile());
    PersistentGlobalState loadedState = stateBackend.loadOrCreateGlobalState();
    assertEquals(initialState, loadedState);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) PersistentGlobalState(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) Test(org.junit.Test)

Example 12 with IndexInfo

use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.

the class LocalStateBackendTest method testCommitGlobalState.

@Test
public void testCommitGlobalState() throws IOException {
    StateBackend stateBackend = new LocalStateBackend(getMockGlobalState());
    Path filePath = getStateFilePath();
    PersistentGlobalState initialState = stateBackend.loadOrCreateGlobalState();
    Map<String, IndexInfo> indicesMap = new HashMap<>();
    indicesMap.put("test_index", new IndexInfo());
    indicesMap.put("test_index_2", new IndexInfo());
    PersistentGlobalState updatedState = new PersistentGlobalState(indicesMap);
    assertNotEquals(initialState, updatedState);
    stateBackend.commitGlobalState(updatedState);
    PersistentGlobalState loadedState = StateUtils.readStateFromFile(filePath);
    assertEquals(updatedState, loadedState);
    indicesMap = new HashMap<>();
    indicesMap.put("test_index_3", new IndexInfo());
    PersistentGlobalState updatedState2 = new PersistentGlobalState(indicesMap);
    assertNotEquals(updatedState, updatedState2);
    stateBackend.commitGlobalState(updatedState2);
    loadedState = StateUtils.readStateFromFile(filePath);
    assertEquals(updatedState2, loadedState);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) PersistentGlobalState(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) Test(org.junit.Test)

Example 13 with IndexInfo

use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.

the class RemoteStateBackendTest method testCommitGlobalState.

@Test
public void testCommitGlobalState() throws IOException {
    StateBackend stateBackend = new RemoteStateBackend(getMockGlobalState(false));
    Path localFilePath = getLocalStateFilePath();
    PersistentGlobalState initialState = stateBackend.loadOrCreateGlobalState();
    Map<String, IndexInfo> indicesMap = new HashMap<>();
    indicesMap.put("test_index", new IndexInfo());
    indicesMap.put("test_index_2", new IndexInfo());
    PersistentGlobalState updatedState = new PersistentGlobalState(indicesMap);
    assertNotEquals(initialState, updatedState);
    stateBackend.commitGlobalState(updatedState);
    PersistentGlobalState loadedState = getS3State();
    assertEquals(updatedState, loadedState);
    PersistentGlobalState loadedLocalState = StateUtils.readStateFromFile(localFilePath);
    assertEquals(updatedState, loadedLocalState);
    indicesMap = new HashMap<>();
    indicesMap.put("test_index_3", new IndexInfo());
    PersistentGlobalState updatedState2 = new PersistentGlobalState(indicesMap);
    assertNotEquals(updatedState, updatedState2);
    stateBackend.commitGlobalState(updatedState2);
    loadedState = getS3State();
    assertEquals(updatedState2, loadedState);
    loadedLocalState = StateUtils.readStateFromFile(localFilePath);
    assertEquals(updatedState2, loadedLocalState);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) PersistentGlobalState(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) Test(org.junit.Test)

Example 14 with IndexInfo

use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo in project nrtsearch by Yelp.

the class RemoteStateBackendTest method testReadOnlyWithInitialState.

@Test
public void testReadOnlyWithInitialState() throws IOException {
    StateBackend stateBackend = new RemoteStateBackend(getMockGlobalState(true));
    Map<String, IndexInfo> indicesMap = new HashMap<>();
    indicesMap.put("test_index", new IndexInfo());
    indicesMap.put("test_index_2", new IndexInfo());
    PersistentGlobalState initialState = new PersistentGlobalState(indicesMap);
    writeStateToS3(initialState);
    PersistentGlobalState loadedState = stateBackend.loadOrCreateGlobalState();
    assertEquals(initialState, loadedState);
}
Also used : HashMap(java.util.HashMap) PersistentGlobalState(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) Test(org.junit.Test)

Example 15 with IndexInfo

use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo 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;
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState)

Aggregations

IndexInfo (com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo)15 HashMap (java.util.HashMap)14 Test (org.junit.Test)14 Path (java.nio.file.Path)7 PersistentGlobalState (com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState)6 LocalStateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend)3 RemoteStateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend)3 StateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend)3 IndexState (com.yelp.nrtsearch.server.luceneserver.IndexState)1