Search in sources :

Example 1 with SolrSnapshotMetaDataManager

use of org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager in project lucene-solr by apache.

the class SolrCore method initSnapshotMetaDataManager.

private SolrSnapshotMetaDataManager initSnapshotMetaDataManager() {
    try {
        String dirName = getDataDir() + SolrSnapshotMetaDataManager.SNAPSHOT_METADATA_DIR + "/";
        Directory snapshotDir = directoryFactory.get(dirName, DirContext.DEFAULT, getSolrConfig().indexConfig.lockType);
        return new SolrSnapshotMetaDataManager(this, snapshotDir);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
Also used : SolrSnapshotMetaDataManager(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager) IOException(java.io.IOException) Directory(org.apache.lucene.store.Directory)

Example 2 with SolrSnapshotMetaDataManager

use of org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager in project lucene-solr by apache.

the class CreateSnapshotOp method execute.

@Override
public void execute(CoreAdminHandler.CallInfo it) throws Exception {
    CoreContainer cc = it.handler.getCoreContainer();
    final SolrParams params = it.req.getParams();
    String commitName = params.required().get(CoreAdminParams.COMMIT_NAME);
    String cname = params.required().get(CoreAdminParams.CORE);
    try (SolrCore core = cc.getCore(cname)) {
        if (core == null) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to locate core " + cname);
        }
        String indexDirPath = core.getIndexDir();
        IndexCommit ic = core.getDeletionPolicy().getLatestCommit();
        if (ic == null) {
            RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
            try {
                ic = searcher.get().getIndexReader().getIndexCommit();
            } finally {
                searcher.decref();
            }
        }
        SolrSnapshotMetaDataManager mgr = core.getSnapshotMetaDataManager();
        mgr.snapshot(commitName, indexDirPath, ic.getGeneration());
        it.rsp.add(CoreAdminParams.CORE, core.getName());
        it.rsp.add(CoreAdminParams.COMMIT_NAME, commitName);
        it.rsp.add(SolrSnapshotManager.INDEX_DIR_PATH, indexDirPath);
        it.rsp.add(SolrSnapshotManager.GENERATION_NUM, ic.getGeneration());
        it.rsp.add(SolrSnapshotManager.FILE_LIST, ic.getFileNames());
    }
}
Also used : SolrSnapshotMetaDataManager(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager) CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) SolrParams(org.apache.solr.common.params.SolrParams) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) SolrException(org.apache.solr.common.SolrException) IndexCommit(org.apache.lucene.index.IndexCommit)

Example 3 with SolrSnapshotMetaDataManager

use of org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager in project lucene-solr by apache.

the class ReplicationHandler method doSnapShoot.

