Ejemplo n.º 1
0
 @Override
 public SyncedFlushResult syncFlush(String syncId, CommitId expectedCommitId)
     throws EngineException {
   // best effort attempt before we acquire locks
   ensureOpen();
   if (indexWriter.hasUncommittedChanges()) {
     logger.trace("can't sync commit [{}]. have pending changes", syncId);
     return SyncedFlushResult.PENDING_OPERATIONS;
   }
   if (expectedCommitId.idsEqual(lastCommittedSegmentInfos.getId()) == false) {
     logger.trace("can't sync commit [{}]. current commit id is not equal to expected.", syncId);
     return SyncedFlushResult.COMMIT_MISMATCH;
   }
   try (ReleasableLock lock = writeLock.acquire()) {
     ensureOpen();
     ensureCanFlush();
     if (indexWriter.hasUncommittedChanges()) {
       logger.trace("can't sync commit [{}]. have pending changes", syncId);
       return SyncedFlushResult.PENDING_OPERATIONS;
     }
     if (expectedCommitId.idsEqual(lastCommittedSegmentInfos.getId()) == false) {
       logger.trace("can't sync commit [{}]. current commit id is not equal to expected.", syncId);
       return SyncedFlushResult.COMMIT_MISMATCH;
     }
     logger.trace("starting sync commit [{}]", syncId);
     commitIndexWriter(indexWriter, translog, syncId);
     logger.debug("successfully sync committed. sync id [{}].", syncId);
     lastCommittedSegmentInfos = store.readLastCommittedSegmentsInfo();
     return SyncedFlushResult.SUCCESS;
   } catch (IOException ex) {
     maybeFailEngine("sync commit", ex);
     throw new EngineException(shardId, "failed to sync commit", ex);
   }
 }
Ejemplo n.º 2
0
  public RefsModel(
      @NotNull Map<VirtualFile, CompressedRefs> refs,
      @NotNull Set<Integer> heads,
      @NotNull VcsLogStorage hashMap,
      @NotNull Map<VirtualFile, VcsLogProvider> providers) {
    myRefs = refs;
    myHashMap = hashMap;

    myBestRefForHead = new TIntObjectHashMap<>();
    myRootForHead = new TIntObjectHashMap<>();
    for (int head : heads) {
      CommitId commitId = myHashMap.getCommitId(head);
      if (commitId != null) {
        VirtualFile root = commitId.getRoot();
        myRootForHead.put(head, root);
        Optional<VcsRef> bestRef =
            myRefs
                .get(root)
                .refsToCommit(head)
                .stream()
                .min(providers.get(root).getReferenceManager().getBranchLayoutComparator());
        if (bestRef.isPresent()) {
          myBestRefForHead.put(head, bestRef.get());
        } else {
          LOG.warn("No references at head " + commitId);
        }
      }
    }
  }
Ejemplo n.º 3
0
 public Collection<VcsRef> refsToCommit(int index) {
   CommitId id = myHashMap.getCommitId(index);
   if (id == null) return Collections.emptyList();
   VirtualFile root = id.getRoot();
   return myRefs.get(root).refsToCommit(index);
 }