Merge pull request #12380 from jasontedor/fix/elasticsearch-cloud-azure-51
Correctly list blobs in Azure Storage to prevent snapshot corruption and do not unnecessarily duplicate Lucene segments in Azure Storage
This commit is contained in:
commit
96c245c190
|
@ -143,6 +143,6 @@ public class AzureBlobContainer extends AbstractBlobContainer {
|
|||
}
|
||||
|
||||
protected String buildKey(String blobName) {
|
||||
return keyPath + blobName;
|
||||
return keyPath + (blobName == null ? "" : blobName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,14 +173,24 @@ public class AzureStorageServiceImpl extends AbstractLifecycleComponent<AzureSto
|
|||
logger.debug("listing container [{}], keyPath [{}], prefix [{}]", container, keyPath, prefix);
|
||||
MapBuilder<String, BlobMetaData> blobsBuilder = MapBuilder.newMapBuilder();
|
||||
|
||||
CloudBlobContainer blob_container = client.getContainerReference(container);
|
||||
if (blob_container.exists()) {
|
||||
for (ListBlobItem blobItem : blob_container.listBlobs(keyPath + prefix)) {
|
||||
CloudBlobContainer blobContainer = client.getContainerReference(container);
|
||||
if (blobContainer.exists()) {
|
||||
for (ListBlobItem blobItem : blobContainer.listBlobs(keyPath + (prefix == null ? "" : prefix))) {
|
||||
URI uri = blobItem.getUri();
|
||||
logger.trace("blob url [{}]", uri);
|
||||
String blobpath = uri.getPath().substring(container.length() + 1);
|
||||
BlobProperties properties = blob_container.getBlockBlobReference(blobpath).getProperties();
|
||||
String name = blobpath.substring(keyPath.length() + 1);
|
||||
|
||||
// uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/
|
||||
// this requires 1 + container.length() + 1, with each 1 corresponding to one of the /
|
||||
String blobPath = uri.getPath().substring(1 + container.length() + 1);
|
||||
|
||||
CloudBlockBlob blob = blobContainer.getBlockBlobReference(blobPath);
|
||||
|
||||
// fetch the blob attributes from Azure (getBlockBlobReference does not do this)
|
||||
// this is needed to retrieve the blob length (among other metadata) from Azure Storage
|
||||
blob.downloadAttributes();
|
||||
|
||||
BlobProperties properties = blob.getProperties();
|
||||
String name = blobPath.substring(keyPath.length());
|
||||
logger.trace("blob url [{}], name [{}], size [{}]", uri, name, properties.getLength());
|
||||
blobsBuilder.put(name, new PlainBlobMetaData(name, properties.getLength()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue