• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ReplicationHandler类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.apache.solr.handler.ReplicationHandler的典型用法代码示例。如果您正苦于以下问题:Java ReplicationHandler类的具体用法?Java ReplicationHandler怎么用?Java ReplicationHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ReplicationHandler类属于org.apache.solr.handler包,在下文中一共展示了ReplicationHandler类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: replicate

点赞 2

import org.apache.solr.handler.ReplicationHandler; //导入依赖的package包/类
private void replicate(String nodeName, SolrCore core, ZkNodeProps leaderprops)
    throws SolrServerException, IOException {

  ZkCoreNodeProps leaderCNodeProps = new ZkCoreNodeProps(leaderprops);
  String leaderUrl = leaderCNodeProps.getCoreUrl();
  
  log.info("Attempting to replicate from " + leaderUrl + ". core=" + coreName);
  
  // send commit
  commitOnLeader(leaderUrl);
  
  // use rep handler directly, so we can do this sync rather than async
  SolrRequestHandler handler = core.getRequestHandler(REPLICATION_HANDLER);
  if (handler instanceof LazyRequestHandlerWrapper) {
    handler = ((LazyRequestHandlerWrapper) handler).getWrappedHandler();
  }
  ReplicationHandler replicationHandler = (ReplicationHandler) handler;
  
  if (replicationHandler == null) {
    throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE,
        "Skipping recovery, no " + REPLICATION_HANDLER + " handler found");
  }
  
  ModifiableSolrParams solrParams = new ModifiableSolrParams();
  solrParams.set(ReplicationHandler.MASTER_URL, leaderUrl);
  
  if (isClosed()) return; // we check closed on return
  boolean success = replicationHandler.doFetch(solrParams, false);
  
  if (!success) {
    throw new SolrException(ErrorCode.SERVER_ERROR,
        "Replication for recovery failed.");
  }
  
  // solrcloud_debug
  if (log.isDebugEnabled()) {
    try {
      RefCounted<SolrIndexSearcher> searchHolder = core
          .getNewestSearcher(false);
      SolrIndexSearcher searcher = searchHolder.get();
      Directory dir = core.getDirectoryFactory().get(core.getIndexDir(), DirContext.META_DATA, null);
      try {
        log.debug(core.getCoreDescriptor().getCoreContainer()
            .getZkController().getNodeName()
            + " replicated "
            + searcher.search(new MatchAllDocsQuery(), 1).totalHits
            + " from "
            + leaderUrl
            + " gen:"
            + core.getDeletionPolicy().getLatestCommit().getGeneration()
            + " data:" + core.getDataDir()
            + " index:" + core.getIndexDir()
            + " newIndex:" + core.getNewIndexDir()
            + " files:" + Arrays.asList(dir.listAll()));
      } finally {
        core.getDirectoryFactory().release(dir);
        searchHolder.decref();
      }
    } catch (Exception e) {
      throw new SolrException(ErrorCode.SERVER_ERROR, null, e);
    }
  }

}
 

开发者ID:europeana,
项目名称:search,
代码行数:65,
代码来源:RecoveryStrategy.java

示例2: checkForBackupSuccess

点赞 2

import org.apache.solr.handler.ReplicationHandler; //导入依赖的package包/类
private void checkForBackupSuccess(final HttpSolrServer client, File location)
    throws InterruptedException, IOException {
  class CheckStatus extends Thread {
    volatile String fail = null;
    volatile String response = null;
    volatile boolean success = false;
    final Pattern p = Pattern
        .compile("<str name=\"snapshotCompletedAt\">(.*?)</str>");
    
    CheckStatus() {}
    
    @Override
    public void run() {
      String masterUrl = client.getBaseURL() + "/replication?command="
          + ReplicationHandler.CMD_DETAILS;
      
      try {
        response = client.getHttpClient().execute(new HttpGet(masterUrl), new BasicResponseHandler());
        if (response.contains("<str name=\"status\">success</str>")) {
          Matcher m = p.matcher(response);
          if (!m.find()) {
            fail("could not find the completed timestamp in response.");
          }
          
          success = true;
        }
      } catch (Exception e) {
        e.printStackTrace();
        fail = e.getMessage();
      }
      
    };
  }
  
  int waitCnt = 0;
  CheckStatus checkStatus = new CheckStatus();
  while (true) {
    checkStatus.run();
    if (checkStatus.fail != null) {
      fail(checkStatus.fail);
    }
    if (checkStatus.success) {
      break;
    }
    Thread.sleep(500);
    if (waitCnt == 90) {
      fail("Backup success not detected:" + checkStatus.response);
    }
    waitCnt++;
  }
  
  File[] files = location.listFiles(new FilenameFilter() {
    
    @Override
    public boolean accept(File dir, String name) {
      if (name.startsWith("snapshot")) {
        return true;
      }
      return false;
    }
  });
  assertEquals(Arrays.asList(files).toString(), 1, files.length);
  File snapDir = files[0];
  
  TestUtil.rm(snapDir);
}
 

开发者ID:europeana,
项目名称:search,
代码行数:67,
代码来源:BasicDistributedZk2Test.java

示例3: replicate

点赞 2

