add the ability to list shard index blobs without actually having one created

This commit is contained in:
kimchy 2010-06-30 22:54:59 +03:00
parent dea8238ced
commit 6709518c4e
2 changed files with 41 additions and 6 deletions

View File

@ -20,8 +20,11 @@
package org.elasticsearch.index.gateway.blobstore;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.common.blobstore.BlobMetaData;
import org.elasticsearch.common.blobstore.BlobPath;
import org.elasticsearch.common.blobstore.BlobStore;
import org.elasticsearch.common.blobstore.ImmutableBlobContainer;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.gateway.Gateway;
@ -32,6 +35,8 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.gateway.IndexGateway;
import org.elasticsearch.index.settings.IndexSettings;
import java.io.IOException;
/**
* @author kimchy (shay.banon)
*/
@ -60,6 +65,11 @@ public abstract class BlobStoreIndexGateway extends AbstractIndexComponent imple
this.indexPath = this.gateway.basePath().add("indices").add(index.name());
}
public ImmutableMap<String, BlobMetaData> listIndexBlobs(int shardId) throws IOException {
ImmutableBlobContainer indexContainer = blobStore.immutableBlobContainer(shardIndexPath(shardId));
return BlobStoreIndexShardGateway.aggregateParts(indexContainer.listBlobs());
}
@Override public String toString() {
return type() + "://" + blobStore + "/" + indexPath;
}
@ -76,6 +86,18 @@ public abstract class BlobStoreIndexGateway extends AbstractIndexComponent imple
return this.chunkSize;
}
public BlobPath shardPath(int shardId) {
return indexPath.add(Integer.toString(shardId));
}
public BlobPath shardIndexPath(int shardId) {
return shardPath(shardId).add("index");
}
public BlobPath shardTranslogPath(int shardId) {
return shardPath(shardId).add("translog");
}
@Override public void close(boolean delete) throws ElasticSearchException {
if (delete) {
blobStore.delete(indexPath);

View File

@ -25,6 +25,7 @@ import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.common.blobstore.*;
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.io.stream.BytesStreamInput;
@ -100,12 +101,14 @@ public abstract class BlobStoreIndexShardGateway extends AbstractIndexShardCompo
this.store = store;
this.recoveryThrottler = recoveryThrottler;
this.chunkSize = ((BlobStoreIndexGateway) indexGateway).chunkSize(); // can be null -> no chunking
this.blobStore = ((BlobStoreIndexGateway) indexGateway).blobStore();
this.shardPath = ((BlobStoreIndexGateway) indexGateway).indexPath().add(Integer.toString(shardId.id()));
BlobStoreIndexGateway blobStoreIndexGateway = (BlobStoreIndexGateway) indexGateway;
this.indexContainer = blobStore.immutableBlobContainer(shardPath.add("index"));
this.translogContainer = blobStore.appendableBlobContainer(shardPath.add("translog"));
this.chunkSize = blobStoreIndexGateway.chunkSize(); // can be null -> no chunking
this.blobStore = blobStoreIndexGateway.blobStore();
this.shardPath = blobStoreIndexGateway.shardPath(shardId.id());
this.indexContainer = blobStore.immutableBlobContainer(blobStoreIndexGateway.shardIndexPath(shardId.id()));
this.translogContainer = blobStore.appendableBlobContainer(blobStoreIndexGateway.shardTranslogPath(shardId.id()));
}
@Override public String toString() {
@ -621,7 +624,17 @@ public abstract class BlobStoreIndexShardGateway extends AbstractIndexShardCompo
}
}
private TObjectLongHashMap<String> buildCombinedPartsBlobs(ImmutableMap<String, BlobMetaData> blobs) {
public static ImmutableMap<String, BlobMetaData> aggregateParts(ImmutableMap<String, BlobMetaData> blobs) {
TObjectLongHashMap<String> combined = buildCombinedPartsBlobs(blobs);
ImmutableMap.Builder<String, BlobMetaData> builder = ImmutableMap.builder();
for (TObjectLongIterator<String> it = combined.iterator(); it.hasNext();) {
it.advance();
builder.put(it.key(), new PlainBlobMetaData(it.key(), it.value()));
}
return builder.build();
}
private static TObjectLongHashMap<String> buildCombinedPartsBlobs(ImmutableMap<String, BlobMetaData> blobs) {
TObjectLongHashMap<String> combinedBlobs = new TObjectLongHashMap<String>();
for (BlobMetaData blob : blobs.values()) {
String cleanName;