smengcl commented on code in PR #4567:
URL: https://github.com/apache/ozone/pull/4567#discussion_r1231728514


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/ReferenceCounted.java:
##########
@@ -0,0 +1,167 @@
+/*
+ * 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.hadoop.ozone.om.snapshot;
+
+import com.google.common.base.Preconditions;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Add reference counter to an object instance.
+ */
+public class ReferenceCounted<T> implements AutoCloseable {
+
+  /**
+   * Object that is being reference counted. e.g. OmSnapshot
+   */
+  private final T obj;
+
+  /**
+   * A map of thread IDs holding the reference of the object and its count.
+   */
+  private final ConcurrentHashMap<Long, Long> threadMap;
+
+  /**
+   * Sum of reference counts from all threads.
+   */
+  private final AtomicLong refCount;
+
+  /**
+   * Parent SnapshotCache instance whose callback will be triggered upon this 
RC
+   * closure.
+   */
+  private final SnapshotCache parentSnapshotCache;

Review Comment:
   done: c2746dca3b4c21122e1cdb32b8004294ae729e6e
   
   The annoyance of `ReferenceCounted<IOmMetadataReader, SnapshotCache>` alone 
taking 50 chars with a 80-char line limit was one of the reasons I didn't do it 
before :)
   
   And `SnapshotCache` import is now everywhere.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to