import org.apache.solr.handler.ReplicationHandler; //导入依赖的package包/类
private void replicate(String nodeName, SolrCore core, ZkNodeProps leaderprops, String baseUrl)
      throws SolrServerException, IOException {
   
    String leaderBaseUrl = leaderprops.getStr(ZkStateReader.BASE_URL_PROP);
    ZkCoreNodeProps leaderCNodeProps = new ZkCoreNodeProps(leaderprops);
    String leaderUrl = leaderCNodeProps.getCoreUrl();
    
    log.info("Attempting to replicate from " + leaderUrl + ". core=" + coreName);
    
    // if we are the leader, either we are trying to recover faster
    // then our ephemeral timed out or we are the only node
    if (!leaderBaseUrl.equals(baseUrl)) {
      
      // send commit
      commitOnLeader(leaderUrl);
      
      // use rep handler directly, so we can do this sync rather than async
      SolrRequestHandler handler = core.getRequestHandler(REPLICATION_HANDLER);
      if (handler instanceof LazyRequestHandlerWrapper) {
        handler = ((LazyRequestHandlerWrapper)handler).getWrappedHandler();
      }
      ReplicationHandler replicationHandler = (ReplicationHandler) handler;
      
      if (replicationHandler == null) {
        throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE,
            "Skipping recovery, no " + REPLICATION_HANDLER + " handler found");
      }
      
      ModifiableSolrParams solrParams = new ModifiableSolrParams();
      solrParams.set(ReplicationHandler.MASTER_URL, leaderUrl);
      
      if (isClosed()) retries = INTERRUPTED;
      boolean success = replicationHandler.doFetch(solrParams, false);

      if (!success) {
        throw new SolrException(ErrorCode.SERVER_ERROR, "Replication for recovery failed.");
      }
      
      // solrcloud_debug
//      try {
//        RefCounted<SolrIndexSearcher> searchHolder = core.getNewestSearcher(false);
//        SolrIndexSearcher searcher = searchHolder.get();
//        try {
//          System.out.println(core.getCoreDescriptor().getCoreContainer().getZkController().getNodeName() + " replicated "
//              + searcher.search(new MatchAllDocsQuery(), 1).totalHits + " from " + leaderUrl + " gen:" + core.getDeletionPolicy().getLatestCommit().getGeneration() + " data:" + core.getDataDir());
//        } finally {
//          searchHolder.decref();
//        }
//      } catch (Exception e) {
//        
//      }
    }
  }
 

开发者ID:pkarmstr,
项目名称:NYBC,
代码行数:54,
代码来源:RecoveryStrategy.java

示例4: replicate

点赞 2

import org.apache.solr.handler.ReplicationHandler; //导入依赖的package包/类
private void replicate(String nodeName, SolrCore core, ZkNodeProps leaderprops)
    throws SolrServerException, IOException {

  ZkCoreNodeProps leaderCNodeProps = new ZkCoreNodeProps(leaderprops);
  String leaderUrl = leaderCNodeProps.getCoreUrl();
  
  log.info("Attempting to replicate from " + leaderUrl + ". core=" + coreName);
  
  // send commit
  commitOnLeader(leaderUrl);
  
  // use rep handler directly, so we can do this sync rather than async
  SolrRequestHandler handler = core.getRequestHandler(REPLICATION_HANDLER);
  if (handler instanceof LazyRequestHandlerWrapper) {
    handler = ((LazyRequestHandlerWrapper) handler).getWrappedHandler();
  }
  ReplicationHandler replicationHandler = (ReplicationHandler) handler;
  
  if (replicationHandler == null) {
    throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE,
        "Skipping recovery, no " + REPLICATION_HANDLER + " handler found");
  }
  
  ModifiableSolrParams solrParams = new ModifiableSolrParams();
  solrParams.set(ReplicationHandler.MASTER_URL, leaderUrl);
  
  if (isClosed()) retries = INTERRUPTED;
  boolean success = replicationHandler.doFetch(solrParams, false);
  
  if (!success) {
    throw new SolrException(ErrorCode.SERVER_ERROR,
        "Replication for recovery failed.");
  }
  
  // solrcloud_debug
  if (log.isDebugEnabled()) {
    try {
      RefCounted<SolrIndexSearcher> searchHolder = core
          .getNewestSearcher(false);
      SolrIndexSearcher searcher = searchHolder.get();
      Directory dir = core.getDirectoryFactory().get(core.getIndexDir(), DirContext.META_DATA, null);
      try {
        log.debug(core.getCoreDescriptor().getCoreContainer()
            .getZkController().getNodeName()
            + " replicated "
            + searcher.search(new MatchAllDocsQuery(), 1).totalHits
            + " from "
            + leaderUrl
            + " gen:"
            + core.getDeletionPolicy().getLatestCommit().getGeneration()
            + " data:" + core.getDataDir()
            + " index:" + core.getIndexDir()
            + " newIndex:" + core.getNewIndexDir()
            + " files:" + Arrays.asList(dir.listAll()));
      } finally {
        core.getDirectoryFactory().release(dir);
        searchHolder.decref();
      }
    } catch (Exception e) {
      throw new SolrException(ErrorCode.SERVER_ERROR, null, e);
    }
  }

}
 

开发者ID:yintaoxue,
项目名称:read-open-source-code,
代码行数:65,
代码来源:RecoveryStrategy.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)