当前位置: 首页>>代码示例>>Java>>正文


Java IndexCommit类代码示例

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


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

示例1: snapshotShard

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
@Override
public void snapshotShard(IndexShard shard, SnapshotId snapshotId, IndexId indexId, IndexCommit snapshotIndexCommit, IndexShardSnapshotStatus snapshotStatus) {
    SnapshotContext snapshotContext = new SnapshotContext(shard, snapshotId, indexId, snapshotStatus);
    snapshotStatus.startTime(System.currentTimeMillis());

    try {
        snapshotContext.snapshot(snapshotIndexCommit);
        snapshotStatus.time(System.currentTimeMillis() - snapshotStatus.startTime());
        snapshotStatus.updateStage(IndexShardSnapshotStatus.Stage.DONE);
    } catch (Exception e) {
        snapshotStatus.time(System.currentTimeMillis() - snapshotStatus.startTime());
        snapshotStatus.updateStage(IndexShardSnapshotStatus.Stage.FAILURE);
        snapshotStatus.failure(ExceptionsHelper.detailedMessage(e));
        if (e instanceof IndexShardSnapshotFailedException) {
            throw (IndexShardSnapshotFailedException) e;
        } else {
            throw new IndexShardSnapshotFailedException(shard.shardId(), e);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:BlobStoreRepository.java

示例2: readLastCommittedSegmentInfos

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
/**
 * Read the last segments info from the commit pointed to by the searcher manager
 */
protected static SegmentInfos readLastCommittedSegmentInfos(final SearcherManager sm, final Store store) throws IOException {
    IndexSearcher searcher = sm.acquire();
    try {
        IndexCommit latestCommit = ((DirectoryReader) searcher.getIndexReader()).getIndexCommit();
        return Lucene.readSegmentInfos(latestCommit);
    } catch (IOException e) {
        // Fall back to reading from the store if reading from the commit fails
        try {
            return store.readLastCommittedSegmentsInfo();
        } catch (IOException e2) {
            e2.addSuppressed(e);
            throw e2;
        }
    } finally {
        sm.release(searcher);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:Engine.java

示例3: acquireIndexCommit

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
@Override
public IndexCommit acquireIndexCommit(final boolean flushFirst) throws EngineException {
    // we have to flush outside of the readlock otherwise we might have a problem upgrading
    // the to a write lock when we fail the engine in this operation
    if (flushFirst) {
        logger.trace("start flush for snapshot");
        flush(false, true);
        logger.trace("finish flush for snapshot");
    }
    try (ReleasableLock lock = readLock.acquire()) {
        ensureOpen();
        logger.trace("pulling snapshot");
        return deletionPolicy.snapshot();
    } catch (IOException e) {
        throw new SnapshotFailedEngineException(shardId, e);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:InternalEngine.java

示例4: snapshotStoreMetadata

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
/**
 * gets a {@link Store.MetadataSnapshot} for the current directory. This method is safe to call in all lifecycle of the index shard,
 * without having to worry about the current state of the engine and concurrent flushes.
 *
 * @throws org.apache.lucene.index.IndexNotFoundException     if no index is found in the current directory
 * @throws CorruptIndexException      if the lucene index is corrupted. This can be caused by a checksum mismatch or an
 *                                    unexpected exception when opening the index reading the segments file.
 * @throws IndexFormatTooOldException if the lucene index is too old to be opened.
 * @throws IndexFormatTooNewException if the lucene index is too new to be opened.
 * @throws FileNotFoundException      if one or more files referenced by a commit are not present.
 * @throws NoSuchFileException        if one or more files referenced by a commit are not present.
 */
public Store.MetadataSnapshot snapshotStoreMetadata() throws IOException {
    IndexCommit indexCommit = null;
    store.incRef();
    try {
        synchronized (mutex) {
            // if the engine is not running, we can access the store directly, but we need to make sure no one starts
            // the engine on us. If the engine is running, we can get a snapshot via the deletion policy which is initialized.
            // That can be done out of mutex, since the engine can be closed half way.
            Engine engine = getEngineOrNull();
            if (engine == null) {
                try (Lock ignored = store.directory().obtainLock(IndexWriter.WRITE_LOCK_NAME)) {
                    return store.getMetadata(null);
                }
            }
        }
        indexCommit = deletionPolicy.snapshot();
        return store.getMetadata(indexCommit);
    } finally {
        store.decRef();
        if (indexCommit != null) {
            deletionPolicy.release(indexCommit);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:IndexShard.java

示例5: testAcquireIndexCommit

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
public void testAcquireIndexCommit() throws IOException {
    final IndexShard shard = newStartedShard();
    int numDocs = randomInt(20);
    for (int i = 0; i < numDocs; i++) {
        indexDoc(shard, "type", "id_" + i);
    }
    final boolean flushFirst = randomBoolean();
    IndexCommit commit = shard.acquireIndexCommit(flushFirst);
    int moreDocs = randomInt(20);
    for (int i = 0; i < moreDocs; i++) {
        indexDoc(shard, "type", "id_" + numDocs + i);
    }
    flushShard(shard);
    // check that we can still read the commit that we captured
    try (IndexReader reader = DirectoryReader.open(commit)) {
        assertThat(reader.numDocs(), equalTo(flushFirst ? numDocs : 0));
    }
    shard.releaseIndexCommit(commit);
    flushShard(shard, true);

    // check it's clean up
    assertThat(DirectoryReader.listCommits(shard.store().directory()), hasSize(1));

    closeShards(shard);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:IndexShardTests.java

示例6: readLastCommittedSegmentInfos

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
/**
 * Read the last segments info from the commit pointed to by the searcher manager
 */
protected static SegmentInfos readLastCommittedSegmentInfos(final SearcherManager sm, final Store store) throws IOException {
    IndexSearcher searcher = sm.acquire();
    try {
        IndexCommit latestCommit = ((DirectoryReader) searcher.getIndexReader()).getIndexCommit();
        return Lucene.readSegmentInfos(latestCommit);
    } catch (IOException e) {
        // Fall back to reading from the store if reading from the commit fails
        try {
            return store. readLastCommittedSegmentsInfo();
        } catch (IOException e2) {
            e2.addSuppressed(e);
            throw e2;
        }
    } finally {
        sm.release(searcher);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:21,代码来源:Engine.java

示例7: configureWriter

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
public static IndexWriter configureWriter(Config config, PerfRunData runData, OpenMode mode, IndexCommit commit) throws IOException {
  IndexWriterConfig iwc = createWriterConfig(config, runData, mode, commit);
  String infoStreamVal = config.get("writer.info.stream", null);
  if (infoStreamVal != null) {
    if (infoStreamVal.equals("SystemOut")) {
      iwc.setInfoStream(System.out);
    } else if (infoStreamVal.equals("SystemErr")) {
      iwc.setInfoStream(System.err);
    } else {
      File f = new File(infoStreamVal).getAbsoluteFile();
      iwc.setInfoStream(new PrintStream(new BufferedOutputStream(new FileOutputStream(f)), false, Charset.defaultCharset().name()));
    }
  }
  IndexWriter writer = new IndexWriter(runData.getDirectory(), iwc);
  return writer;
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:CreateIndexTask.java

示例8: IndexReplicationHandler

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
/**
 * Constructor with the given index directory and callback to notify when the
 * indexes were updated.
 */
public IndexReplicationHandler(Directory indexDir, Callable<Boolean> callback) throws IOException {
  this.callback = callback;
  this.indexDir = indexDir;
  currentRevisionFiles = null;
  currentVersion = null;
  if (DirectoryReader.indexExists(indexDir)) {
    final List<IndexCommit> commits = DirectoryReader.listCommits(indexDir);
    final IndexCommit commit = commits.get(commits.size() - 1);
    currentRevisionFiles = IndexRevision.revisionFiles(commit);
    currentVersion = IndexRevision.revisionVersion(commit);
    final InfoStream infoStream = InfoStream.getDefault();
    if (infoStream.isEnabled(INFO_STREAM_COMPONENT)) {
      infoStream.message(INFO_STREAM_COMPONENT, "constructor(): currentVersion=" + currentVersion
          + " currentRevisionFiles=" + currentRevisionFiles);
      infoStream.message(INFO_STREAM_COMPONENT, "constructor(): commit=" + commit);
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:IndexReplicationHandler.java

示例9: getCommits

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
private List<NamedList<Object>> getCommits() {
  Map<Long, IndexCommit> commits = core.getDeletionPolicy().getCommits();
  List<NamedList<Object>> l = new ArrayList<>();

  for (IndexCommit c : commits.values()) {
    try {
      NamedList<Object> nl = new NamedList<>();
      nl.add("indexVersion", IndexDeletionPolicyWrapper.getCommitTimestamp(c));
      nl.add(GENERATION, c.getGeneration());
      List<String> commitList = new ArrayList<>(c.getFileNames().size());
      commitList.addAll(c.getFileNames());
      Collections.sort(commitList);
      nl.add(CMD_GET_FILE_LIST, commitList);
      l.add(nl);
    } catch (IOException e) {
      LOG.warn("Exception while reading files for commit " + c, e);
    }
  }
  return l;
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:ReplicationHandler.java

示例10: getId

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
private String getId(IndexCommit commit) {
  StringBuilder sb = new StringBuilder();
  Directory dir = commit.getDirectory();

  // For anything persistent, make something that will
  // be the same, regardless of the Directory instance.
  if (dir instanceof FSDirectory) {
    FSDirectory fsd = (FSDirectory) dir;
    File fdir = fsd.getDirectory();
    sb.append(fdir.getPath());
  } else {
    sb.append(dir);
  }

  sb.append('/');
  sb.append(commit.getGeneration());
  return sb.toString();
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:SolrDeletionPolicy.java

示例11: testCommitAge

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
@Test
public void testCommitAge() throws InterruptedException {
  assumeFalse("This test is not working on Windows (or maybe machines with only 2 CPUs)",
    Constants.WINDOWS);

  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.getGeneration()));
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:TestSolrDeletionPolicy1.java

示例12: shouldReturnRealSnapshotIfIndexAllowsIt

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
@Test
public void shouldReturnRealSnapshotIfIndexAllowsIt() throws Exception
{
    // Given
    LuceneSnapshotter snapshotter = new LuceneSnapshotter();

    when(luceneSnapshot.getFileNames()).thenReturn( asList("a", "b") );

    // When
    ResourceIterator<File> snapshot = snapshotter.snapshot( indexDir, writer );

    // Then
    assertEquals( new File(indexDir, "a"), snapshot.next() );
    assertEquals( new File(indexDir, "b"), snapshot.next() );
    assertFalse( snapshot.hasNext() );
    snapshot.close();

    verify( snapshotPolicy ).release( any(IndexCommit.class) );
}
 
开发者ID:neo4j-contrib,项目名称:neo4j-lucene5-index,代码行数:20,代码来源:LuceneSnapshotterTest.java

示例13: getIndexVersion

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
private long[] getIndexVersion() {
  long version[] = new long[2];
  RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
  try {
    final IndexCommit commit = searcher.get().getIndexReader().getIndexCommit();
    final Map<String,String> commitData = commit.getUserData();
    String commitTime = commitData.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
    if (commitTime != null) {
      version[0] = Long.parseLong(commitTime);
    }
    version[1] = commit.getGeneration();
  } catch (IOException e) {
    LOG.warn("Unable to get index version : ", e);
  } finally {
    searcher.decref();
  }
  return version;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:19,代码来源:ReplicationHandler.java

示例14: str

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
static String str(IndexCommit commit) {
  StringBuilder sb = new StringBuilder();
  try {
    sb.append("commit{");

    Directory dir = commit.getDirectory();

    if (dir instanceof FSDirectory) {
      FSDirectory fsd = (FSDirectory) dir;
      sb.append("dir=").append(fsd.getDirectory());
    } else {
      sb.append("dir=").append(dir);
    }

    sb.append(",segFN=").append(commit.getSegmentsFileName());
    sb.append(",generation=").append(commit.getGeneration());
    sb.append(",filenames=").append(commit.getFileNames());
  } catch (Exception e) {
    sb.append(e);
  }
  return sb.toString();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:23,代码来源:SolrDeletionPolicy.java

示例15: onCommit

import org.apache.lucene.index.IndexCommit; //导入依赖的package包/类
@Override
public void onCommit(List<? extends IndexCommit> commits) throws IOException {
  _writeLock.lock();
  try {
    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();
      }
    }
  } finally {
    _writeLock.unlock();
  }
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:17,代码来源:SnapshotIndexDeletionPolicy.java


注:本文中的org.apache.lucene.index.IndexCommit类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。