Skip to content

Commit

Permalink
Allow parallel TableLocation factory invocation in AbstractTableLocat…
Browse files Browse the repository at this point in the history
…ionProvider
  • Loading branch information
rcaudy committed Apr 29, 2024
1 parent c71506e commit 580ca33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private void maybeAddLocations(@NotNull final Collection<ImmutableTableLocationK
return;
}
filterLocationKeys(locationKeys)
.parallelStream()
.forEach(lk -> columnSourceManager.addLocation(locationProvider.getTableLocation(lk)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,18 @@ public TableLocation getTableLocationIfPresent(@NotNull final TableLocationKey t
// See JavaDoc on tableLocations for background.
// The intent is to create a TableLocation exactly once to replace the TableLocationKey placeholder that was
// added in handleTableLocationKey.
if (current instanceof TableLocation) {
return (TableLocation) current;
}
synchronized (tableLocations) {
current = tableLocations.get(tableLocationKey);
if (current instanceof TableLocation) {
return (TableLocation) current;
while (!(current instanceof TableLocation)) {
final TableLocationKey immutableKey = (TableLocationKey) current;
// noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (immutableKey) {
current = tableLocations.get(immutableKey);
if (immutableKey == current) {
// Note, this may contend for the lock on tableLocations
tableLocations.add(current = makeTableLocation(immutableKey));
}
}
final TableLocation result = makeTableLocation((TableLocationKey) current);
tableLocations.add(result);
return result;
}
return (TableLocation) current;
}

/**
Expand Down

0 comments on commit 580ca33

Please sign in to comment.