-
Notifications
You must be signed in to change notification settings - Fork 63
Use the same shared FileSystem instance across calls in HadoopTableOperations #108
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -47,13 +47,15 @@ class HadoopTableOperations implements TableOperations { | |
|
|
||
| private final Configuration conf; | ||
| private final Path location; | ||
| private final FileSystem metadataFs; | ||
| private TableMetadata currentMetadata = null; | ||
| private Integer version = null; | ||
| private boolean shouldRefresh = true; | ||
|
|
||
| HadoopTableOperations(Path location, Configuration conf) { | ||
| this.conf = conf; | ||
| this.location = location; | ||
| this.metadataFs = Util.getFS(location, conf); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes look fine to me, along with the package-private changes to HadoopInputFile and HadoopOutputFile. |
||
| } | ||
|
|
||
| public TableMetadata current() { | ||
|
|
@@ -67,18 +69,17 @@ public TableMetadata current() { | |
| public TableMetadata refresh() { | ||
| int ver = version != null ? version : readVersionHint(); | ||
| Path metadataFile = metadataFile(ver); | ||
| FileSystem fs = Util.getFS(metadataFile, conf); | ||
| try { | ||
| // don't check if the file exists if version is non-null because it was already checked | ||
| if (version == null && !fs.exists(metadataFile)) { | ||
| if (version == null && !metadataFs.exists(metadataFile)) { | ||
| if (ver == 0) { | ||
| // no v0 metadata means the table doesn't exist yet | ||
| return null; | ||
| } | ||
| throw new ValidationException("Metadata file is missing: %s", metadataFile); | ||
| } | ||
|
|
||
| while (fs.exists(metadataFile(ver + 1))) { | ||
| while (metadataFs.exists(metadataFile(ver + 1))) { | ||
| ver += 1; | ||
| metadataFile = metadataFile(ver); | ||
| } | ||
|
|
@@ -88,7 +89,7 @@ public TableMetadata refresh() { | |
| } | ||
| this.version = ver; | ||
| this.currentMetadata = TableMetadataParser.read(this, | ||
| HadoopInputFile.fromPath(metadataFile, conf)); | ||
| HadoopInputFile.fromFsPath(metadataFs, metadataFile, conf)); | ||
| this.shouldRefresh = false; | ||
| return currentMetadata; | ||
| } | ||
|
|
@@ -105,14 +106,13 @@ public void commit(TableMetadata base, TableMetadata metadata) { | |
| } | ||
|
|
||
| Path tempMetadataFile = metadataPath(UUID.randomUUID().toString() + getFileExtension(conf)); | ||
| TableMetadataParser.write(metadata, HadoopOutputFile.fromPath(tempMetadataFile, conf)); | ||
| TableMetadataParser.write(metadata, HadoopOutputFile.fromFsPath(metadataFs, tempMetadataFile, conf)); | ||
|
|
||
| int nextVersion = (version != null ? version : 0) + 1; | ||
| Path finalMetadataFile = metadataFile(nextVersion); | ||
| FileSystem fs = Util.getFS(tempMetadataFile, conf); | ||
|
|
||
| try { | ||
| if (fs.exists(finalMetadataFile)) { | ||
| if (metadataFs.exists(finalMetadataFile)) { | ||
| throw new CommitFailedException( | ||
| "Version %d already exists: %s", nextVersion, finalMetadataFile); | ||
| } | ||
|
|
@@ -123,7 +123,7 @@ public void commit(TableMetadata base, TableMetadata metadata) { | |
|
|
||
| try { | ||
| // this rename operation is the atomic commit operation | ||
| if (!fs.rename(tempMetadataFile, finalMetadataFile)) { | ||
| if (!metadataFs.rename(tempMetadataFile, finalMetadataFile)) { | ||
| throw new CommitFailedException( | ||
| "Failed to commit changes using rename: %s", finalMetadataFile); | ||
| } | ||
|
|
@@ -140,20 +140,19 @@ public void commit(TableMetadata base, TableMetadata metadata) { | |
|
|
||
| @Override | ||
| public InputFile newInputFile(String path) { | ||
| return HadoopInputFile.fromPath(new Path(path), conf); | ||
| return HadoopInputFile.fromFsPath(metadataFs, new Path(path), conf); | ||
| } | ||
|
|
||
| @Override | ||
| public OutputFile newMetadataFile(String filename) { | ||
| return HadoopOutputFile.fromPath(metadataPath(filename), conf); | ||
| return HadoopOutputFile.fromFsPath(metadataFs, metadataPath(filename), conf); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteFile(String path) { | ||
| Path toDelete = new Path(path); | ||
| FileSystem fs = Util.getFS(toDelete, conf); | ||
| try { | ||
| fs.delete(toDelete, false /* not recursive */ ); | ||
| metadataFs.delete(toDelete, false /* not recursive */ ); | ||
| } catch (IOException e) { | ||
| throw new RuntimeIOException(e, "Failed to delete file: %s", path); | ||
| } | ||
|
|
@@ -178,9 +177,7 @@ private Path versionHintFile() { | |
|
|
||
| private void writeVersionHint(int version) { | ||
| Path versionHintFile = versionHintFile(); | ||
| FileSystem fs = Util.getFS(versionHintFile, conf); | ||
|
|
||
| try (FSDataOutputStream out = fs.create(versionHintFile, true /* overwrite */ )) { | ||
| try (FSDataOutputStream out = metadataFs.create(versionHintFile, true /* overwrite */ )) { | ||
| out.write(String.valueOf(version).getBytes("UTF-8")); | ||
|
|
||
| } catch (IOException e) { | ||
|
|
||
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.
Instead of adding this, I think
HadoopInputFileshould make its constructor protected to allow you to create a subclass.The reason why we use
PathandConfigurationis to ensure that the file system always matches the path's scheme. Adding a new factory method that allows users to supply a file system creates a path around that guarantee. That's legitimate for your use case, but you'll need to implementHadoopTableOperationsanyway, so I think a safer way to solve the problem for you is to subclassHadoopInputFileand expose this method in your private subclass.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 should note that for the limited use in this PR I think it is okay because this is package-private. It would just be better to solve your overall use case with a custom
TableOperationsimplementation.