-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Raised IOException on deleteBlob #18815
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 all commits
9a8a139
9e50e09
41dc3a7
c797068
c5e9afe
83c4d55
f328c11
ed8f982
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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.repositories.azure; | ||
|
|
||
| import com.microsoft.azure.storage.StorageException; | ||
| import org.elasticsearch.cloud.azure.blobstore.AzureBlobStore; | ||
| import org.elasticsearch.cloud.azure.storage.AzureStorageServiceMock; | ||
| import org.elasticsearch.common.blobstore.BlobStore; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.repositories.ESBlobStoreContainerTestCase; | ||
| import org.elasticsearch.repositories.RepositoryName; | ||
| import org.elasticsearch.repositories.RepositorySettings; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URISyntaxException; | ||
|
|
||
| public class AzureBlobStoreContainerTests extends ESBlobStoreContainerTestCase { | ||
| @Override | ||
| protected BlobStore newBlobStore() throws IOException { | ||
| try { | ||
| RepositoryName repositoryName = new RepositoryName("azure", "ittest"); | ||
| RepositorySettings repositorySettings = new RepositorySettings( | ||
| Settings.EMPTY, Settings.EMPTY); | ||
| AzureStorageServiceMock client = new AzureStorageServiceMock(Settings.EMPTY); | ||
| return new AzureBlobStore(repositoryName, Settings.EMPTY, repositorySettings, client); | ||
| } catch (URISyntaxException | StorageException e) { | ||
| throw new IOException(e); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,16 +68,16 @@ public Boolean run(FileContext fileContext) throws IOException { | |
|
|
||
| @Override | ||
| public void deleteBlob(String blobName) throws IOException { | ||
| try { | ||
| store.execute(new Operation<Boolean>() { | ||
| @Override | ||
| public Boolean run(FileContext fileContext) throws IOException { | ||
| return fileContext.delete(new Path(path, blobName), true); | ||
| } | ||
| }); | ||
| } catch (FileNotFoundException ok) { | ||
| // behaves like Files.deleteIfExists | ||
| if (!blobExists(blobName)) { | ||
| throw new IOException("Blob [" + blobName + "] does not exist"); | ||
| } | ||
|
|
||
| store.execute(new Operation<Boolean>() { | ||
| @Override | ||
| public Boolean run(FileContext fileContext) throws IOException { | ||
| return fileContext.delete(new Path(path, blobName), true); | ||
| } | ||
| }); | ||
|
||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.repositories.hdfs; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.AbstractFileSystem; | ||
| import org.apache.hadoop.fs.FileContext; | ||
| import org.apache.hadoop.fs.UnsupportedFileSystemException; | ||
| import org.elasticsearch.common.blobstore.BlobStore; | ||
| import org.elasticsearch.repositories.ESBlobStoreContainerTestCase; | ||
|
|
||
| import javax.security.auth.Subject; | ||
| import java.io.IOException; | ||
| import java.lang.reflect.Constructor; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.security.AccessController; | ||
| import java.security.Principal; | ||
| import java.security.PrivilegedAction; | ||
| import java.util.Collections; | ||
|
|
||
| public class HdfsBlobStoreContainerTests extends ESBlobStoreContainerTestCase { | ||
|
|
||
| @Override | ||
| protected BlobStore newBlobStore() throws IOException { | ||
| return AccessController.doPrivileged( | ||
| new PrivilegedAction<HdfsBlobStore>() { | ||
| @Override | ||
| public HdfsBlobStore run() { | ||
| try { | ||
| FileContext fileContext = createContext(new URI("hdfs:///")); | ||
| return new HdfsBlobStore(fileContext, "temp", 1024); | ||
| } catch (IOException | URISyntaxException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| public FileContext createContext(URI uri) { | ||
| // mirrors HdfsRepository.java behaviour | ||
| Configuration cfg = new Configuration(true); | ||
| cfg.setClassLoader(HdfsRepository.class.getClassLoader()); | ||
| cfg.reloadConfiguration(); | ||
|
|
||
| Constructor<?> ctor; | ||
| Subject subject; | ||
|
|
||
| try { | ||
| Class<?> clazz = Class.forName("org.apache.hadoop.security.User"); | ||
| ctor = clazz.getConstructor(String.class); | ||
| ctor.setAccessible(true); | ||
| } catch (ClassNotFoundException | NoSuchMethodException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| try { | ||
| Principal principal = (Principal) ctor.newInstance(System.getProperty("user.name")); | ||
| subject = new Subject(false, Collections.singleton(principal), | ||
| Collections.emptySet(), Collections.emptySet()); | ||
| } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| // disable file system cache | ||
| cfg.setBoolean("fs.hdfs.impl.disable.cache", true); | ||
|
|
||
| // set file system to TestingFs to avoid a bunch of security | ||
| // checks, similar to what is done in HdfsTests.java | ||
| cfg.set(String.format("fs.AbstractFileSystem.%s.impl", uri.getScheme()), | ||
| TestingFs.class.getName()); | ||
|
||
|
|
||
| // create the FileContext with our user | ||
| return Subject.doAs(subject, new PrivilegedAction<FileContext>() { | ||
| @Override | ||
| public FileContext run() { | ||
| try { | ||
| TestingFs fs = (TestingFs) AbstractFileSystem.get(uri, cfg); | ||
| return FileContext.getFileContext(fs, cfg); | ||
| } catch (UnsupportedFileSystemException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if this is this needed because just below, we catch a
HTTP_NOT_FOUNDand rethrow it as aFileNotFoundExceptionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot, Azure was ambiguous about the behavior, so its good to keep the blobExists check as you have it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, tests failed without that check.