示例#1
0
  private int findLatestIndex() throws IOException {
    ImmutableMap<String, BlobMetaData> blobs = metaDataBlobContainer.listBlobsByPrefix("metadata-");

    int index = -1;
    for (BlobMetaData md : blobs.values()) {
      if (logger.isTraceEnabled()) {
        logger.trace("[findLatestMetadata]: Processing [" + md.name() + "]");
      }
      String name = md.name();
      int fileIndex = Integer.parseInt(name.substring(name.indexOf('-') + 1));
      if (fileIndex >= index) {
        // try and read the meta data
        byte[] data = null;
        try {
          data = metaDataBlobContainer.readBlobFully(name);
          readMetaData(data);
          index = fileIndex;
        } catch (IOException e) {
          logger.warn(
              "[findLatestMetadata]: failed to read metadata from [{}], data_length [{}] ignoring...",
              e,
              name,
              data == null ? "na" : data.length);
        }
      }
    }

    return index;
  }
示例#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);
 }