Package org.apache.lucene.index

Examples of org.apache.lucene.index.IndexCommit


  @Test
  public void testCommitAge() throws InterruptedException {
    IndexDeletionPolicyWrapper delPolicy = h.getCore().getDeletionPolicy();
    addDocs();
    Map<Long, IndexCommit> commits = delPolicy.getCommits();
    IndexCommit ic = delPolicy.getLatestCommit();
    String agestr = ((SolrDeletionPolicy) (delPolicy.getWrappedDeletionPolicy())).getMaxCommitAge().replaceAll("[a-zA-Z]", "").replaceAll("-", "");
    long age = Long.parseLong(agestr);
    Thread.sleep(age);

    assertU(adoc("id", String.valueOf(6),
            "name", "name" + String.valueOf(6)));
    assertU(optimize());
    assertQ("return all docs",
            req("id:[0 TO 6]"),
            "*[count(//doc)=6]"
    );

    commits = delPolicy.getCommits();
    assertTrue(!commits.containsKey(ic.getVersion()));
  }
View Full Code Here


  public void testKeepOptimizedOnlyCommits() {

    IndexDeletionPolicyWrapper delPolicy = h.getCore().getDeletionPolicy();
    addDocs();
    Map<Long, IndexCommit> commits = delPolicy.getCommits();
    IndexCommit latest = delPolicy.getLatestCommit();
    for (Long version : commits.keySet()) {
      if (commits.get(version) == latest)
        continue;
      assertTrue(commits.get(version).isOptimized());
    }
View Full Code Here

  @Test
  public void testCommitAge() throws InterruptedException {
    IndexDeletionPolicyWrapper delPolicy = h.getCore().getDeletionPolicy();
    addDocs();
    Map<Long, IndexCommit> commits = delPolicy.getCommits();
    IndexCommit ic = delPolicy.getLatestCommit();
    String agestr = ((SolrDeletionPolicy) (delPolicy.getWrappedDeletionPolicy())).getMaxCommitAge().replaceAll("[a-zA-Z]", "").replaceAll("-", "");
    long age = Long.parseLong(agestr) * 1000;
    Thread.sleep(age);

    assertU(adoc("id", String.valueOf(6),
            "name", "name" + String.valueOf(6)));
    assertU(optimize());
    assertQ("return all docs",
            req("id:[0 TO 6]"),
            "*[count(//doc)=6]"
    );

    commits = delPolicy.getCommits();
    assertTrue(!commits.containsKey(ic.getVersion()));
  }
View Full Code Here

  private synchronized void processCommits(List commits)
  {
    int size = commits.size();
    if(size == 0) return;
   
    IndexCommit indexCommit = null;
    for(Object commit : commits)
    {
      indexCommit = (IndexCommit)commit;
      if(--size > 0 && !_currentSnapshots.containsKey(indexCommit.getSegmentsFileName()))
      {
        indexCommit.delete();
      }
    }
    _lastCommit = indexCommit;
  }
View Full Code Here

  @Override
  public void onCommit(List<? extends IndexCommit> commits) throws IOException {
    int size = commits.size();
    for (int i = 0; i < size - 1; i++) {
      IndexCommit indexCommit = commits.get(i);
      long generation = indexCommit.getGeneration();
      if (!_generationsToNames.containsKey(generation)) {
        indexCommit.delete();
      }
    }
  }
View Full Code Here

  public void createSnapshot(String name, DirectoryReader reader, String context) throws IOException {
    if (_namesToGenerations.containsKey(name)) {
      throw new IOException("Snapshot [" + name + "] already exists.");
    }
    LOG.info("Creating snapshot [{0}] in [{1}].", name, context);
    IndexCommit indexCommit = reader.getIndexCommit();
    long generation = indexCommit.getGeneration();
    _namesToGenerations.put(name, generation);
    Set<String> names = _generationsToNames.get(generation);
    if (names == null) {
      names = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
      _generationsToNames.put(generation, names);
View Full Code Here

      return;
    }
    // This command does not give the current index version of the master
    // It gives the current 'replicateable' index version
   if (command.equals(CMD_INDEX_VERSION)) {
      IndexCommit commitPoint = indexCommitPoint;  // make a copy so it won't change
      if (commitPoint != null && replicationEnabled.get()) {
        //
        // There is a race condition here.  The commit point may be changed / deleted by the time
        // we get around to reserving it.  This is a very small window though, and should not result
        // in a catastrophic failure, but will result in the client getting an empty file list for
        // the CMD_GET_FILE_LIST command.
        //
        core.getDeletionPolicy().setReserveDuration(commitPoint.getVersion(), reserveCommitDuration);
        rsp.add(CMD_INDEX_VERSION, commitPoint.getVersion());
        rsp.add(GENERATION, commitPoint.getGeneration());
      } else {
        // This happens when replication is not configured to happen after startup and no commit/optimize
        // has happened yet.
        rsp.add(CMD_INDEX_VERSION, 0L);
        rsp.add(GENERATION, 0L);
View Full Code Here

  }

  private void doSnapShoot(SolrParams params, SolrQueryResponse rsp, SolrQueryRequest req) {
    try {
      IndexDeletionPolicyWrapper delPolicy = core.getDeletionPolicy();
      IndexCommit indexCommit = delPolicy.getLatestCommit();
      // race?
      delPolicy.setReserveDuration(indexCommit.getVersion(), reserveCommitDuration);
      if(indexCommit == null) {
        indexCommit = req.getSearcher().getReader().getIndexCommit();
      }
      if (indexCommit != null)  {
        new SnapShooter(core, params.get("location")).createSnapAsync(indexCommit, this);
View Full Code Here

    if (v == null) {
      rsp.add("status", "no indexversion specified");
      return;
    }
    long version = Long.parseLong(v);
    IndexCommit commit = core.getDeletionPolicy().getCommitPoint(version);
    if (commit == null) {
      rsp.add("status", "invalid indexversion");
      return;
    }
    // reserve the indexcommit for sometime
    core.getDeletionPolicy().setReserveDuration(version, reserveCommitDuration);
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    try {
      //get all the files in the commit
      //use a set to workaround possible Lucene bug which returns same file name multiple times
      Collection<String> files = new HashSet<String>(commit.getFileNames());
      for (String fileName : files) {
        if(fileName.endsWith(".lock")) continue;
        File file = new File(core.getIndexDir(), fileName);
        Map<String, Object> fileMeta = getFileInfo(file);
        result.add(fileMeta);
View Full Code Here

    details.add("isSlave", String.valueOf(isSlave));
    long[] versionAndGeneration = getIndexVersion();
    details.add("indexVersion", versionAndGeneration[0]);
    details.add(GENERATION, versionAndGeneration[1]);

    IndexCommit commit = indexCommitPoint;  // make a copy so it won't change

    if (isMaster) {
      if (includeConfFiles != null) master.add(CONF_FILES, includeConfFiles);
      master.add(REPLICATE_AFTER, getReplicateAfterStrings());
      master.add("replicationEnabled", String.valueOf(replicationEnabled.get()));
    }

    if (isMaster && commit != null) {
      master.add("replicatableIndexVersion", commit.getVersion());
      master.add("replicatableGeneration", commit.getGeneration());
    }

    SnapPuller snapPuller = tempSnapPuller;
    if (showSlaveDetails && snapPuller != null) {
      Properties props = loadReplicationProperties();
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.IndexCommit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.