private void doSnapShoot(SolrParams params, SolrQueryResponse rsp, SolrQueryRequest req) {
    try {
        int numberToKeep = params.getInt(NUMBER_BACKUPS_TO_KEEP_REQUEST_PARAM, 0);
        if (numberToKeep > 0 && numberBackupsToKeep > 0) {
            throw new SolrException(ErrorCode.BAD_REQUEST, "Cannot use " + NUMBER_BACKUPS_TO_KEEP_REQUEST_PARAM + " if " + NUMBER_BACKUPS_TO_KEEP_INIT_PARAM + " was specified in the configuration.");
        }
        numberToKeep = Math.max(numberToKeep, numberBackupsToKeep);
        if (numberToKeep < 1) {
            numberToKeep = Integer.MAX_VALUE;
        }
        IndexCommit indexCommit = null;
        String commitName = params.get(CoreAdminParams.COMMIT_NAME);
        if (commitName != null) {
            SolrSnapshotMetaDataManager snapshotMgr = core.getSnapshotMetaDataManager();
            Optional<IndexCommit> commit = snapshotMgr.getIndexCommitByName(commitName);
            if (commit.isPresent()) {
                indexCommit = commit.get();
            } else {
                throw new SolrException(ErrorCode.BAD_REQUEST, "Unable to find an index commit with name " + commitName + " for core " + core.getName());
            }
        } else {
            IndexDeletionPolicyWrapper delPolicy = core.getDeletionPolicy();
            indexCommit = delPolicy.getLatestCommit();
            if (indexCommit == null) {
                indexCommit = req.getSearcher().getIndexReader().getIndexCommit();
            }
        }
        String location = params.get(CoreAdminParams.BACKUP_LOCATION);
        String repoName = params.get(CoreAdminParams.BACKUP_REPOSITORY);
        CoreContainer cc = core.getCoreContainer();
        BackupRepository repo = null;
        if (repoName != null) {
            repo = cc.newBackupRepository(Optional.of(repoName));
            location = repo.getBackupLocation(location);
            if (location == null) {
                throw new IllegalArgumentException("location is required");
            }
        } else {
            repo = new LocalFileSystemRepository();
            if (location == null) {
                location = core.getDataDir();
            } else {
                location = core.getCoreDescriptor().getInstanceDir().resolve(location).normalize().toString();
            }
        }
        // small race here before the commit point is saved
        URI locationUri = repo.createURI(location);
        SnapShooter snapShooter = new SnapShooter(repo, core, locationUri, params.get(NAME), commitName);
        snapShooter.validateCreateSnapshot();
        snapShooter.createSnapAsync(indexCommit, numberToKeep, (nl) -> snapShootDetails = nl);
    } catch (Exception e) {
        LOG.warn("Exception during creating a snapshot", e);
        rsp.add("exception", e);
    }
}
Also used : IndexDeletionPolicyWrapper(org.apache.solr.core.IndexDeletionPolicyWrapper) LocalFileSystemRepository(org.apache.solr.core.backup.repository.LocalFileSystemRepository) URI(java.net.URI) IndexCommit(org.apache.lucene.index.IndexCommit) NoSuchFileException(java.nio.file.NoSuchFileException) SolrException(org.apache.solr.common.SolrException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SolrSnapshotMetaDataManager(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager) BackupRepository(org.apache.solr.core.backup.repository.BackupRepository) CoreContainer(org.apache.solr.core.CoreContainer) SolrException(org.apache.solr.common.SolrException)

Example 4 with SolrSnapshotMetaDataManager

use of org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager in project lucene-solr by apache.

the class SnapShooter method createSnapshot.

public NamedList createSnapshot() throws Exception {
    RefCounted<SolrIndexSearcher> searcher = solrCore.getSearcher();
    try {
        if (commitName != null) {
            SolrSnapshotMetaDataManager snapshotMgr = solrCore.getSnapshotMetaDataManager();
            Optional<IndexCommit> commit = snapshotMgr.getIndexCommitByName(commitName);
            if (commit.isPresent()) {
                return createSnapshot(commit.get());
            }
            throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to find an index commit with name " + commitName + " for core " + solrCore.getName());
        } else {
            //TODO should we try solrCore.getDeletionPolicy().getLatestCommit() first?
            IndexDeletionPolicyWrapper deletionPolicy = solrCore.getDeletionPolicy();
            IndexCommit indexCommit = searcher.get().getIndexReader().getIndexCommit();
            deletionPolicy.saveCommitPoint(indexCommit.getGeneration());
            try {
                return createSnapshot(indexCommit);
            } finally {
                deletionPolicy.releaseCommitPoint(indexCommit.getGeneration());
            }
        }
    } finally {
        searcher.decref();
    }
}
Also used : SolrSnapshotMetaDataManager(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager) IndexDeletionPolicyWrapper(org.apache.solr.core.IndexDeletionPolicyWrapper) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) IndexCommit(org.apache.lucene.index.IndexCommit) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrSnapshotMetaDataManager (org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager)4 IndexCommit (org.apache.lucene.index.IndexCommit)3 SolrException (org.apache.solr.common.SolrException)3 IOException (java.io.IOException)2 CoreContainer (org.apache.solr.core.CoreContainer)2 IndexDeletionPolicyWrapper (org.apache.solr.core.IndexDeletionPolicyWrapper)2 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)2 FileNotFoundException (java.io.FileNotFoundException)1 URI (java.net.URI)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Directory (org.apache.lucene.store.Directory)1 SolrParams (org.apache.solr.common.params.SolrParams)1 SolrCore (org.apache.solr.core.SolrCore)1 BackupRepository (org.apache.solr.core.backup.repository.BackupRepository)1 LocalFileSystemRepository (org.apache.solr.core.backup.repository.LocalFileSystemRepository)1