Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hive] Make HiveMetastoreClient.addPartition thread safe #4669

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,6 @@ public void retry(ManifestCommittable committable) {
addPartitions(partitions);
}

private void addPartition(BinaryRow partition) {
try {
boolean added = cache.get(partition, () -> false);
if (added) {
return;
}

client.addPartition(partition);
cache.put(partition, true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private void addPartitions(Set<BinaryRow> partitions) {
try {
List<BinaryRow> newPartitions = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.IMetaStoreClient;
import org.apache.hadoop.hive.metastore.api.AlreadyExistsException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
import org.apache.hadoop.hive.metastore.api.Partition;
import org.apache.hadoop.hive.metastore.api.PartitionEventType;
Expand Down Expand Up @@ -92,21 +93,15 @@ public void addPartitions(List<BinaryRow> partitions) throws Exception {

@Override
public void addPartition(LinkedHashMap<String, String> partitionSpec) throws Exception {
List<String> partitionValues = new ArrayList<>(partitionSpec.values());
try {
clients.execute(
client ->
client.getPartition(
identifier.getDatabaseName(),
identifier.getTableName(),
partitionValues));
// do nothing if the partition already exists
} catch (NoSuchObjectException e) {
// partition not found, create new partition
Partition hivePartition =
toHivePartition(partitionSpec, (int) (System.currentTimeMillis() / 1000));
clients.execute(client -> client.add_partition(hivePartition));
}
Partition hivePartition =
toHivePartition(partitionSpec, (int) (System.currentTimeMillis() / 1000));
clients.execute(
client -> {
try {
client.add_partition(hivePartition);
} catch (AlreadyExistsException ignore) {
}
});
}

@Override
Expand Down
Loading