Removed duplicate deleteBlob methods (#18813)
Removed the following methods from the BlobContainer interface to clean up the interface: 1) deleteBlobs 2) deleteBlobsByPrefix Closes #18529
This commit is contained in:
parent
ce65ab6eb7
commit
3f2e1066d3
|
@ -99,35 +99,6 @@ public interface BlobContainer {
|
||||||
*/
|
*/
|
||||||
void deleteBlob(String blobName) throws IOException;
|
void deleteBlob(String blobName) throws IOException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes blobs with the given names. If any subset of the names do not exist in the container, this method has no
|
|
||||||
* effect for those names, and will delete the blobs for those names that do exist. If any of the blobs failed
|
|
||||||
* to delete, those blobs that were processed before it and successfully deleted will remain deleted. An exception
|
|
||||||
* is thrown at the first blob entry that fails to delete (TODO: is this the right behavior? Should we collect
|
|
||||||
* all the failed deletes into a single IOException instead?)
|
|
||||||
*
|
|
||||||
* TODO: remove, see https://github.com/elastic/elasticsearch/issues/18529
|
|
||||||
*
|
|
||||||
* @param blobNames
|
|
||||||
* The collection of blob names to delete from the container.
|
|
||||||
* @throws IOException if any of the blobs in the collection exists but could not be deleted.
|
|
||||||
*/
|
|
||||||
void deleteBlobs(Collection<String> blobNames) throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes all blobs in the container that match the specified prefix. If any of the blobs failed to delete,
|
|
||||||
* those blobs that were processed before it and successfully deleted will remain deleted. An exception is
|
|
||||||
* thrown at the first blob entry that fails to delete (TODO: is this the right behavior? Should we collect
|
|
||||||
* all the failed deletes into a single IOException instead?)
|
|
||||||
*
|
|
||||||
* TODO: remove, see: https://github.com/elastic/elasticsearch/issues/18529
|
|
||||||
*
|
|
||||||
* @param blobNamePrefix
|
|
||||||
* The prefix to match against blob names in the container. Any blob whose name has the prefix will be deleted.
|
|
||||||
* @throws IOException if any of the matching blobs failed to delete.
|
|
||||||
*/
|
|
||||||
void deleteBlobsByPrefix(String blobNamePrefix) throws IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists all blobs in the container.
|
* Lists all blobs in the container.
|
||||||
*
|
*
|
||||||
|
|
|
@ -45,21 +45,6 @@ public abstract class AbstractBlobContainer implements BlobContainer {
|
||||||
return this.path;
|
return this.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteBlobsByPrefix(final String blobNamePrefix) throws IOException {
|
|
||||||
Map<String, BlobMetaData> blobs = listBlobsByPrefix(blobNamePrefix);
|
|
||||||
for (BlobMetaData blob : blobs.values()) {
|
|
||||||
deleteBlob(blob.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteBlobs(Collection<String> blobNames) throws IOException {
|
|
||||||
for (String blob: blobNames) {
|
|
||||||
deleteBlob(blob);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeBlob(String blobName, BytesReference bytes) throws IOException {
|
public void writeBlob(String blobName, BytesReference bytes) throws IOException {
|
||||||
try (InputStream stream = bytes.streamInput()) {
|
try (InputStream stream = bytes.streamInput()) {
|
||||||
|
|
|
@ -970,37 +970,33 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
||||||
*/
|
*/
|
||||||
protected void finalize(List<SnapshotFiles> snapshots, int fileListGeneration, Map<String, BlobMetaData> blobs) {
|
protected void finalize(List<SnapshotFiles> snapshots, int fileListGeneration, Map<String, BlobMetaData> blobs) {
|
||||||
BlobStoreIndexShardSnapshots newSnapshots = new BlobStoreIndexShardSnapshots(snapshots);
|
BlobStoreIndexShardSnapshots newSnapshots = new BlobStoreIndexShardSnapshots(snapshots);
|
||||||
List<String> blobsToDelete = new ArrayList<>();
|
|
||||||
// delete old index files first
|
// delete old index files first
|
||||||
for (String blobName : blobs.keySet()) {
|
for (String blobName : blobs.keySet()) {
|
||||||
// delete old file lists
|
|
||||||
if (indexShardSnapshotsFormat.isTempBlobName(blobName) || blobName.startsWith(SNAPSHOT_INDEX_PREFIX)) {
|
if (indexShardSnapshotsFormat.isTempBlobName(blobName) || blobName.startsWith(SNAPSHOT_INDEX_PREFIX)) {
|
||||||
blobsToDelete.add(blobName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
blobContainer.deleteBlobs(blobsToDelete);
|
blobContainer.deleteBlob(blobName);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// We cannot delete index file - this is fatal, we cannot continue, otherwise we might end up
|
// We cannot delete index file - this is fatal, we cannot continue, otherwise we might end up
|
||||||
// with references to non-existing files
|
// with references to non-existing files
|
||||||
throw new IndexShardSnapshotFailedException(shardId, "error deleting index files during cleanup", e);
|
throw new IndexShardSnapshotFailedException(shardId, "error deleting index file ["
|
||||||
|
+ blobName + "] during cleanup", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blobsToDelete = new ArrayList<>();
|
// now go over all the blobs, and if they don't exist in a snapshot, delete them
|
||||||
// now go over all the blobs, and if they don't exists in a snapshot, delete them
|
|
||||||
for (String blobName : blobs.keySet()) {
|
for (String blobName : blobs.keySet()) {
|
||||||
// delete unused files
|
// delete unused files
|
||||||
if (blobName.startsWith(DATA_BLOB_PREFIX)) {
|
if (blobName.startsWith(DATA_BLOB_PREFIX)) {
|
||||||
if (newSnapshots.findNameFile(BlobStoreIndexShardSnapshot.FileInfo.canonicalName(blobName)) == null) {
|
if (newSnapshots.findNameFile(BlobStoreIndexShardSnapshot.FileInfo.canonicalName(blobName)) == null) {
|
||||||
blobsToDelete.add(blobName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
blobContainer.deleteBlobs(blobsToDelete);
|
blobContainer.deleteBlob(blobName);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.debug("[{}] [{}] error deleting some of the blobs [{}] during cleanup", e, snapshotId, shardId, blobsToDelete);
|
// TODO: don't catch and let the user handle it?
|
||||||
|
logger.debug("[{}] [{}] error deleting blob [{}] during cleanup", e, snapshotId, shardId, blobName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we deleted all snapshots - we don't need to create the index file
|
// If we deleted all snapshots - we don't need to create the index file
|
||||||
|
|
|
@ -68,16 +68,6 @@ public class BlobContainerWrapper implements BlobContainer {
|
||||||
delegate.deleteBlob(blobName);
|
delegate.deleteBlob(blobName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteBlobs(Collection<String> blobNames) throws IOException {
|
|
||||||
delegate.deleteBlobs(blobNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteBlobsByPrefix(String blobNamePrefix) throws IOException {
|
|
||||||
delegate.deleteBlobsByPrefix(blobNamePrefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, BlobMetaData> listBlobs() throws IOException {
|
public Map<String, BlobMetaData> listBlobs() throws IOException {
|
||||||
return delegate.listBlobs();
|
return delegate.listBlobs();
|
||||||
|
|
|
@ -299,12 +299,6 @@ public class MockRepository extends FsRepository {
|
||||||
super.deleteBlob(blobName);
|
super.deleteBlob(blobName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteBlobsByPrefix(String blobNamePrefix) throws IOException {
|
|
||||||
maybeIOExceptionOrBlock(blobNamePrefix);
|
|
||||||
super.deleteBlobsByPrefix(blobNamePrefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, BlobMetaData> listBlobs() throws IOException {
|
public Map<String, BlobMetaData> listBlobs() throws IOException {
|
||||||
maybeIOExceptionOrBlock("");
|
maybeIOExceptionOrBlock("");
|
||||||
|
|
|
@ -84,16 +84,6 @@ public class GoogleCloudStorageBlobContainer extends AbstractBlobContainer {
|
||||||
blobStore.deleteBlob(buildKey(blobName));
|
blobStore.deleteBlob(buildKey(blobName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteBlobsByPrefix(String prefix) throws IOException {
|
|
||||||
blobStore.deleteBlobsByPrefix(buildKey(prefix));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteBlobs(Collection<String> blobNames) throws IOException {
|
|
||||||
blobStore.deleteBlobs(buildKeys(blobNames));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void move(String sourceBlobName, String targetBlobName) throws IOException {
|
public void move(String sourceBlobName, String targetBlobName) throws IOException {
|
||||||
blobStore.moveBlob(buildKey(sourceBlobName), buildKey(targetBlobName));
|
blobStore.moveBlob(buildKey(sourceBlobName), buildKey(targetBlobName));
|
||||||
|
@ -103,12 +93,4 @@ public class GoogleCloudStorageBlobContainer extends AbstractBlobContainer {
|
||||||
assert blobName != null;
|
assert blobName != null;
|
||||||
return path + blobName;
|
return path + blobName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set<String> buildKeys(Collection<String> blobNames) {
|
|
||||||
Set<String> keys = new HashSet<>();
|
|
||||||
if (blobNames != null) {
|
|
||||||
keys.addAll(blobNames.stream().map(this::buildKey).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue