fix: enforce Glue table version checks (#1184)

This commit is contained in:
David Phillips authored and GitHub committed 2026-06-06 20:55:36 -05:00
1 parent 3732d2491b
commit 24250b658d
5 files changed
+159 -1

No files matched your search

@@ -79,7 +79,8 @@ public class GlueJsonHandler {
case "UpdateTable" -> {
String dbName = request.get("DatabaseName").asText();
Table table = mapper.treeToValue(request.get("TableInput"), Table.class);
glueService.updateTable(dbName, table);
String versionId = request.path("VersionId").asText(null);
glueService.updateTable(dbName, table, versionId);
yield Response.ok().build();
}
case "GetTableVersions" -> {
@@ -108,6 +108,7 @@ public class GlueService {
if (table.getCreateTime() == null) {
table.setCreateTime(Instant.now());
}
table.setVersionId("0");
tableStore.put(key, table);
LOG.infov("Created Glue Table: {0}.{1}", databaseName, table.getName());
}
@@ -129,15 +130,24 @@ public class GlueService {
}
public void updateTable(String databaseName, Table table) {
updateTable(databaseName, table, null);
}
public synchronized void updateTable(String databaseName, Table table, String versionId) {
getDatabase(databaseName);
String key = databaseName + ":" + table.getName();
Table existing = tableStore.get(key)
.orElseThrow(() -> new AwsException("EntityNotFoundException",
"Table not found: " + databaseName + "." + table.getName(), 400));
if (versionId != null && !versionId.equals(existing.getVersionId())) {
throw new AwsException("ConcurrentModificationException",
"Table was modified concurrently: " + databaseName + "." + table.getName(), 400);
}
validateSchemaReference(table);
table.setDatabaseName(databaseName);
table.setCreateTime(existing.getCreateTime());
table.setUpdateTime(Instant.now());
table.setVersionId(nextVersionId(existing.getVersionId()));
tableStore.put(key, table);
LOG.infov("Updated Glue Table: {0}.{1}", databaseName, table.getName());
}
@@ -330,10 +340,23 @@ public class GlueService {
copy.setTableType(source.getTableType());
copy.setViewOriginalText(source.getViewOriginalText());
copy.setViewExpandedText(source.getViewExpandedText());
copy.setVersionId(source.getVersionId());
copy.setParameters(copyMap(source.getParameters()));
return copy;
}
private static String nextVersionId(String versionId) {
if (versionId == null) {
return "1";
}
try {
return Long.toString(Math.addExact(Long.parseLong(versionId), 1));
}
catch (ArithmeticException | NumberFormatException e) {
throw new AwsException("InvalidInputException", "Invalid table VersionId: " + versionId, 400);
}
}
private static StorageDescriptor copyStorageDescriptor(StorageDescriptor source) {
if (source == null) {
return null;
@@ -36,6 +36,8 @@ public class Table {
private String viewOriginalText;
@JsonProperty("ViewExpandedText")
private String viewExpandedText;
@JsonProperty("VersionId")
private String versionId;
@JsonProperty("Parameters")
private Map<String, String> parameters;
@@ -65,6 +67,8 @@ public class Table {
public void setViewOriginalText(String viewOriginalText) { this.viewOriginalText = viewOriginalText; }
public String getViewExpandedText() { return viewExpandedText; }
public void setViewExpandedText(String viewExpandedText) { this.viewExpandedText = viewExpandedText; }
public String getVersionId() { return versionId; }
public void setVersionId(String versionId) { this.versionId = versionId; }
public Map<String, String> getParameters() { return parameters; }
public void setParameters(Map<String, String> parameters) { this.parameters = parameters; }
}