mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(glue): serialize table deletion with catalog updates (#8173)
This commit is contained in:
1 parent
7c138ce3f1
commit
405a3cad12
4 files changed
+253
-14
No files matched your search
@@ -50,6 +50,10 @@ descriptor keeps the `AdditionalLocations`, `BucketColumns`, `SortColumns`, `Ske
|
||||
| BatchDeleteTableVersion | Deletes several archived versions, reporting the ones not deleted in `Errors`. |
|
||||
| SearchTables | Searches every table of the catalog by `SearchText` (substring, or exact when quoted), property `Filters` (string keys use the tokenised match of the API reference, time keys honour `Comparator`, other keys read table parameters) and `SortCriteria`, paged by `MaxResults` and `NextToken`. |
|
||||
|
||||
`BatchDeleteTable` requires `TablesToDelete` with 0 to 100 names. Missing or oversized lists
|
||||
fail with `InvalidInputException` before any table is deleted. Valid batches keep their per-table
|
||||
`Errors` response.
|
||||
|
||||
#### Partitions
|
||||
|
||||
| Action | Description |
|
||||
|
||||
@@ -85,6 +85,7 @@ public class GlueService {
|
||||
private static final Logger LOG = Logger.getLogger(GlueService.class);
|
||||
private static final int MAX_FUNCTION_PATTERN_LENGTH = 255;
|
||||
private static final int MAX_FUNCTION_RESULTS = 100;
|
||||
private static final int MAX_BATCH_DELETE_TABLES = 100;
|
||||
private static final int MAX_SECURITY_CONFIGURATION_NAME_LENGTH = 255;
|
||||
private static final int MAX_DATA_QUALITY_NAME_LENGTH = 255;
|
||||
private static final int MAX_DATA_QUALITY_DESCRIPTION_LENGTH = 2048;
|
||||
@@ -790,7 +791,7 @@ public class GlueService {
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteTable(String databaseName, String tableName) {
|
||||
public synchronized void deleteTable(String databaseName, String tableName) {
|
||||
getTable(databaseName, tableName);
|
||||
String key = tableKey(databaseName, tableName);
|
||||
tableStore.delete(key);
|
||||
@@ -813,20 +814,27 @@ public class GlueService {
|
||||
}
|
||||
|
||||
public List<BatchDeleteTableError> batchDeleteTables(String databaseName, List<String> tableNames) {
|
||||
getDatabase(databaseName);
|
||||
List<BatchDeleteTableError> errors = new ArrayList<>();
|
||||
for (String tableName : tableNames) {
|
||||
String key = tableKey(databaseName, tableName);
|
||||
Optional<Table> table = tableStore.get(key);
|
||||
if (table.isEmpty()) {
|
||||
errors.add(new BatchDeleteTableError(
|
||||
tableName,
|
||||
new ErrorDetail("EntityNotFoundException", "Table " + tableName + " not found")));
|
||||
continue;
|
||||
}
|
||||
deleteTable(databaseName, tableName);
|
||||
validateRequired(tableNames, "TablesToDelete");
|
||||
if (tableNames.size() > MAX_BATCH_DELETE_TABLES) {
|
||||
throw new AwsException("InvalidInputException",
|
||||
"TablesToDelete must have at most " + MAX_BATCH_DELETE_TABLES + " items.", 400);
|
||||
}
|
||||
synchronized (this) {
|
||||
getDatabase(databaseName);
|
||||
List<BatchDeleteTableError> errors = new ArrayList<>();
|
||||
for (String tableName : tableNames) {
|
||||
String key = tableKey(databaseName, tableName);
|
||||
Optional<Table> table = tableStore.get(key);
|
||||
if (table.isEmpty()) {
|
||||
errors.add(new BatchDeleteTableError(
|
||||
tableName,
|
||||
new ErrorDetail("EntityNotFoundException", "Table " + tableName + " not found")));
|
||||
continue;
|
||||
}
|
||||
deleteTable(databaseName, tableName);
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
public void updateColumnStatisticsForTable(
|
||||
|
||||
@@ -1226,6 +1226,59 @@ class GlueServiceTest {
|
||||
assertEquals("EntityNotFoundException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {101, 1000})
|
||||
void batchDeleteTablesRejectsOversizedRequestsBeforeDeletingTables(int size) {
|
||||
createVersions("table_0", 1);
|
||||
List<String> names = IntStream.range(0, size).mapToObj(index -> "table_" + index).toList();
|
||||
|
||||
AwsException invalid = assertThrows(AwsException.class,
|
||||
() -> glueService.batchDeleteTables("db1", names));
|
||||
|
||||
assertEquals("InvalidInputException", invalid.getErrorCode());
|
||||
assertEquals(400, invalid.getHttpStatus());
|
||||
assertTrue(invalid.getMessage().contains("TablesToDelete"));
|
||||
assertEquals("table_0", glueService.getTable("db1", "table_0").getName());
|
||||
assertFalse(tableVersionStore.keys().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void batchDeleteTablesRequiresNames() {
|
||||
AwsException invalid = assertThrows(AwsException.class,
|
||||
() -> glueService.batchDeleteTables("db1", null));
|
||||
|
||||
assertEquals("InvalidInputException", invalid.getErrorCode());
|
||||
assertEquals(400, invalid.getHttpStatus());
|
||||
assertTrue(invalid.getMessage().contains("TablesToDelete"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 100})
|
||||
void batchDeleteTablesAcceptsApiBoundarySizes(int size) {
|
||||
List<String> names = IntStream.range(0, size).mapToObj(index -> "missing_" + index).toList();
|
||||
|
||||
List<GlueService.BatchDeleteTableError> errors = glueService.batchDeleteTables("db1", names);
|
||||
|
||||
assertEquals(names, errors.stream().map(GlueService.BatchDeleteTableError::tableName).toList());
|
||||
assertTrue(errors.stream().allMatch(error -> "EntityNotFoundException".equals(error.errorDetail().errorCode())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void oversizedTableDeletionDoesNotWaitForTheCatalogMonitor() throws Exception {
|
||||
List<String> names = IntStream.range(0, 101).mapToObj(index -> "table_" + index).toList();
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
synchronized (glueService) {
|
||||
Future<AwsException> rejected = executor.submit(() -> assertThrows(AwsException.class,
|
||||
() -> glueService.batchDeleteTables("db1", names)));
|
||||
assertEquals("InvalidInputException", rejected.get(5, TimeUnit.SECONDS).getErrorCode());
|
||||
}
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTableVersionsReturnsCurrentAndArchivedVersions() {
|
||||
Table table = new Table();
|
||||
@@ -2447,6 +2500,89 @@ class GlueServiceTest {
|
||||
assertEquals("new", glueService.getTable("db1", "new").getName());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
void tableDeletionWaitsForAnUpdateAndRemovesItsPublishedVersion(boolean batch) throws Exception {
|
||||
ParkingStore<Table> tables = new ParkingStore<>();
|
||||
setUp(new InMemoryStorage<>(), new InMemoryStorage<>(), tables);
|
||||
createVersions("table", 1);
|
||||
glueService.createTable("db1", paginationTable("neighbor"));
|
||||
tables.parkNextWrite();
|
||||
assertOperationWaitsForParkedStore(tables,
|
||||
() -> glueService.updateTable("db1", paginationTable("table"), "1", false),
|
||||
() -> deleteExistingTable(batch));
|
||||
|
||||
assertEquals("EntityNotFoundException", assertThrows(AwsException.class,
|
||||
() -> glueService.getTable("db1", "table")).getErrorCode());
|
||||
assertTrue(tableVersionStore.keys().isEmpty());
|
||||
assertEquals(List.of("neighbor"), glueService.getTables("db1").stream().map(Table::getName).toList());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
void tableUpdateWaitsForDeletionAndRejectsTheMissingTable(boolean batch) throws Exception {
|
||||
ParkingStore<Table> tables = new ParkingStore<>();
|
||||
setUp(new InMemoryStorage<>(), new InMemoryStorage<>(), tables);
|
||||
createVersions("table", 1);
|
||||
tables.parkNextRead();
|
||||
assertOperationWaitsForParkedStore(tables, () -> deleteExistingTable(batch), () -> {
|
||||
AwsException missing = assertThrows(AwsException.class,
|
||||
() -> glueService.updateTable("db1", paginationTable("table"), null, false));
|
||||
assertEquals("EntityNotFoundException", missing.getErrorCode());
|
||||
});
|
||||
|
||||
assertTrue(glueService.getTables("db1").isEmpty());
|
||||
assertTrue(tableVersionStore.keys().isEmpty());
|
||||
glueService.createTable("db1", paginationTable("table"));
|
||||
assertEquals("0", glueService.getTable("db1", "table").getVersionId());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
void tableDeletionWaitsForDatabaseDeletionWithoutInterruptingItsCascade(boolean batch) throws Exception {
|
||||
ParkingStore<Table> tables = new ParkingStore<>();
|
||||
setUp(new InMemoryStorage<>(), new InMemoryStorage<>(), tables);
|
||||
createVersions("table", 1);
|
||||
glueService.createTable("db1", paginationTable("neighbor"));
|
||||
tables.parkNextRead();
|
||||
assertOperationWaitsForParkedStore(tables, () -> glueService.deleteDatabase("db1"), () -> {
|
||||
AwsException missing = assertThrows(AwsException.class, () -> deleteExistingTable(batch));
|
||||
assertEquals("EntityNotFoundException", missing.getErrorCode());
|
||||
});
|
||||
|
||||
assertEquals("EntityNotFoundException", assertThrows(AwsException.class,
|
||||
() -> glueService.getDatabase("db1")).getErrorCode());
|
||||
assertTrue(tableStore.keys().isEmpty());
|
||||
assertTrue(tableVersionStore.keys().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void batchDeletionHoldsItsTableCheckUntilDeletionCompletes() throws Exception {
|
||||
ParkingStore<Table> tables = new ParkingStore<>();
|
||||
setUp(new InMemoryStorage<>(), new InMemoryStorage<>(), tables);
|
||||
glueService.createTable("db1", paginationTable("table"));
|
||||
tables.parkNextRead();
|
||||
assertOperationWaitsForParkedStore(tables, () -> {
|
||||
List<GlueService.BatchDeleteTableError> errors =
|
||||
glueService.batchDeleteTables("db1", List.of("table", "missing"));
|
||||
assertEquals(List.of("missing"), errors.stream().map(GlueService.BatchDeleteTableError::tableName).toList());
|
||||
assertEquals("EntityNotFoundException", errors.getFirst().errorDetail().errorCode());
|
||||
}, () -> {
|
||||
AwsException missing = assertThrows(AwsException.class, () -> glueService.deleteTable("db1", "table"));
|
||||
assertEquals("EntityNotFoundException", missing.getErrorCode());
|
||||
});
|
||||
|
||||
assertTrue(glueService.getTables("db1").isEmpty());
|
||||
}
|
||||
|
||||
private void deleteExistingTable(boolean batch) {
|
||||
if (batch) {
|
||||
assertTrue(glueService.batchDeleteTables("db1", List.of("table")).isEmpty());
|
||||
} else {
|
||||
glueService.deleteTable("db1", "table");
|
||||
}
|
||||
}
|
||||
|
||||
private static UserDefinedFunction function(String database, String name) {
|
||||
UserDefinedFunction function = new UserDefinedFunction();
|
||||
function.setDatabaseName(database);
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package io.floci.aws.services.glue;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import software.amazon.awssdk.services.glue.model.BatchDeleteTableResponse;
|
||||
import software.amazon.awssdk.services.glue.model.EntityNotFoundException;
|
||||
import software.amazon.awssdk.services.glue.model.InvalidInputException;
|
||||
import software.amazon.awssdk.services.glue.model.TableVersion;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@QuarkusTest
|
||||
class GlueTableDeletionIntegrationTest {
|
||||
|
||||
@Test
|
||||
void batchSizeValidationPrecedesDeletionAndAcceptsTheApiBoundaries() {
|
||||
GlueCatalogPaginationTestSupport.withCatalog("814800000002", "batch_deletion_", (client, database) -> {
|
||||
client.createTable(request -> request.databaseName(database).tableInput(input -> input.name("table_0")));
|
||||
List<String> oversized = IntStream.range(0, 101).mapToObj(index -> "table_" + index).toList();
|
||||
|
||||
InvalidInputException tooMany = assertThrows(InvalidInputException.class,
|
||||
() -> client.batchDeleteTable(request -> request.databaseName(database).tablesToDelete(oversized)));
|
||||
assertEquals(400, tooMany.statusCode());
|
||||
assertTrue(tooMany.getMessage().contains("TablesToDelete"));
|
||||
InvalidInputException missing = assertThrows(InvalidInputException.class,
|
||||
() -> client.batchDeleteTable(request -> request.databaseName(database)));
|
||||
assertEquals(400, missing.statusCode());
|
||||
assertTrue(missing.getMessage().contains("TablesToDelete"));
|
||||
|
||||
assertTrue(client.batchDeleteTable(request -> request.databaseName(database)
|
||||
.tablesToDelete(List.of())).errors().isEmpty());
|
||||
assertEquals("table_0", client.getTable(request -> request.databaseName(database).name("table_0"))
|
||||
.table().name());
|
||||
|
||||
List<String> maximum = oversized.subList(0, 100);
|
||||
BatchDeleteTableResponse response = client.batchDeleteTable(request -> request.databaseName(database)
|
||||
.tablesToDelete(maximum));
|
||||
assertEquals(maximum.subList(1, 100), response.errors().stream().map(error -> error.tableName()).toList());
|
||||
assertTrue(response.errors().stream()
|
||||
.allMatch(error -> "EntityNotFoundException".equals(error.errorDetail().errorCode())));
|
||||
assertThrows(EntityNotFoundException.class,
|
||||
() -> client.getTable(request -> request.databaseName(database).name("table_0")));
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
void deletionHidesArchivedVersionsAndAllowsFreshCreation(boolean batch) {
|
||||
GlueCatalogPaginationTestSupport.withCatalog("814800000001", "table_deletion_", (client, database) -> {
|
||||
client.createTable(request -> request.databaseName(database)
|
||||
.tableInput(input -> input.name("example").description("first")));
|
||||
client.updateTable(request -> request.databaseName(database)
|
||||
.tableInput(input -> input.name("example").description("second")));
|
||||
assertEquals(2, client.getTableVersions(request -> request.databaseName(database).tableName("example"))
|
||||
.tableVersions().size());
|
||||
|
||||
if (batch) {
|
||||
BatchDeleteTableResponse response = client.batchDeleteTable(request -> request.databaseName(database)
|
||||
.tablesToDelete("example", "missing"));
|
||||
assertEquals(1, response.errors().size());
|
||||
assertEquals("missing", response.errors().getFirst().tableName());
|
||||
assertEquals("EntityNotFoundException", response.errors().getFirst().errorDetail().errorCode());
|
||||
} else {
|
||||
client.deleteTable(request -> request.databaseName(database).name("example"));
|
||||
}
|
||||
|
||||
EntityNotFoundException missing = assertThrows(EntityNotFoundException.class,
|
||||
() -> client.getTable(request -> request.databaseName(database).name("example")));
|
||||
assertEquals(400, missing.statusCode());
|
||||
assertThrows(EntityNotFoundException.class,
|
||||
() -> client.getTableVersions(request -> request.databaseName(database).tableName("example")));
|
||||
assertThrows(EntityNotFoundException.class, () -> client.updateTable(request -> request.databaseName(database)
|
||||
.tableInput(input -> input.name("example").description("too late"))));
|
||||
|
||||
client.createTable(request -> request.databaseName(database)
|
||||
.tableInput(input -> input.name("example").description("fresh")));
|
||||
assertEquals(List.of("0"), client.getTableVersions(request -> request
|
||||
.databaseName(database).tableName("example")).tableVersions().stream()
|
||||
.map(TableVersion::versionId).toList());
|
||||
assertEquals("fresh", client.getTable(request -> request.databaseName(database).name("example"))
|
||||
.table().description());
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user