Repository navigation
Conversation
…given the partitioning and file name.
| * The partition values of the rows in this file may be used to derive the final location of | ||
| * the file. | ||
| */ | ||
| OutputFile newPartitionedDataFile( |
There was a problem hiding this comment.
I was thinking about this a little bit more, and in contrast to what was discussed on the ticket, I propose creating the OutputFile instance directly instead of just returning the path alone.
This comes up in the case where the file doesn't exist yet, which is always going to be the case for Spark (Spark is always creating new data files). In such a case, it is desirable for the plugin to not necessarily only know what the path is, but also to perhaps create the path itself, oftentimes by asking for some new entry in an external system that is a reference to this file we're about to write to.
In other words, the semantics of this API are that we're not only asking for the location of the data file, but we're also asking to create the data file as part of this action. In practice most of the implementations should just derive this as newOutputFile(getPath(args)). Nevertheless I think this version of the API is more rich. Thoughts?
There was a problem hiding this comment.
Sounds reasonable to me, as long as this doesn't cause odd practices like generating an OutputFile, converting it to a location, then later getting an OutputFile for it. I don't think that would happen though, so this is probably saving a call.
There was a problem hiding this comment.
We're often using the location of the OutputFile object, but we shouldn't be converting twice anywhere.
| return new Path(new Path(tableLocation, "metadata"), filename); | ||
| } | ||
|
|
||
| public void updateProperties(Map<String, String> newTableProperties) { |
There was a problem hiding this comment.
This is a concession to the fact that when table properties are updated, it's possible that the data path could change. It's not immediately clear if we can do better than this.
There was a problem hiding this comment.
The table's base location may change as well, at least for metastore tables that also use HadoopFileIO.
I think that this FileIO should use the TableMetadata instead of maintaining parts of it (location and properties). What about passing in a supplier?
public HadoopFileIO(Configuration conf, Supplier<TableMetadata> tableMetadata) { ... }
public Path metadataPath(String filename) {
Path basePath = new Path(this.tableMetadata.get().location());
...
}What do you think?
There was a problem hiding this comment.
The Supplier makes sense to me.
There was a problem hiding this comment.
Actually Supplier isn't great because the Supplier itself isn't serializable. The Supplier would be tied to the HadoopTableOperations object.
There was a problem hiding this comment.
That makes sense. I think the best option is what you originally had, but with TableMetadata, updateTableMetadata. That's Serializable right?
There was a problem hiding this comment.
You could also make tableMetadataSupplier transient and cache the result. Then at least the FileIO pulls metadata when needed instead of requiring a push.
There was a problem hiding this comment.
Hmm, TableMetadata isn't serializable as far as I can tell. So here are the fields:
// stored metadata
private final String location;
private final long lastUpdatedMillis;
private final int lastColumnId;
private final Schema schema;
private final int defaultSpecId;
private final List<PartitionSpec> specs;
private final Map<String, String> properties;
private final long currentSnapshotId;
private final List<Snapshot> snapshots;
private final Map<Long, Snapshot> snapshotsById;
private final Map<Integer, PartitionSpec> specsById;
private final List<SnapshotLogEntry> snapshotLog;
The problem is Snapshot. The interface doesn't extend Serializable. Furthermore, BaseSnapshot which I presume the Snapshot fields are, contains a reference to TableOperations.
There was a problem hiding this comment.
Ah actually I also missed the fact that TableMetadata also contains a reference to TableOperations.
There was a problem hiding this comment.
Okay, so HadoopFileIO would need to extract paths from TableMetadata each time updateMetadata is called instead of storing a reference. I think it is still better to pass the whole TableMetadata in case anything else changes. Probably also note in javadoc that TableMetadata isn't serializable, so don't save a copy of it.
There was a problem hiding this comment.
updateMetadata is a fitting compromise here!
| private final Configuration conf; | ||
| private final FileIO fileIo; | ||
|
|
||
| private HadoopFileIO fileIo; |
There was a problem hiding this comment.
I don't think this needs to be a HadoopFileIO, does it?
There was a problem hiding this comment.
Now it does because we specifically refresh the metadata on it (this really should be defaultFileIo though). However, perhaps part of the question is if updateMetadata should be part of the FileIO API contract too.
| 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 && !fs.exists(metadataFilePath)) { |
There was a problem hiding this comment.
Should InputFile define an exists method?
I'm reluctant to add another method to that interface because it is supposed to be light-weight, but it would be simple to implement in most cases and would avoid this problem of getting the location of an input file to check existence here.
There was a problem hiding this comment.
Yeah I also understand not wanting to add exists. I'm also hesitant because we don't want to blow up these APIs to become a full-fledged file system. Where is the boundary with regards to what File System-like operations we will require implementations to provide?
There was a problem hiding this comment.
We want to keep it as light-weight as possible to make it easy to avoid using the Hadoop API in the future. There's no reason to force downstream apps to include it. After that goal is met, then it's really a matter of trying to do as much as we can cleanly through the API. I think that adding exists would be okay. Then the only non-standard part of the Hadoop implementation would be the rename call.
| /** | ||
| * Get an {@link InputFile} to get the bytes for this table's metadata file with the given name. | ||
| */ | ||
| InputFile readMetadataFile(String fileName); |
There was a problem hiding this comment.
Metastore tables always use full paths to metadata files, so this is only used by file system tables in HadoopTables. I think the need for this method is caused by not separating the concern of building a metadata path from getting an InputFile or OutputFile instance. It seems odd to me to add a method to this interface just for Hadoop tables. Another minor issue is that it isn't obvious why this takes a filename and not a full path: the name readMetadataFile doesn't indicate that to me. If a caller has a full path to a metadata file, why indicates that readMetadataFile is not the right choice?
On the other hand, if this were replaced by metadataFileLocation, it would still only be used by Hadoop tables because it is built into newMetadataFile. I like the way newMetadataFile and newPartitionedDataFile work, so I'd rather not change those.
What about removing readMetadataFile and instead using newMetadataFile(filename).toInputFile()? I think that it is clear that newMetadataFile adds the metadata path because it is distinct from newOutputFile and how to construct the full file path is a concern. I think this is a reasonable way to "guess" the location of metadata files for Hadoop tables.
There was a problem hiding this comment.
+1 - sounds like a good way to resolve this.
| /** | ||
| * Get an {@link OutputFile} to write bytes for a new table metadata file with the given name. | ||
| */ | ||
| OutputFile newMetadataFile(String fileName); |
There was a problem hiding this comment.
What do you think about renaming this to newMetadataOutputFile to be clear that this is producing an OutputFile and to fit the existing convention where newInputFile and newOutputFile are distinguished from one another?
|
@rdblue addressed most of the comments. Think there's a few things we can continue to think about. Also worth highlighting is that the last commit is a conflict resolution where I also moved the metadata location configuration into |
| FileIO initializedFileIo = io(); | ||
| // This would be false if the subclass overrides io() and returns a different kind. | ||
| if (initializedFileIo instanceof HadoopFileIO) { | ||
| ((HadoopFileIO) initializedFileIo).updateTableMetadata(metadata); |
There was a problem hiding this comment.
Alternatively, we could pass TableMetadata to newMetadataOutputFile and newDataOutputFile. Then we wouldn't need this notification, or special handling for HadoopFileIO.
There was a problem hiding this comment.
The more I think about this, the more I like it. Then FileIO wouldn't need to keep mutable state.
There was a problem hiding this comment.
The problem is that TableMetadata is in iceberg-core but this module is in iceberg-api. But FileIO is returned by Table, which is in iceberg-api. Thus to make this API take TableMetadata as input we'd likely have to move TableMetadata into iceberg-api. The modules aren't set up correctly right now.
There was a problem hiding this comment.
Moving TableMetadata into iceberg-api runs into the problem of TableOperations not being in iceberg-api.
There was a problem hiding this comment.
I think we would expose the classes themselves. We'd add an interface to the API and implement that. That gets around the TableOperations problem.
There was a problem hiding this comment.
I think better would be that instead of caching the FileIO object and trying to maintain its state, we should just make a new one with the most up to date metadata every time it's needed to write something.
There was a problem hiding this comment.
I think we would expose the classes themselves. We'd add an interface to the API and implement that. That gets around the TableOperations problem.
Meaning, add an interface on top of TableMetadata?
There was a problem hiding this comment.
I think better would be that instead of caching the FileIO object and trying to maintain its state, we should just make a new one with the most up to date metadata every time it's needed to write something.
Yes, that sounds reasonable.
Meaning, add an interface on top of TableMetadata?
Yeah. That's what we've done with the rest of the API to avoid exposing implementation details. I'd prefer to avoid adding one, though. I like the idea of refreshing FileIO better.
There was a problem hiding this comment.
I built something similar to the proposed solution. The main difference is that now TableOperations has a new io(TableMetadata) method, which allows custom file IO implementations to be returned both in the case when the current table metadata is used and when some alternative table metadata is used. We now don't save the FileIO object as discussed earlier.
| * Metadata for a table. | ||
| */ | ||
| public class TableMetadata { | ||
| public class TableMetadata implements Serializable { |
There was a problem hiding this comment.
This isn't Serializable, right? I think this may have been left in from other changes.
|
Addressed comments. |
|
@rdblue any further comments on this? |
| @Override | ||
| public FileIO io() { | ||
| return fileIo; | ||
| public FileIO io(TableMetadata tableMetadata) { |
There was a problem hiding this comment.
Is it possible to make this private? It is odd for a TableOperations class that provides TableMetadata instances to have a public method that accepts TableMetadata instead of using current.
There was a problem hiding this comment.
Sorry, I'm now looking at the javadoc for it.
There was a problem hiding this comment.
Okay, looks like the trade-off here is that BaseTransaction needs to provide a FileIO object and its view of TableMetadata may be different from the table's actual metadata state because we stack up multiple changes and then commit just the final version in the transaction.
So unless I'm missing something again, the only thing that adding this method accomplishes is to be able to update some location and have the change take effect for a write in the same atomic commit. I'm okay with that limitation to make this API cleaner, unless you need to be able to change settings and write in an atomic commit for your use case.
There was a problem hiding this comment.
So unless I'm missing something again, the only thing that adding this method accomplishes is to be able to update some location and have the change take effect for a write in the same atomic commit. I'm okay with that limitation to make this API cleaner, unless you need to be able to change settings and write in an atomic commit for your use case.
So I accidentally stumbled upon having to do it this way because a lot of tests just failed if we used the old location to commit when the new metadata specifies committing elsewhere. Thus I had thought that the current behavior is part of public API and we don't intend on changing it. I suppose we ought to document this specific behavior somewhere (if you change the new metadata location table property on a commit, the change is / is not reflected in that current commit). However it's unclear where the right place to document that is.
| Map<String, String> tableProperties = tableMetadata.properties(); | ||
| this.newDataFileDir = stripTrailingSlash( | ||
| tableProperties | ||
| .getOrDefault( |
There was a problem hiding this comment.
Nit: different indentation than the next statement? (Not a big deal if you aren't making further changes)
| return; | ||
| } | ||
|
|
||
| FileIO newMetadataIO = io(metadata); |
There was a problem hiding this comment.
Why move this before the validation checks? If those fail, this file would need to be cleaned up.
| } | ||
|
|
||
| InputFile inFile = fileIo.newInputFile(file); | ||
| InputFile inFile = fileIo.newInputFile(file.location()); |
There was a problem hiding this comment.
What about file.toInputFile()?
| currentAppender.close(); | ||
| this.currentAppender = null; | ||
| fileIo.deleteFile(currentPath); | ||
| fileIo.deleteFile(currentFile.location()); |
There was a problem hiding this comment.
Maybe it would make sense to add deleteFile(InputFile file) with a default implementation that calls file.location().
|
@mccheah, thanks for working on this. It's looking close, but I have doubts about adding Otherwise, I think this is about ready to get in. |
But pushes down the idea of "metadata-aware" file IO down to BaseMetastoreTableOperations.
|
Ok I adjusted this such that |
|
To override FileIO generation for subclasses of |
|
Superceded by #87 |
Cherrypick PR#745
No description provided.