Zhangyx39 commented on a change in pull request #986: SAMZA-2156: Couchbase 
support for Samza Table API
URL: https://github.com/apache/samza/pull/986#discussion_r278310701
 
 

 ##########
 File path: 
samza-kv-couchbase/src/main/java/org/apache/samza/table/remote/couchbase/CouchbaseBucketRegistry.java
 ##########
 @@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.samza.table.remote.couchbase;
+
+import com.couchbase.client.java.Bucket;
+import com.couchbase.client.java.Cluster;
+import com.couchbase.client.java.CouchbaseCluster;
+import com.couchbase.client.java.auth.CertAuthenticator;
+import com.couchbase.client.java.env.CouchbaseEnvironment;
+import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The CouchbaseBucketRegistry is intended to reuse the same {@link Cluster} 
instance given same clusterNodes and reuse
+ * the same {@link Bucket} given same bucketName. Instantiating a Bucket is 
expensive. Different tasks within a
+ * container that is using the same bucket should use this registry to avoid 
creating multiple Buckets.
+ */
+public class CouchbaseBucketRegistry {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(CouchbaseBucketRegistry.class);
+  private final Map<String, Bucket> openedBuckets;
 
 Review comment:
   I see. We can use ConcurrentHashMap.computeIfAbsent can do the job. But it 
makes it harder to count the usage of a bucket. Since this method will only be 
called once per task per table, it's ok to use a synchronized method.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to