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

BugFix: CTAS doesnt allow custom UUID for Replica Table #271

Merged
merged 1 commit into from
Dec 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,21 @@ private void validatePathOfProvidedRequest(
String tableURI = String.format("%s.%s", databaseId, tableId);
String dbIdFromProps = extractFromTblPropsIfExists(tableURI, tableProperties, DB_RAW_KEY);
String tblIdFromProps = extractFromTblPropsIfExists(tableURI, tableProperties, TBL_RAW_KEY);
// Extract tableLocation from table properties (openhouse.tableLocation)
// tableLocation should be the absolute path to the latest metadata file including scheme.
// Scheme is not present for HDFS and Local storages. See:
// https://github.com/linkedin/openhouse/issues/121
String tableLocation = extractFromTblPropsIfExists(tableURI, tableProperties, TBL_LOC_RAW_KEY);
Storage storage = storageManager.getStorageFromPath(tableLocation);

if (TableType.REPLICA_TABLE != tableType
&& !storage.isPathValid(tableLocation, dbIdFromProps, tblIdFromProps, tableUUIDProperty)) {
log.error("Previous tableLocation: {} doesn't exist", tableLocation);
throw new RequestValidationFailureException(
String.format("Provided snapshot is invalid for %s.%s", dbIdFromProps, tblIdFromProps));
if (TableType.REPLICA_TABLE != tableType) {
// Extract tableLocation from table properties (openhouse.tableLocation)
// tableLocation should be the absolute path to the latest metadata file including scheme.
// Scheme is not present for HDFS and Local storages. See:
// https://github.com/linkedin/openhouse/issues/121
String tableLocation =
extractFromTblPropsIfExists(tableURI, tableProperties, TBL_LOC_RAW_KEY);
Storage storage = storageManager.getStorageFromPath(tableLocation);

if (!storage.isPathValid(tableLocation, dbIdFromProps, tblIdFromProps, tableUUIDProperty)) {
log.error("Previous tableLocation: {} doesn't exist", tableLocation);
throw new RequestValidationFailureException(
String.format("Provided snapshot is invalid for %s.%s", dbIdFromProps, tblIdFromProps));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,72 @@ public void testUUIDFailsForMissingIdentifiers() {
.build()));
}

@Test
public void testReplicaTableDoesNotCallIsPathValid() {
// Stub behavior for storage
when(storageManager.getStorageFromPath(any())).thenReturn(storage);
when(storage.getClient()).thenReturn(storageClient);
when(storageClient.getRootPrefix()).thenReturn("/tmp");

UUID expectedUUID = UUID.randomUUID();
UUID actualUUID =
tableUUIDGenerator.generateUUID(
CreateUpdateTableRequestBody.builder()
.tableId("t")
.databaseId("db")
.clusterId(CLUSTER_NAME)
.tableType(TableType.REPLICA_TABLE)
.tableProperties(
ImmutableMap.of(
"openhouse.tableUUID",
expectedUUID.toString(),
"openhouse.tableId",
"t",
"openhouse.databaseId",
"db",
"openhouse.tableLocation",
String.format("/tmp/db/t-%s/metadata.json", expectedUUID)))
.build());

Assertions.assertEquals(expectedUUID, actualUUID);

// Verify that isPathValid is not called
verify(storage, never()).isPathValid(anyString(), anyString(), anyString(), anyString());
}

@Test
public void testPrimaryTableCallsIsPathValid() {
// Stub behavior for storage
when(storageManager.getStorageFromPath(any())).thenReturn(storage);
when(storage.getClient()).thenReturn(storageClient);
when(storageClient.getRootPrefix()).thenReturn("/tmp");

UUID expectedUUID = UUID.randomUUID();
UUID actualUUID =
tableUUIDGenerator.generateUUID(
CreateUpdateTableRequestBody.builder()
.tableId("t")
.databaseId("db")
.clusterId(CLUSTER_NAME)
.tableType(TableType.PRIMARY_TABLE)
.tableProperties(
ImmutableMap.of(
"openhouse.tableUUID",
expectedUUID.toString(),
"openhouse.tableId",
"t",
"openhouse.databaseId",
"db",
"openhouse.tableLocation",
String.format("/tmp/db/t-%s/metadata.json", expectedUUID)))
.build());

Assertions.assertEquals(expectedUUID, actualUUID);

// Verify that isPathValid is called
verify(storage, times(1)).isPathValid(anyString(), anyString(), anyString(), anyString());
}

private String getTableLocation(
String rootPrefix, String databaseId, String tableId, UUID tableUUID) {
return String.format("%s/%s/%s-%s", rootPrefix, databaseId, tableId, tableUUID.toString());
Expand Down
Loading