-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
HADOOP-16906. Abortable #2684
Merged
steveloughran
merged 8 commits into
apache:trunk
from
steveloughran:incoming/limj/HADOOP-16906-abort-trunk
Feb 11, 2021
Merged
HADOOP-16906. Abortable #2684
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ec9a488
WIP. HADOOP-16906. Add Abortable.abort() interface for streams to ena…
HeartSaVioR a1d11d5
WIP still working...
HeartSaVioR 2775086
address basic integration tests
HeartSaVioR 01a7892
Fix checkstyle & address FIXME on javadoc
HeartSaVioR d5a3b7d
HADOOP-16906. Abortable
steveloughran b5c8163
HADOOP-16906. Abortable: style and findbugs
steveloughran 5f8a5ef
HADOOP-16906. checkstyle
steveloughran 8d50dcf
HADOOP-16906. final commentary
steveloughran File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Abortable.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,67 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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.apache.hadoop.fs; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.hadoop.classification.InterfaceAudience; | ||
import org.apache.hadoop.classification.InterfaceStability; | ||
|
||
/** | ||
* Abort data being written to a stream, so that close() does | ||
* not write the data. It is implemented by output streams in | ||
* some object stores, and passed through {@link FSDataOutputStream}. | ||
*/ | ||
@InterfaceAudience.Public | ||
@InterfaceStability.Unstable | ||
public interface Abortable { | ||
|
||
/** | ||
* Abort the active operation without the output becoming visible. | ||
* | ||
* This is to provide ability to cancel the write on stream; once | ||
* a stream is aborted, the write MUST NOT become visible. | ||
* | ||
* @throws UnsupportedOperationException if the operation is not supported. | ||
* @return the result. | ||
*/ | ||
AbortableResult abort(); | ||
|
||
/** | ||
* Interface for the result of aborts; allows subclasses to extend | ||
* (IOStatistics etc) or for future enhancements if ever needed. | ||
*/ | ||
interface AbortableResult { | ||
|
||
/** | ||
* Was the stream already closed/aborted? | ||
* @return true if a close/abort operation had already | ||
* taken place. | ||
*/ | ||
boolean alreadyClosed(); | ||
|
||
/** | ||
* Any exception caught during cleanup operations, | ||
* exceptions whose raising/catching does not change | ||
* the semantics of the abort. | ||
* @return an exception or null. | ||
*/ | ||
IOException anyCleanupException(); | ||
} | ||
} |
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
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
186 changes: 186 additions & 0 deletions
186
hadoop-common-project/hadoop-common/src/site/markdown/filesystem/abortable.md
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,186 @@ | ||
<!--- | ||
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. See accompanying LICENSE file. | ||
--> | ||
|
||
|
||
<!-- ============================================================= --> | ||
<!-- CLASS: FileSystem --> | ||
<!-- ============================================================= --> | ||
|
||
# interface `org.apache.hadoop.fs.Abortable` | ||
|
||
<!-- MACRO{toc|fromDepth=1|toDepth=2} --> | ||
|
||
Abort the active operation such that the output does not become | ||
manifest. | ||
|
||
Specifically, if supported on an [output stream](outputstream.html), | ||
a successful `abort()` MUST guarantee that the stream will not be made visible in the `close()` | ||
operation. | ||
|
||
```java | ||
|
||
@InterfaceAudience.Public | ||
@InterfaceStability.Unstable | ||
public interface Abortable { | ||
|
||
/** | ||
* Abort the active operation without the output becoming visible. | ||
* | ||
* This is to provide ability to cancel the write on stream; once | ||
* a stream is aborted, the write MUST NOT become visible. | ||
* | ||
* @throws UnsupportedOperationException if the operation is not supported. | ||
* @return the result. | ||
*/ | ||
AbortableResult abort(); | ||
|
||
/** | ||
* Interface for the result of aborts; allows subclasses to extend | ||
* (IOStatistics etc) or for future enhancements if ever needed. | ||
*/ | ||
interface AbortableResult { | ||
|
||
/** | ||
* Was the stream already closed/aborted? | ||
* @return true if a close/abort operation had already | ||
* taken place. | ||
*/ | ||
boolean alreadyClosed(); | ||
|
||
/** | ||
* Any exception caught during cleanup operations, | ||
* exceptions whose raising/catching does not change | ||
* the semantics of the abort. | ||
* @return an exception or null. | ||
*/ | ||
IOException anyCleanupException(); | ||
} | ||
} | ||
``` | ||
|
||
## Method `abort()` | ||
|
||
Aborts the ongoing operation such that no output SHALL become visible | ||
when the operation is completed. | ||
|
||
Unless and until other File System classes implement `Abortable`, the | ||
interface is specified purely for output streams. | ||
|
||
## Method `abort()` on an output stream | ||
|
||
`Abortable.abort()` MUST only be supported on output streams | ||
whose output is only made visible when `close()` is called, | ||
for example. output streams returned by the S3A FileSystem. | ||
|
||
## Preconditions | ||
|
||
The stream MUST implement `Abortable` and `StreamCapabilities`. | ||
|
||
```python | ||
if unsupported: | ||
throw UnsupportedException | ||
|
||
if not isOpen(stream): | ||
no-op | ||
|
||
StreamCapabilities.hasCapability("fs.capability.outputstream.abortable") == True | ||
|
||
``` | ||
|
||
|
||
## Postconditions | ||
|
||
After `abort()` returns, the filesystem MUST be unchanged: | ||
|
||
``` | ||
FS' = FS | ||
``` | ||
|
||
A successful `abort()` operation MUST guarantee that | ||
when the stream` close()` is invoked no output shall be manifest. | ||
|
||
* The stream MUST retry any remote calls needed to force the abort outcome. | ||
* If any file was present at the destination path, it MUST remain unchanged. | ||
|
||
Strictly then: | ||
|
||
> if `Abortable.abort()` does not raise `UnsupportedOperationException` | ||
> then returns, then it guarantees that the write SHALL NOT become visible | ||
> and that any existing data in the filesystem at the destination path SHALL | ||
> continue to be available. | ||
|
||
|
||
1. Calls to `write()` methods MUST fail. | ||
1. Calls to `flush()` MUST be no-ops (applications sometimes call this on closed streams) | ||
1. Subsequent calls to `abort()` MUST be no-ops. | ||
1. `close()` MUST NOT manifest the file, and MUST NOT raise an exception | ||
|
||
That is, the postconditions of `close()` becomes: | ||
|
||
``` | ||
FS' = FS | ||
``` | ||
|
||
### Cleanup | ||
|
||
* If temporary data is stored in the local filesystem or in the store's upload | ||
infrastructure then this MAY be cleaned up; best-effort is expected here. | ||
|
||
* The stream SHOULD NOT retry cleanup operations; any failure there MUST be | ||
caught and added to `AbortResult` | ||
|
||
#### Returned `AbortResult` | ||
|
||
The `AbortResult` value returned is primarily for testing and logging. | ||
|
||
`alreadyClosed()`: MUST return `true` if the write had already been aborted or closed; | ||
|
||
`anyCleanupException();`: SHOULD return any IOException raised during any optional | ||
cleanup operations. | ||
|
||
|
||
### Thread safety and atomicity | ||
|
||
Output streams themselves aren't formally required to be thread safe, | ||
but as applications do sometimes assume they are, this call MUST be thread safe. | ||
|
||
## Path/Stream capability "fs.capability.outputstream.abortable" | ||
|
||
|
||
An application MUST be able to verify that a stream supports the `Abortable.abort()` | ||
operation without actually calling it. This is done through the `StreamCapabilities` | ||
interface. | ||
|
||
1. If a stream instance supports `Abortable` then it MUST return `true` | ||
in the probe `hasCapability("fs.capability.outputstream.abortable")` | ||
|
||
1. If a stream instance does not support `Abortable` then it MUST return `false` | ||
in the probe `hasCapability("fs.capability.outputstream.abortable")` | ||
|
||
That is: if a stream declares its support for the feature, a call to `abort()` | ||
SHALL meet the defined semantics of the operation. | ||
|
||
FileSystem/FileContext implementations SHOULD declare support similarly, to | ||
allow for applications to probe for the feature in the destination directory/path. | ||
|
||
If a filesystem supports `Abortable` under a path `P` then it SHOULD return `true` to | ||
`PathCababilities.hasPathCapability(path, "fs.capability.outputstream.abortable")` | ||
This is to allow applications to verify that the store supports the feature. | ||
|
||
If a filesystem does not support `Abortable` under a path `P` then it MUST | ||
return `false` to | ||
`PathCababilities.hasPathCapability(path, "fs.capability.outputstream.abortable")` | ||
|
||
|
||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
then -> and ?