clintropolis commented on code in PR #19830:
URL: https://github.com/apache/druid/pull/19830#discussion_r3936906834
##########
extensions-core/druid-catalog/src/main/java/org/apache/druid/catalog/storage/sql/SQLCatalogManager.java:
##########
@@ -453,44 +436,47 @@ public TableMetadata withHandle(Handle handle) throws
CatalogException
{
handle.begin();
try {
- final Query<Map<String, Object>> query = handle
- .createQuery(statement(SELECT_COLUMNS_STMT))
+ final ResultIterator<TableMetadata> resultIterator = handle
+ .createQuery(statement(selectStmt))
.setFetchSize(connector.getStreamingFetchSize())
.bind(SCHEMA_NAME_COL, id.schema())
- .bind(TABLE_NAME_COL, id.name());
-
- final ResultIterator<TableSpec> resultIterator = query
- .map((index, r, ctx) ->
- tableSpecFromBytes(
- jsonMapper,
- r.getString(1),
- null,
- r.getBytes(2)
- )
- )
- .iterator();
- final TableSpec tableSpec;
+ .bind(TABLE_NAME_COL, id.name())
+ .map((index, r, ctx) ->
+ TableMetadata.forUpdate(
+ id,
+ r.getLong(4),
+ tableSpecFromBytes(jsonMapper, r.getString(1),
r.getBytes(2), r.getBytes(3))
+ )
+ )
+ .iterator();
+ final TableMetadata existing;
if (resultIterator.hasNext()) {
- tableSpec = resultIterator.next();
+ existing = resultIterator.next();
} else {
throw tableNotFound(id);
}
- final TableSpec revised = transform.apply(TableMetadata.of(id,
tableSpec));
+ final TableSpec revised = transform.apply(existing);
if (revised == null) {
handle.rollback();
return null;
}
- final long updateTime = System.currentTimeMillis();
+ // The version is also the compare-and-set token, so it must
actually change on every write: a commit
+ // landing in the same millisecond as the write that produced
the version it read would otherwise
+ // leave the token as it was, letting a second writer's
predicate match after this one commits.
+ final long updateTime = Math.max(System.currentTimeMillis(),
existing.updateTime() + 1);
Review Comment:
done, also drive creates through here too instead of using current time
inline
--
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]