Java Code Examples for org.apache.solr.core.SolrCore#getDirectoryFactory()

The following examples show how to use org.apache.solr.core.SolrCore#getDirectoryFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpdateHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public UpdateHandler(SolrCore core, UpdateLog updateLog)  {
  this.core=core;
  idField = core.getLatestSchema().getUniqueKeyField();
  idFieldType = idField!=null ? idField.getType() : null;
  parseEventListeners();
  PluginInfo ulogPluginInfo = core.getSolrConfig().getPluginInfo(UpdateLog.class.getName());

  // If this is a replica of type PULL, don't create the update log
  boolean skipUpdateLog = core.getCoreDescriptor().getCloudDescriptor() != null && !core.getCoreDescriptor().getCloudDescriptor().requiresTransactionLog();
  if (updateLog == null && ulogPluginInfo != null && ulogPluginInfo.isEnabled() && !skipUpdateLog) {
    DirectoryFactory dirFactory = core.getDirectoryFactory();
    if (dirFactory instanceof HdfsDirectoryFactory) {
      ulog = new HdfsUpdateLog(((HdfsDirectoryFactory)dirFactory).getConfDir());
    } else {
      String className = ulogPluginInfo.className == null ? UpdateLog.class.getName() : ulogPluginInfo.className;
      ulog = core.getResourceLoader().newInstance(className, UpdateLog.class);
    }

    if (!core.isReloaded() && !dirFactory.isPersistent()) {
      ulog.clearLog(core, ulogPluginInfo);
    }

    if (log.isInfoEnabled()) {
      log.info("Using UpdateLog implementation: {}", ulog.getClass().getName());
    }
    ulog.init(ulogPluginInfo);
    ulog.init(this, core);
  } else {
    ulog = updateLog;
  }
}
 
Example 2
Source File: TestReplicationHandler.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private CachingDirectoryFactory getCachingDirectoryFactory(SolrCore core) {
  return (CachingDirectoryFactory) core.getDirectoryFactory();
}
 
Example 3
Source File: SolrRecordWriter.java    From examples with Apache License 2.0 4 votes vote down vote up
public static EmbeddedSolrServer createEmbeddedSolrServer(Path solrHomeDir, FileSystem fs, Path outputShardDir)
    throws IOException {

  if (solrHomeDir == null) {
    throw new IOException("Unable to find solr home setting");
  }
  LOG.info("Creating embedded Solr server with solrHomeDir: " + solrHomeDir + ", fs: " + fs + ", outputShardDir: " + outputShardDir);

  Path solrDataDir = new Path(outputShardDir, "data");

  String dataDirStr = solrDataDir.toUri().toString();

  SolrResourceLoader loader = new SolrResourceLoader(solrHomeDir.toString(), null, null);

  LOG.info(String
      .format(Locale.ENGLISH, 
          "Constructed instance information solr.home %s (%s), instance dir %s, conf dir %s, writing index to solr.data.dir %s, with permdir %s",
          solrHomeDir, solrHomeDir.toUri(), loader.getInstanceDir(),
          loader.getConfigDir(), dataDirStr, outputShardDir));

  // TODO: This is fragile and should be well documented
  System.setProperty("solr.directoryFactory", HdfsDirectoryFactory.class.getName()); 
  System.setProperty("solr.lock.type", "hdfs"); 
  System.setProperty("solr.hdfs.nrtcachingdirectory", "false");
  System.setProperty("solr.hdfs.blockcache.enabled", "false");
  System.setProperty("solr.autoCommit.maxTime", "600000");
  System.setProperty("solr.autoSoftCommit.maxTime", "-1");
  
  CoreContainer container = new CoreContainer(loader);
  container.load();
  
  Properties props = new Properties();
  props.setProperty(CoreDescriptor.CORE_DATADIR, dataDirStr);
  
  CoreDescriptor descr = new CoreDescriptor(container, "core1", solrHomeDir.toString(), props);
  
  SolrCore core = container.create(descr);
  
  if (!(core.getDirectoryFactory() instanceof HdfsDirectoryFactory)) {
    throw new UnsupportedOperationException(
        "Invalid configuration. Currently, the only DirectoryFactory supported is "
            + HdfsDirectoryFactory.class.getSimpleName());
  }

  EmbeddedSolrServer solr = new EmbeddedSolrServer(container, "core1");
  return solr;
}
 
