deniskuzZ commented on PR #6159:
URL: https://github.com/apache/hive/pull/6159#issuecomment-3523118763
it is still using pessimistic locking. how about
````
// ✅ OPTIMISTIC LOCKING: Read current version, increment, and prepare for
atomic check
String currentVersionStr = table.getParameters().get(versionParamKey);
long currentVersion = (currentVersionStr != null ?
Long.parseLong(currentVersionStr) : 0L);
long newVersion = currentVersion + 1;
newParams.put(versionParamKey, String.valueOf(newVersion));
oldt.setParameters(newParams);
// ✅ Atomically increment version with conflict detection
// This UPDATE will fail if another transaction changed the version
int updCount = incrementTableVersionAtomic(mTable.getId(), versionParamKey,
currentVersion, newVersion);
if (updCount == 0) {
// Concurrent modification detected - retry
LOG.debug("Table {}.{} was modified by another transaction (version {}
changed), retrying...", dbname, name, currentVersion);
throw new RetryingExecutor.RetryException(
new MetaException("Optimistic lock failure - table version
changed"));
}
LOG.debug("Successfully updated table {}.{} version: {} -> {}", dbname,
name, currentVersion, newVersion);
....
private int incrementTableVersionAtomic(long tblId, String
versionParamKey,
long expectedVersion, long newVersion) throws MetaException {
try {
// First, try to UPDATE with optimistic lock check
String updateSQL = "UPDATE \"TABLE_PARAMS\" " +
"SET \"PARAM_VALUE\" = '" + newVersion + "' " +
"WHERE \"TBL_ID\" = " + tblId +
" AND \"PARAM_KEY\" = '" + versionParamKey + "' " +
" AND \"PARAM_VALUE\" = '" + expectedVersion + "'";
int updCount = executePlainSQLUpdate(updateSQL);
if (updCount == 1) {
// Success - version was incremented
return 1;
}
....
````
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]