Skip to content
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

Add exception mappers to convert storage failures to Iceberg REST client exceptions #8558

Merged
merged 17 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ as necessary. Empty sections will not end in the release notes.

### Breaking changes

- The `throttled-retry-after` advanced configuration property was renamed from
`nessie.catalog.service.s3.throttled-retry-after` to
`nessie.catalog.error-handling.throttled-retry-after`. The old property name is ignored.

### New Features

- CLI: New `REVERT CONTENT` command to update one or more tables or views to a previous state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@
*/
package org.projectnessie.catalog.files.api;

import java.time.Instant;
import java.util.Optional;
public enum BackendErrorCode {
/**
* Treat unknown errors as non-retryable to prevent indefinite retry cycles when the server is not
* able to determine a specific failure reason. This may be changed in the future when task
* deadlines are supported.
*/
UNKNOWN(false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make UNKNOWN retryable - we don't know what happened, so it can be retryable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know real UNKNOWN will end up in infinite retry

Copy link
Member Author

@dimas-b dimas-b Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning to add task deadlines in a follow-up PR and also fix #8860

THROTTLED(true),
NOT_FOUND(false),
UNAUTHORIZED(false),
FORBIDDEN(false),
BAD_REQUEST(false),
NESSIE_ERROR(false),
ICEBERG_ERROR(false),
;

public class NonRetryableException extends ObjectIOException {
public NonRetryableException(Throwable cause) {
super(cause);
}

public NonRetryableException(String message) {
super(message);
}
private final boolean retryable;

public NonRetryableException(String message, Throwable cause) {
super(message, cause);
BackendErrorCode(boolean retryable) {
this.retryable = retryable;
}

@Override
public boolean isRetryable() {
return false;
}

@Override
public Optional<Instant> retryNotBefore() {
return Optional.empty();
return retryable;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 static org.projectnessie.catalog.files.api.BackendErrorCode.BAD_REQUEST;
import static org.projectnessie.catalog.files.api.BackendErrorCode.FORBIDDEN;
import static org.projectnessie.catalog.files.api.BackendErrorCode.NOT_FOUND;
import static org.projectnessie.catalog.files.api.BackendErrorCode.THROTTLED;
import static org.projectnessie.catalog.files.api.BackendErrorCode.UNAUTHORIZED;
import static org.projectnessie.catalog.files.api.BackendErrorCode.UNKNOWN;

import org.projectnessie.nessie.immutables.NessieImmutable;

@NessieImmutable
public interface BackendErrorStatus {
BackendErrorCode statusCode();

Throwable cause();

static BackendErrorStatus of(BackendErrorCode statusCode, Throwable cause) {
return ImmutableBackendErrorStatus.of(statusCode, cause);
}

static BackendErrorStatus fromHttpStatusCode(int httpStatusCode, Throwable cause) {
switch (httpStatusCode) {
dimas-b marked this conversation as resolved.
Show resolved Hide resolved
case 400:
return BackendErrorStatus.of(BAD_REQUEST, cause);
case 401:
return BackendErrorStatus.of(UNAUTHORIZED, cause);
case 403:
return BackendErrorStatus.of(FORBIDDEN, cause);
case 404:
return BackendErrorStatus.of(NOT_FOUND, cause);
case 429:
return BackendErrorStatus.of(THROTTLED, cause);
default:
return BackendErrorStatus.of(UNKNOWN, cause);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List;
import java.util.Optional;
import org.projectnessie.nessie.immutables.NessieImmutable;

@NessieImmutable
public abstract class BackendExceptionMapper {

protected abstract List<Analyzer> analyzers();

public static Builder builder() {
return ImmutableBackendExceptionMapper.builder();
}

public Optional<BackendErrorStatus> analyze(Throwable ex) {
for (Throwable th = ex; th != null; th = th.getCause()) {
for (Analyzer analyzer : analyzers()) {
BackendErrorStatus status = analyzer.analyze(th);
if (status != null) {
return Optional.of(status);
}
}
}

return Optional.empty();
}

public interface Analyzer {
BackendErrorStatus analyze(Throwable th);
}

public interface Builder {
@CanIgnoreReturnValue
Builder addAnalyzer(Analyzer analyzer);

BackendExceptionMapper build();
}
}

This file was deleted.

This file was deleted.

Loading