-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exception mappers to convert storage failures to Iceberg REST cli…
…ent exceptions * Read path for ObjectIO. * Add AccessCheckHandler to ObjectStorageMock for simulating access failures in tests. * Add exception mappers to convert storage failures to Iceberg REST client exceptions. Closes #8738
- Loading branch information
Showing
23 changed files
with
586 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../files/api/src/main/java/org/projectnessie/catalog/files/api/ObjectIOExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (C) 2024 Dremio | ||
* | ||
* Licensed 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.projectnessie.catalog.files.api; | ||
|
||
import java.time.Instant; | ||
import javax.annotation.Nullable; | ||
import org.projectnessie.catalog.files.api.ObjectIOException.IOMode; | ||
import org.projectnessie.storage.uri.StorageUri; | ||
|
||
public abstract class ObjectIOExceptionMapper { | ||
|
||
private final StorageUri uri; | ||
private final IOMode ioMode; | ||
|
||
protected ObjectIOExceptionMapper(StorageUri uri, IOMode ioMode) { | ||
this.uri = uri; | ||
this.ioMode = ioMode; | ||
} | ||
|
||
public ObjectIOException toStorageFailure(Throwable th) { | ||
while (th != null) { | ||
if (th instanceof ObjectIOException) { | ||
return (ObjectIOException) th; | ||
} | ||
|
||
ObjectIOException mapped = maybeMap(th); | ||
if (mapped != null) { | ||
return mapped; | ||
} | ||
|
||
th = th.getCause(); | ||
} | ||
|
||
return new NonRetryableException(uri, ioMode, 500, th); | ||
} | ||
|
||
@Nullable | ||
protected abstract ObjectIOException maybeMap(Throwable th); | ||
|
||
protected NonRetryableException asNonRetryableException(int httpStatusCode, Throwable cause) { | ||
return new NonRetryableException(uri, ioMode, httpStatusCode, cause); | ||
} | ||
|
||
protected BackendThrottledException asThrottledException( | ||
Instant retryNotBefore, String message, int httpStatusCode, Throwable cause) { | ||
return new BackendThrottledException( | ||
retryNotBefore, message, uri, ioMode, httpStatusCode, cause); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
catalog/files/api/src/main/java/org/projectnessie/catalog/files/api/ObjectIOInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (C) 2024 Dremio | ||
* | ||
* Licensed 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.projectnessie.catalog.files.api; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class ObjectIOInputStream extends InputStream { | ||
|
||
private final InputStream in; | ||
private final ObjectIOExceptionMapper mapper; | ||
|
||
public ObjectIOInputStream(InputStream in, ObjectIOExceptionMapper mapper) { | ||
this.in = in; | ||
this.mapper = mapper; | ||
} | ||
|
||
@Override | ||
public int read() throws IOException { | ||
try { | ||
return in.read(); | ||
} catch (IOException e) { | ||
throw mapper.toStorageFailure(e); | ||
} | ||
} | ||
|
||
@Override | ||
public int read(byte[] b, int off, int len) throws IOException { | ||
try { | ||
return in.read(b, off, len); | ||
} catch (IOException e) { | ||
throw mapper.toStorageFailure(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
try { | ||
in.close(); | ||
} catch (IOException e) { | ||
throw mapper.toStorageFailure(e); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...log/files/api/src/main/java/org/projectnessie/catalog/files/api/ObjectIOOutputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2024 Dremio | ||
* | ||
* Licensed 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.projectnessie.catalog.files.api; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import javax.annotation.Nonnull; | ||
|
||
public class ObjectIOOutputStream extends OutputStream { | ||
|
||
private final OutputStream out; | ||
private final ObjectIOExceptionMapper mapper; | ||
|
||
public ObjectIOOutputStream(OutputStream out, ObjectIOExceptionMapper mapper) { | ||
this.out = out; | ||
this.mapper = mapper; | ||
} | ||
|
||
@Override | ||
public void write(int b) throws IOException { | ||
try { | ||
out.write(b); | ||
} catch (IOException e) { | ||
throw mapper.toStorageFailure(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void write(@Nonnull byte[] b, int off, int len) throws IOException { | ||
try { | ||
out.write(b, off, len); | ||
} catch (IOException e) { | ||
throw mapper.toStorageFailure(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
try { | ||
out.close(); | ||
} catch (IOException e) { | ||
throw mapper.toStorageFailure(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...og/files/impl/src/main/java/org/projectnessie/catalog/files/adls/AdlsExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2024 Dremio | ||
* | ||
* Licensed 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.projectnessie.catalog.files.adls; | ||
|
||
import com.azure.storage.blob.models.BlobStorageException; | ||
import javax.annotation.Nullable; | ||
import org.projectnessie.catalog.files.api.ObjectIOException; | ||
import org.projectnessie.catalog.files.api.ObjectIOExceptionMapper; | ||
import org.projectnessie.storage.uri.StorageUri; | ||
|
||
public class AdlsExceptionMapper extends ObjectIOExceptionMapper { | ||
protected AdlsExceptionMapper(StorageUri uri, ObjectIOException.IOMode ioMode) { | ||
super(uri, ioMode); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
protected ObjectIOException maybeMap(Throwable th) { | ||
if (th instanceof BlobStorageException) { | ||
return asNonRetryableException(((BlobStorageException) th).getStatusCode(), th); | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.