Skip to content

Commit

Permalink
Hadoop: Log where the missing metadata file is located
Browse files Browse the repository at this point in the history
  • Loading branch information
manuzhang committed Nov 25, 2024
1 parent eddf9a1 commit eb017a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public TableMetadata refresh() {
// no v0 metadata means the table doesn't exist yet
return null;
} else if (metadataFile == null) {
throw new ValidationException("Metadata file for version %d is missing", ver);
throw new ValidationException(
"Metadata file for version %d is missing under %s", ver, metadataRoot());
}

Path nextMetadataFile = getMetadataFile(ver + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
import org.apache.iceberg.exceptions.NoSuchNamespaceException;
import org.apache.iceberg.exceptions.NoSuchTableException;
import org.apache.iceberg.exceptions.ValidationException;
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.io.PositionOutputStream;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -548,6 +549,32 @@ public void testVersionHintFileMissingMetadata() throws Exception {
.hasMessageStartingWith("Table does not exist");
}

@Test
public void testMetadataFileMissing() throws Exception {
addVersionsToTable(table);

HadoopTableOperations tableOperations =
(HadoopTableOperations) TABLES.newTableOps(tableLocation);

FileIO io = table.io();
io.deleteFile(versionHintFile.getPath());
try (PositionOutputStream stream = io.newOutputFile(versionHintFile.getPath()).create()) {
stream.write("3".getBytes(StandardCharsets.UTF_8));
}

// Check the result of the findVersion(), and load the table and check the current snapshotId
assertThat(tableOperations.findVersion()).isEqualTo(3);
assertThat(TABLES.load(tableLocation).currentSnapshot().snapshotId())
.isEqualTo(table.currentSnapshot().snapshotId());

io.deleteFile(tableOperations.getMetadataFile(3).toString());
assertThatThrownBy(() -> TABLES.load(tableLocation))
.isInstanceOf(ValidationException.class)
.hasMessage(
"Metadata file for version 3 is missing under "
+ (new Path(tableLocation, "metadata")));
}

@Test
public void testTableName() throws Exception {
HadoopCatalog catalog = hadoopCatalog();
Expand Down

0 comments on commit eb017a4

Please sign in to comment.