Skip to content

Commit

Permalink
SwiftBlobContainer: Add ability to list child containers
Browse files Browse the repository at this point in the history
These are used to delete unreferenced index directories recursively[1],
for details check this commit[2].

[1]: elastic/elasticsearch#42189
[2]: elastic/elasticsearch@2f637d4
  • Loading branch information
avgerin0s committed Aug 18, 2020
1 parent 9b6c5da commit f241ba9
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.blobstore.BlobMetaData;
import org.elasticsearch.common.blobstore.BlobPath;
import org.elasticsearch.common.blobstore.BlobContainer;
import org.elasticsearch.common.blobstore.DeleteResult;
import org.elasticsearch.common.blobstore.support.AbstractBlobContainer;
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
Expand Down Expand Up @@ -154,6 +155,31 @@ public Map<String, BlobMetaData> listBlobsByPrefix(@Nullable final String blobNa
});
}

@Override
public Map<String, BlobContainer> children() throws IOException {
return SwiftPerms.exec(() -> {
MapBuilder<String, BlobContainer> blobContainerBuilder = MapBuilder.newMapBuilder();
String path = path().buildAsString();
Collection<DirectoryOrObject> files = blobStore.swift().listDirectory(new Directory(path, '/'));

if (files != null && !files.isEmpty()) {
for (DirectoryOrObject directory : files) {
String name = directory.getName();
String indexKey = name.substring(keyPath.length(), name.length() - 1);

if (! blobContainerBuilder.containsKey(indexKey)) {
BlobPath p = new BlobPath();
p = p.add(directory.getName());
blobContainerBuilder.put(indexKey, new SwiftBlobContainer(p, blobStore));
}

}
}

return blobContainerBuilder.immutableMap();
});
}

/**
* Get all the blobs
*/
Expand Down

0 comments on commit f241ba9

Please sign in to comment.