Skip to content

Commit

Permalink
[#1953] [#1946] [#1941] [#1920] [#1910] improment(trino): make versio…
Browse files Browse the repository at this point in the history
…n atomic to keep thread safe (#2139)

<!--
1. Title: [#<issue>] <type>(<scope>): <subject>
   Examples:
     - "[#123] feat(operator): support xxx"
     - "[#233] fix: check null before access result in xxx"
     - "[MINOR] refactor: fix typo in variable name"
     - "[MINOR] docs: fix typo in README"
     - "[#255] test: fix flaky test NameOfTheTest"
   Reference: https://www.conventionalcommits.org/en/v1.0.0/
2. If the PR is unfinished, please mark this PR as draft.
-->

### What changes were proposed in this pull request?

close #1953 #1946 #1941 #1920 #1910 

### Why are the changes needed?


Fix: #1953 #1946 #1941 #1920 #1910 

### Does this PR introduce _any_ user-facing change?

- no

### How was this patch tested?

- ut
  • Loading branch information
coolderli authored Feb 20, 2024
1 parent f4056ab commit b29a7cc
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/** Transforming Hive connector configuration and components into Gravitino connector. */
public class HiveConnectorAdapter implements CatalogConnectorAdapter {

private static int version = 0;
private static final AtomicInteger VERSION = new AtomicInteger(0);

private final HasPropertyMeta propertyMetadata;
private final PropertyConverter catalogConverter;
Expand All @@ -33,7 +34,8 @@ public Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog
throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(
"catalogHandle", String.format("%s_v%d:normal:default", catalog.getName(), version++));
"catalogHandle",
String.format("%s_v%d:normal:default", catalog.getName(), VERSION.getAndIncrement()));
config.put("connectorName", "hive");

Map<String, Object> properties = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/** Transforming Iceberg connector configuration and components into Gravitino connector. */
public class IcebergConnectorAdapter implements CatalogConnectorAdapter {

private static int version = 0;
private static final AtomicInteger VERSION = new AtomicInteger(0);
private final IcebergPropertyMeta propertyMetadata;
private final PropertyConverter catalogConverter;

Expand All @@ -31,7 +32,8 @@ public Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog
throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(
"catalogHandle", String.format("%s_v%d:normal:default", catalog.getName(), version++));
"catalogHandle",
String.format("%s_v%d:normal:default", catalog.getName(), VERSION.getAndIncrement()));
config.put("connectorName", "iceberg");

Map<String, String> properties =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/** Transforming MySQL connector configuration and components into Gravitino connector. */
public class MySQLConnectorAdapter implements CatalogConnectorAdapter {

private final PropertyConverter catalogConverter;
private static int version = 0;
private static final AtomicInteger VERSION = new AtomicInteger(0);
private final HasPropertyMeta propertyMetadata;

public MySQLConnectorAdapter() {
Expand All @@ -33,7 +34,8 @@ public Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog
throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(
"catalogHandle", String.format("%s_v%d:normal:default", catalog.getName(), version++));
"catalogHandle",
String.format("%s_v%d:normal:default", catalog.getName(), VERSION.getAndIncrement()));
config.put("connectorName", "mysql");

Map<String, String> properties =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
import com.datastrato.gravitino.trino.connector.metadata.GravitinoCatalog;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/** Transforming PostgreSQL connector configuration and components into Gravitino connector. */
public class PostgreSQLConnectorAdapter implements CatalogConnectorAdapter {
private final PropertyConverter catalogConverter;
private static int version = 0;
private static final AtomicInteger VERSION = new AtomicInteger(0);

public PostgreSQLConnectorAdapter() {
this.catalogConverter = new JDBCCatalogPropertyConverter();
Expand All @@ -27,7 +28,8 @@ public Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog
throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(
"catalogHandle", String.format("%s_v%d:normal:default", catalog.getName(), version++));
"catalogHandle",
String.format("%s_v%d:normal:default", catalog.getName(), VERSION.getAndIncrement()));
config.put("connectorName", "postgresql");

Map<String, String> properties =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Support trino Memory connector for testing. Transforming Memory connector configuration and
* components into Gravitino connector.
*/
public class MemoryConnectorAdapter implements CatalogConnectorAdapter {

private static int version = 0;
private static final AtomicInteger VERSION = new AtomicInteger(0);
private final HasPropertyMeta propertyMetadata;

public MemoryConnectorAdapter() {
Expand All @@ -31,7 +32,8 @@ public MemoryConnectorAdapter() {
public Map<String, Object> buildInternalConnectorConfig(GravitinoCatalog catalog) {
Map<String, Object> config = new HashMap<>();
config.put(
"catalogHandle", String.format("%s_v%d:normal:default", catalog.getName(), version++));
"catalogHandle",
String.format("%s_v%d:normal:default", catalog.getName(), VERSION.getAndIncrement()));
config.put("connectorName", "memory");

Map<String, Object> properties = new HashMap<>();
Expand Down

0 comments on commit b29a7cc

Please sign in to comment.