-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Recursively Delete Unreferenced Index Directories #42189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
09ec6f3
20a6720
273a165
aba91e1
ac3c496
e593e0c
de61d35
22a668e
3d7da2e
826e513
96dabb7
c0e025e
e99e5c0
0e66c19
e4aa770
a2bfa0f
98dc56c
372fd26
5eb036b
3d1e26b
cb2a196
2ca8c4c
908cfeb
2d0f368
d72cbcd
b9b4c32
8a82885
ae4c9a8
b8441ac
f50a895
014f5e0
f825d3f
2e0bd14
1c33d31
bb3fb73
def2d77
d6fa0fe
e7a3c2b
bb95f7f
9cac1a4
c8394fe
b338a91
a8bf18e
be8b479
58fcfe2
1e39e9b
5b5ddb2
dc62d64
c52a394
dea1a07
43bb00a
af47bb8
47766e1
81aab9b
deb73e3
b8a7067
c613d89
d841af4
e13d799
f384e9c
79478cb
bc1497e
421553b
b3478b5
bbb9632
26df577
7617660
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| import org.elasticsearch.ExceptionsHelper; | ||
| import org.elasticsearch.common.Nullable; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.blobstore.BlobContainer; | ||
| import org.elasticsearch.common.blobstore.BlobMetaData; | ||
| import org.elasticsearch.common.blobstore.BlobPath; | ||
| import org.elasticsearch.common.blobstore.BlobStoreException; | ||
|
|
@@ -231,6 +232,36 @@ public Map<String, BlobMetaData> listBlobs() throws IOException { | |
| return listBlobsByPrefix(null); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, BlobContainer> children() throws IOException { | ||
| try (AmazonS3Reference clientReference = blobStore.clientReference()) { | ||
| ObjectListing prevListing = null; | ||
| final var entries = new ArrayList<Map.Entry<String, BlobContainer>>(); | ||
| while (true) { | ||
| ObjectListing list; | ||
| if (prevListing != null) { | ||
| final ObjectListing finalPrevListing = prevListing; | ||
| list = SocketAccess.doPrivileged(() -> clientReference.client().listNextBatchOfObjects(finalPrevListing)); | ||
| } else { | ||
| list = SocketAccess.doPrivileged(() -> clientReference.client().listObjects(blobStore.bucket(), keyPath)); | ||
| } | ||
| for (final String summary : list.getCommonPrefixes()) { | ||
| final String name = summary.substring(keyPath.length()); | ||
| final BlobPath path = path().add(name); | ||
| entries.add(entry(name, blobStore.blobContainer(path))); | ||
| } | ||
| if (list.isTruncated()) { | ||
| prevListing = list; | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| return Maps.ofEntries(entries); | ||
| } catch (final AmazonClientException e) { | ||
| throw new IOException("Exception when listing children", e); | ||
|
||
| } | ||
| } | ||
|
|
||
| private String buildKey(String blobName) { | ||
| return keyPath + blobName; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,6 +158,16 @@ default void deleteBlobIgnoringIfNotExists(String blobName) throws IOException { | |
| */ | ||
| Map<String, BlobMetaData> listBlobs() throws IOException; | ||
|
|
||
| /** | ||
| * Lists all child containers under this container. A child container is defined as a container whose {@link #path()} method returns | ||
| * a path that has the return of this container's {@link #path()} method as a prefix with a single path component added to it. | ||
|
||
| * The path component by which a container and its child differ is referred to as the name of the child container below. | ||
| * | ||
| * @return Map of name of the child container to child container | ||
| * @throws IOException on failure to list child containers | ||
| */ | ||
| Map<String, BlobContainer> children() throws IOException; | ||
|
|
||
| /** | ||
| * Lists all blobs in the container that match the specified prefix. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| package org.elasticsearch.common.blobstore.fs; | ||
|
|
||
| import org.elasticsearch.common.UUIDs; | ||
| import org.elasticsearch.common.blobstore.BlobContainer; | ||
| import org.elasticsearch.common.blobstore.BlobMetaData; | ||
| import org.elasticsearch.common.blobstore.BlobPath; | ||
| import org.elasticsearch.common.blobstore.support.AbstractBlobContainer; | ||
|
|
@@ -73,6 +74,22 @@ public Map<String, BlobMetaData> listBlobs() throws IOException { | |
| return listBlobsByPrefix(null); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, BlobContainer> children() throws IOException { | ||
| // If we get duplicate files we should just take the last entry | ||
|
||
| Map<String, BlobContainer> builder = new HashMap<>(); | ||
| try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { | ||
| for (Path file : stream) { | ||
| final BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class); | ||
| if (attrs.isDirectory()) { | ||
|
||
| final String name = file.getFileName().toString(); | ||
| builder.put(name, new FsBlobContainer(blobStore, path().add(name), file)); | ||
| } | ||
| } | ||
| } | ||
| return unmodifiableMap(builder); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, BlobMetaData> listBlobsByPrefix(String blobNamePrefix) throws IOException { | ||
| // If we get duplicate files we should just take the last entry | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.