Apache9 commented on code in PR #5157:
URL: https://github.com/apache/hbase/pull/5157#discussion_r1160513331


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/wal/LazyInitializedWALProvider.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.hbase.wal;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.Abortable;
+import org.apache.hadoop.hbase.regionserver.wal.MetricsWAL;
+import org.apache.hadoop.hbase.wal.WALFactory.Providers;
+import org.apache.yetus.audience.InterfaceAudience;
+
+/**
+ * A lazy initialized WAL provider for holding the WALProvider for some 
special tables, such as
+ * hbase:meta, hbase:replication, etc.
+ */
[email protected]
+class LazyInitializedWALProvider implements Closeable {
+
+  private final WALFactory factory;
+
+  private final String providerId;
+
+  private final String providerConfigName;
+
+  private final Abortable abortable;
+
+  private final AtomicReference<WALProvider> holder = new AtomicReference<>();
+
+  LazyInitializedWALProvider(WALFactory factory, String providerId, String 
providerConfigName,
+    Abortable abortable) {
+    this.factory = factory;
+    this.providerId = providerId;
+    this.providerConfigName = providerConfigName;
+    this.abortable = abortable;
+  }
+
+  WALProvider getProvider() throws IOException {
+    Configuration conf = factory.getConf();
+    for (;;) {
+      WALProvider provider = this.holder.get();
+      if (provider != null) {
+        return provider;
+      }
+      Class<? extends WALProvider> clz = null;
+      if (conf.get(providerConfigName) == null) {
+        try {
+          clz = conf.getClass(WALFactory.WAL_PROVIDER, 
Providers.defaultProvider.clazz,
+            WALProvider.class);
+        } catch (Throwable t) {
+          // the WAL provider should be an enum. Proceed
+        }
+      }
+      if (clz == null) {
+        clz = factory.getProviderClass(providerConfigName,
+          conf.get(WALFactory.WAL_PROVIDER, WALFactory.DEFAULT_WAL_PROVIDER));
+      }
+      provider = WALFactory.createProvider(clz);
+      provider.init(factory, conf, providerId, this.abortable);
+      provider.addWALActionsListener(new MetricsWAL());
+      if (this.holder.compareAndSet(null, provider)) {
+        return provider;
+      } else {
+        // someone is ahead of us, close and try again.
+        provider.close();

Review Comment:
   The code is just a copy of the old code in WALFactory. Here we just close 
the loser, i.e, the one which is failed to set to the class field, so we need 
to close it. No one will use it.



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

Reply via email to