Skip to content

Commit

Permalink
Bypass metastore locking in Glue
Browse files Browse the repository at this point in the history
  • Loading branch information
pratyakshsharma committed Nov 8, 2023
1 parent fc399fc commit 2c67fe8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ public void setPartitionLeases(MetastoreContext metastoreContext, String databas
}

@Override
public long lock(MetastoreContext metastoreContext, String databaseName, String tableName)
public Optional<Long> lock(MetastoreContext metastoreContext, String databaseName, String tableName)
{
tableCache.invalidate(getCachingKey(metastoreContext, new HiveTableHandle(databaseName, tableName)));
return delegate.lock(metastoreContext, databaseName, tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ List<PartitionNameWithVersion> getPartitionNamesWithVersionByFilter(

void setPartitionLeases(MetastoreContext metastoreContext, String databaseName, String tableName, Map<String, String> partitionNameToLocation, Duration leaseDuration);

default long lock(MetastoreContext metastoreContext, String databaseName, String tableName)
default Optional<Long> lock(MetastoreContext metastoreContext, String databaseName, String tableName)
{
throw new NotSupportedException("Lock is not supported by default");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ public synchronized void setPartitionLeases(MetastoreContext metastoreContext, S
}

@Override
public synchronized long lock(MetastoreContext metastoreContext, String databaseName, String tableName)
public synchronized Optional<Long> lock(MetastoreContext metastoreContext, String databaseName, String tableName)
{
HiveTableName hiveTableName = hiveTableName(databaseName, tableName);
while (lockedHiveTables.containsValue(hiveTableName)) {
Expand All @@ -1038,7 +1038,7 @@ public synchronized long lock(MetastoreContext metastoreContext, String database
}
long lockId = ++currentLockId;
lockedHiveTables.put(lockId, hiveTableName);
return lockId;
return Optional.of(lockId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,4 +1018,14 @@ public void setPartitionLeases(MetastoreContext metastoreContext, String databas
{
throw new PrestoException(NOT_SUPPORTED, "setPartitionLeases is not supported by Glue");
}

public Optional<Long> lock(MetastoreContext metastoreContext, String databaseName, String tableName)
{
return Optional.empty();
}

public void unlock(MetastoreContext metastoreContext, long lockId)
{
//No-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,9 @@ public void setPartitionLeases(MetastoreContext metastoreContext, String databas
}

@Override
public long lock(MetastoreContext metastoreContext, String databaseName, String tableName)
public Optional<Long> lock(MetastoreContext metastoreContext, String databaseName, String tableName)
{
return delegate.lock(metastoreContext, databaseName, tableName);
return Optional.of(delegate.lock(metastoreContext, databaseName, tableName));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void commit(@Nullable TableMetadata base, TableMetadata metadata)
tableLevelMutex.lock();
try {
try {
lockId = Optional.of(metastore.lock(metastoreContext, database, tableName));
lockId = metastore.lock(metastoreContext, database, tableName);
if (base == null) {
String tableComment = metadata.properties().get(TABLE_COMMENT);
Map<String, String> parameters = new HashMap<>();
Expand Down

0 comments on commit 2c67fe8

Please sign in to comment.