diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/AbstractFSWALProvider.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/AbstractFSWALProvider.java index ccdc95f..e976a08 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/AbstractFSWALProvider.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/AbstractFSWALProvider.java @@ -540,4 +540,9 @@ public abstract class AbstractFSWALProvider> implemen public static long getWALStartTimeFromWALName(String name) { return Long.parseLong(getWALNameGroupFromWALName(name, 2)); } + + @Override + public WALIdentity createWALIdentity(String wal) { + return new FSWALIdentity(wal); + } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/DisabledWALProvider.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/DisabledWALProvider.java index 75439fe..3c18b48 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/DisabledWALProvider.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/DisabledWALProvider.java @@ -262,4 +262,9 @@ class DisabledWALProvider implements WALProvider { public void addWALActionsListener(WALActionsListener listener) { disabled.registerWALActionsListener(listener); } + + @Override + public WALIdentity createWALIdentity(String wal) { + return new FSWALIdentity(wal); + } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/RegionGroupingProvider.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/RegionGroupingProvider.java index e4390c9..4f8da31 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/RegionGroupingProvider.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/RegionGroupingProvider.java @@ -288,4 +288,9 @@ public class RegionGroupingProvider implements WALProvider { // extra code actually works, then we will have other big problems. So leave it as is. listeners.add(listener); } + + @Override + public WALIdentity createWALIdentity(String wal) { + return new FSWALIdentity(wal); + } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/SyncReplicationWALProvider.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/SyncReplicationWALProvider.java index 9859c20..6441a8c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/SyncReplicationWALProvider.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/SyncReplicationWALProvider.java @@ -349,4 +349,8 @@ public class SyncReplicationWALProvider implements WALProvider, PeerActionListen return provider; } + @Override + public WALIdentity createWALIdentity(String wal) { + return new FSWALIdentity(wal); + } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALProvider.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALProvider.java index 244a636..b8698e6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALProvider.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALProvider.java @@ -113,4 +113,13 @@ public interface WALProvider { return path -> getWALs().stream().map(w -> w.getLogFileSizeIfBeingWritten(path)) .filter(o -> o.isPresent()).findAny().orElse(OptionalLong.empty()); } + + /** + * Creates WALIdentity for WAL path/name. + * The name should be uniquely identifying a WAL in this WALProvider. + * + * @param wal the WAL + * @return WALIdentity instance for the WAL + */ + WALIdentity createWALIdentity(String wal); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/IOTestProvider.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/IOTestProvider.java index d062c77..91cf53e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/IOTestProvider.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/IOTestProvider.java @@ -286,6 +286,10 @@ public class IOTestProvider implements WALProvider { @Override public void addWALActionsListener(WALActionsListener listener) { // TODO Implement WALProvider.addWALActionLister + } + @Override + public WALIdentity createWALIdentity(String wal) { + return new FSWALIdentity(new Path(wal)); } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/FSWALIdentity.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/FSWALIdentity.java new file mode 100644 index 0000000..4fe7138 --- /dev/null +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/FSWALIdentity.java @@ -0,0 +1,79 @@ +/** + * 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 org.apache.hadoop.fs.Path; +import org.apache.yetus.audience.InterfaceAudience; +import org.apache.yetus.audience.InterfaceStability; + +@InterfaceAudience.Private +@InterfaceStability.Evolving +public class FSWALIdentity implements WALIdentity{ + private String name; + private Path path; + + public FSWALIdentity(String name) { + this.path = new Path(name); + if (path != null) { + this.name = path.getName(); + } + } + + public FSWALIdentity(Path path) { + this.path = path; + if (path !=null) { + this.name = path.getName(); + } + } + + @Override + public String getName() { + return name; + } + + /** + * @return {@link Path} object of the name encapsulated in WALIdentity + */ + public Path getPath() { + return path; + } + + @Override + public int compareTo(WALIdentity o) { + FSWALIdentity that = (FSWALIdentity)o; + return this.path.compareTo(that.getPath()); + } + + @Override + public String toString() { + return this.path.toString(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof FSWALIdentity)) { + return false; + } + FSWALIdentity that = (FSWALIdentity) obj; + return this.path.equals(that.getPath()); + } + @Override + public int hashCode() { + return this.path.hashCode(); + } +} diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALIdentity.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALIdentity.java new file mode 100644 index 0000000..677114c --- /dev/null +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALIdentity.java @@ -0,0 +1,42 @@ +/** + * 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 org.apache.yetus.audience.InterfaceAudience; +import org.apache.yetus.audience.InterfaceStability; + +/** + * This interface defines the identification of WAL for both stream based and distributed FileSystem + * based environments. + * See {@link #getName()} method. + */ +@InterfaceAudience.Private +@InterfaceStability.Evolving +public interface WALIdentity extends Comparable { + + /** + * WALIdentity is uniquely identifying a WAL stored in this WALProvider. + * This name can be thought of as a human-readable, serialized form of the WALIdentity. + * + * The same value should be returned across calls to this method. + * + * @return name of the wal + */ + String getName(); + +}