private boolean commitPointFileExistsInBlobs(
     CommitPoint.FileInfo fileInfo, ImmutableMap<String, BlobMetaData> blobs) {
   BlobMetaData blobMetaData = blobs.get(fileInfo.name());
   if (blobMetaData != null) {
     if (blobMetaData.length() != fileInfo.length()) {
       return false;
     }
   } else if (blobs.containsKey(fileInfo.name() + ".part0")) {
     // multi part file sum up the size and check
     int part = 0;
     long totalSize = 0;
     while (true) {
       blobMetaData = blobs.get(fileInfo.name() + ".part" + part++);
       if (blobMetaData == null) {
         break;
       }
       totalSize += blobMetaData.length();
     }
     if (totalSize != fileInfo.length()) {
       return false;
     }
   } else {
     // no file, not exact and not multipart
     return false;
   }
   return true;
 }
Exemplo n.º 2
0
 public CommitPoint findCommitPoint(String index, int shardId) throws IOException {
   BlobPath path = BlobStoreIndexGateway.shardPath(basePath, index, shardId);
   ImmutableBlobContainer container = blobStore.immutableBlobContainer(path);
   ImmutableMap<String, BlobMetaData> blobs = container.listBlobs();
   List<CommitPoint> commitPointsList = Lists.newArrayList();
   for (BlobMetaData md : blobs.values()) {
     if (md.length() == 0) { // a commit point that was not flushed yet...
       continue;
     }
     if (md.name().startsWith("commit-")) {
       try {
         commitPointsList.add(CommitPoints.fromXContent(container.readBlobFully(md.name())));
       } catch (Exception e) {
         logger.warn("failed to read commit point at path {} with name [{}]", e, path, md.name());
       }
     }
   }
   CommitPoints commitPoints = new CommitPoints(commitPointsList);
   if (commitPoints.commits().isEmpty()) {
     return null;
   }
   return commitPoints.commits().get(0);
 }