Example 4
Source File: SolrRecordWriter.java    From hbase-indexer with Apache License 2.0 4 votes vote down vote up
public static EmbeddedSolrServer createEmbeddedSolrServer(Path solrHomeDir, FileSystem fs, Path outputShardDir)
      throws IOException {

    LOG.info("Creating embedded Solr server with solrHomeDir: " + solrHomeDir + ", fs: " + fs + ", outputShardDir: " + outputShardDir);
    
    LOG.info("Using custom SolrRecordWriter class for HBaseMapReduceIndexer");
    if (LOG.isDebugEnabled()) {
      LOG.debug("Listing files contained in solrHomeDir {} ...", solrHomeDir);
      int i = 0;
      for (File file : FileUtils.listFiles(new File(solrHomeDir.toString()), null, true)) {
        // strip off common path prefix for better human readability
        String relPath = file.toString();
        relPath = relPath.substring(solrHomeDir.toString().length() + 1, relPath.length());
        LOG.debug("solrHomeDirFile[{}]: {}", i++, relPath);
      }
    }

    Path solrDataDir = new Path(outputShardDir, "data");

    String dataDirStr = solrDataDir.toUri().toString();

    SolrResourceLoader loader = new SolrResourceLoader(Paths.get(solrHomeDir.toString()), null, null);

    LOG.info(String
        .format(Locale.ENGLISH, 
            "Constructed instance information solr.home %s (%s), instance dir %s, conf dir %s, writing index to solr.data.dir %s, with permdir %s",
            solrHomeDir, solrHomeDir.toUri(), loader.getInstancePath(),
            loader.getConfigDir(), dataDirStr, outputShardDir));

    // TODO: This is fragile and should be well documented
    System.setProperty("solr.directoryFactory", HdfsDirectoryFactory.class.getName()); 
    System.setProperty("solr.lock.type", DirectoryFactory.LOCK_TYPE_HDFS);
    System.setProperty("solr.hdfs.nrtcachingdirectory", "false");
    System.setProperty("solr.hdfs.blockcache.enabled", "false");
    System.setProperty("solr.autoCommit.maxTime", "600000");
    System.setProperty("solr.autoSoftCommit.maxTime", "-1");
    
    CoreContainer container = new CoreContainer(loader);
    container.load();

    SolrCore core = container.create("core1", Paths.get(solrHomeDir.toString()), ImmutableMap.of(CoreDescriptor.CORE_DATADIR, dataDirStr), false);
//    SolrCore core = container.create("", ImmutableMap.of(CoreDescriptor.CORE_DATADIR, dataDirStr));
    
    if (!(core.getDirectoryFactory() instanceof HdfsDirectoryFactory)) {
      throw new UnsupportedOperationException(
          "Invalid configuration. Currently, the only DirectoryFactory supported is "
              + HdfsDirectoryFactory.class.getSimpleName());
    }

    EmbeddedSolrServer solr = new EmbeddedSolrServer(container, "core1");
//    EmbeddedSolrServer solr = new EmbeddedSolrServer(container, "");
    return solr;
  }
 
Example 5
Source File: TestUtils.java    From hbase-indexer with Apache License 2.0 4 votes vote down vote up
private static EmbeddedSolrServer createEmbeddedSolrServer(File solrHomeDir, FileSystem fs, Path outputShardDir)
        throws IOException {

  LOG.info("Creating embedded Solr server with solrHomeDir: " + solrHomeDir + ", fs: " + fs + ", outputShardDir: " + outputShardDir);

  // copy solrHomeDir to ensure it isn't modified across multiple unit tests or multiple EmbeddedSolrServer instances
  File tmpDir = Files.createTempDir();
  tmpDir.deleteOnExit();
  FileUtils.copyDirectory(solrHomeDir, tmpDir);
  solrHomeDir = tmpDir;

  Path solrDataDir = new Path(outputShardDir, "data");

  String dataDirStr = solrDataDir.toUri().toString();

  SolrResourceLoader loader = new SolrResourceLoader(Paths.get(solrHomeDir.toString()), null, null);

  LOG.info(String
          .format(Locale.ENGLISH,
                  "Constructed instance information solr.home %s (%s), instance dir %s, conf dir %s, writing index to solr.data.dir %s, with permdir %s",
                  solrHomeDir, solrHomeDir.toURI(), loader.getInstancePath(),
                  loader.getConfigDir(), dataDirStr, outputShardDir));

  // TODO: This is fragile and should be well documented
  System.setProperty("solr.directoryFactory", HdfsDirectoryFactory.class.getName());
  System.setProperty("solr.lock.type", DirectoryFactory.LOCK_TYPE_HDFS);
  System.setProperty("solr.hdfs.nrtcachingdirectory", "false");
  System.setProperty("solr.hdfs.blockcache.enabled", "false");
  System.setProperty("solr.autoCommit.maxTime", "600000");
  System.setProperty("solr.autoSoftCommit.maxTime", "-1");

  CoreContainer container = new CoreContainer(loader);
  container.load();

  SolrCore core = container.create("core1", Paths.get(solrHomeDir.toString()), ImmutableMap.of(CoreDescriptor.CORE_DATADIR, dataDirStr), false);

  if (!(core.getDirectoryFactory() instanceof HdfsDirectoryFactory)) {
    throw new UnsupportedOperationException(
            "Invalid configuration. Currently, the only DirectoryFactory supported is "
                    + HdfsDirectoryFactory.class.getSimpleName());
  }

  EmbeddedSolrServer solr = new EmbeddedSolrServer(container, "core1");
  return solr;
}