Skip to content

Commit f241ba9

Browse files
committed
SwiftBlobContainer: Add ability to list child containers
These are used to delete unreferenced index directories recursively[1], for details check this commit[2]. [1]: elastic/elasticsearch#42189 [2]: elastic/elasticsearch@2f637d4
1 parent 9b6c5da commit f241ba9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/main/java/org/wikimedia/elasticsearch/swift/repositories/blobstore/SwiftBlobContainer.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.common.Nullable;
2020
import org.elasticsearch.common.blobstore.BlobMetaData;
2121
import org.elasticsearch.common.blobstore.BlobPath;
22+
import org.elasticsearch.common.blobstore.BlobContainer;
2223
import org.elasticsearch.common.blobstore.DeleteResult;
2324
import org.elasticsearch.common.blobstore.support.AbstractBlobContainer;
2425
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
@@ -154,6 +155,31 @@ public Map<String, BlobMetaData> listBlobsByPrefix(@Nullable final String blobNa
154155
});
155156
}
156157

158+
@Override
159+
public Map<String, BlobContainer> children() throws IOException {
160+
return SwiftPerms.exec(() -> {
161+
MapBuilder<String, BlobContainer> blobContainerBuilder = MapBuilder.newMapBuilder();
162+
String path = path().buildAsString();
163+
Collection<DirectoryOrObject> files = blobStore.swift().listDirectory(new Directory(path, '/'));
164+
165+
if (files != null && !files.isEmpty()) {
166+
for (DirectoryOrObject directory : files) {
167+
String name = directory.getName();
168+
String indexKey = name.substring(keyPath.length(), name.length() - 1);
169+
170+
if (! blobContainerBuilder.containsKey(indexKey)) {
171+
BlobPath p = new BlobPath();
172+
p = p.add(directory.getName());
173+
blobContainerBuilder.put(indexKey, new SwiftBlobContainer(p, blobStore));
174+
}
175+
176+
}
177+
}
178+
179+
return blobContainerBuilder.immutableMap();
180+
});
181+
}
182+
157183
/**
158184
* Get all the blobs
159185
*/

0 commit comments

Comments
 (0)