Skip to content

Commit d3b24d2

Browse files
authored
JDBC: Optimize writeEntity calls (#1496)
* Remove transaction from atomic writes * remove if-else
1 parent a857602 commit d3b24d2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

extension/persistence/relational-jdbc/src/main/java/org/apache/polaris/extension/persistence/relational/jdbc/JdbcBasePersistenceImpl.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ public void writeEntity(
9393
boolean nameOrParentChanged,
9494
PolarisBaseEntity originalEntity) {
9595
try {
96-
datasourceOperations.runWithinTransaction(
97-
statement -> {
98-
persistEntity(callCtx, entity, originalEntity, statement);
99-
return true;
100-
});
96+
persistEntity(callCtx, entity, originalEntity, datasourceOperations::executeUpdate);
10197
} catch (SQLException e) {
10298
throw new RuntimeException("Error persisting entity", e);
10399
}
@@ -115,7 +111,6 @@ public void writeEntities(
115111
PolarisBaseEntity entity = entities.get(i);
116112
PolarisBaseEntity originalEntity =
117113
originalEntities != null ? originalEntities.get(i) : null;
118-
119114
// first, check if the entity has already been created, in which case we will simply
120115
// return it.
121116
PolarisBaseEntity entityFound =
@@ -127,7 +122,7 @@ public void writeEntities(
127122
// already been updated after the creation.
128123
continue;
129124
}
130-
persistEntity(callCtx, entity, originalEntity, statement);
125+
persistEntity(callCtx, entity, originalEntity, statement::executeUpdate);
131126
}
132127
return true;
133128
});
@@ -143,12 +138,12 @@ private void persistEntity(
143138
@Nonnull PolarisCallContext callCtx,
144139
@Nonnull PolarisBaseEntity entity,
145140
PolarisBaseEntity originalEntity,
146-
Statement statement)
141+
QueryAction queryAction)
147142
throws SQLException {
148143
ModelEntity modelEntity = ModelEntity.fromEntity(entity);
149144
if (originalEntity == null) {
150145
try {
151-
statement.executeUpdate(generateInsertQuery(modelEntity, realmId));
146+
queryAction.apply(generateInsertQuery(modelEntity, realmId));
152147
} catch (SQLException e) {
153148
if (datasourceOperations.isConstraintViolation(e)) {
154149
PolarisBaseEntity existingEntity =
@@ -176,7 +171,7 @@ private void persistEntity(
176171
"realm_id",
177172
realmId);
178173
try {
179-
int rowsUpdated = statement.executeUpdate(generateUpdateQuery(modelEntity, params));
174+
int rowsUpdated = queryAction.apply(generateUpdateQuery(modelEntity, params));
180175
if (rowsUpdated == 0) {
181176
throw new RetryOnConcurrencyException(
182177
"Entity '%s' id '%s' concurrently modified; expected version %s",
@@ -923,4 +918,9 @@ PolarisStorageIntegration<T> loadPolarisStorageIntegration(
923918
BaseMetaStoreManager.extractStorageConfiguration(callContext, entity);
924919
return storageIntegrationProvider.getStorageIntegrationForConfig(storageConfig);
925920
}
921+
922+
@FunctionalInterface
923+
private interface QueryAction {
924+
Integer apply(String query) throws SQLException;
925+
}
926926
}

0 commit comments

Comments
 (0)