igorbernstein2 commented on code in PR #26205:
URL: https://github.com/apache/beam/pull/26205#discussion_r1161960876
##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableServiceFactory.java:
##########
@@ -44,111 +43,120 @@
class BigtableServiceFactory implements Serializable {
private static final Logger LOG =
LoggerFactory.getLogger(BigtableServiceFactory.class);
-
- static final BigtableServiceFactory FACTORY_INSTANCE = new
BigtableServiceFactory();
-
- private transient int nextId = 0;
-
- private transient Map<ConfigId, BigtableServiceEntry> entries = new
HashMap<>();
+ private static final ConcurrentHashMap<UUID, BigtableServiceEntry> entries =
+ new ConcurrentHashMap<>();
+ private static final ConcurrentHashMap<UUID, AtomicInteger> refCounts = new
ConcurrentHashMap<>();
+ private static final Object lock = new Object();
@AutoValue
abstract static class ConfigId implements Serializable {
- abstract int id();
+ abstract UUID id();
- static ConfigId create(int id) {
- return new AutoValue_BigtableServiceFactory_ConfigId(id);
+ static ConfigId create() {
+ return new AutoValue_BigtableServiceFactory_ConfigId(UUID.randomUUID());
}
}
@AutoValue
abstract static class BigtableServiceEntry implements Serializable,
AutoCloseable {
- abstract BigtableServiceFactory getServiceFactory();
-
abstract ConfigId getConfigId();
abstract BigtableService getService();
- abstract AtomicInteger getRefCount();
-
- static BigtableServiceEntry create(
- BigtableServiceFactory factory,
- ConfigId configId,
- BigtableService service,
- AtomicInteger refCount) {
- return new AutoValue_BigtableServiceFactory_BigtableServiceEntry(
- factory, configId, service, refCount);
+ static BigtableServiceEntry create(ConfigId configId, BigtableService
service) {
+ return new
AutoValue_BigtableServiceFactory_BigtableServiceEntry(configId, service);
}
@Override
public void close() {
- getServiceFactory().releaseService(this);
+ int refCount =
+ refCounts.getOrDefault(getConfigId().id(), new
AtomicInteger(0)).decrementAndGet();
Review Comment:
if refCounts doesnt contain the configId or the ref count is already < 0,
please log an error
--
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]