Search in sources :

Example 11 with PersistentGlobalState

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

the class RemoteStateBackend method loadOrCreateGlobalState.

@Override
public PersistentGlobalState loadOrCreateGlobalState() throws IOException {
    logger.info("Loading remote state");
    Path downloadedPath = archiver.download(globalState.getConfiguration().getServiceName(), GLOBAL_STATE_RESOURCE);
    if (downloadedPath == null) {
        PersistentGlobalState state = new PersistentGlobalState();
        logger.info("Remote state not present, initializing default");
        commitGlobalState(state);
        return state;
    } else {
        Path downloadedStateFilePath = downloadedPath.resolve(GLOBAL_STATE_FOLDER).resolve(GLOBAL_STATE_FILE);
        if (!downloadedStateFilePath.toFile().exists()) {
            throw new IllegalStateException("No state file present in downloaded directory");
        }
        // copy restored state to local state directory, not strictly required but ensures a
        // current copy of the state is always in the local directory
        Files.copy(downloadedStateFilePath, localFilePath.resolve(GLOBAL_STATE_FILE), StandardCopyOption.REPLACE_EXISTING);
        PersistentGlobalState persistentGlobalState = StateUtils.readStateFromFile(downloadedStateFilePath);
        logger.info("Loaded remote state: " + MAPPER.writeValueAsString(persistentGlobalState));
        return persistentGlobalState;
    }
}
Also used : Path(java.nio.file.Path) PersistentGlobalState(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState)

Aggregations

PersistentGlobalState (com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState)11 Path (java.nio.file.Path)9 Test (org.junit.Test)8 IndexInfo (com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo)6 HashMap (java.util.HashMap)6 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 LZ4FrameInputStream (net.jpountz.lz4.LZ4FrameInputStream)1 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)1 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)1