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 0b7b8da..645d7eb 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 @@ -285,4 +285,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..65c0c88 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,11 @@ 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 + * @param 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 453b742..da2781a 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 @@ -283,6 +283,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..74bb401 --- /dev/null +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/FSWALIdentity.java @@ -0,0 +1,98 @@ +/** + * 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.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +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 static final Pattern WAL_FILE_NAME_PATTERN = + Pattern.compile("(.+)\\.(\\d+)(\\.[0-9A-Za-z]+)?"); + 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; + } + + @Override + public long getWalStartTime() { + return Long.parseLong(getWALNameGroupFromWALName(name, 2)); + } + + private static String getWALNameGroupFromWALName(String name, int group) { + Matcher matcher = WAL_FILE_NAME_PATTERN.matcher(name); + if (matcher.matches()) { + return matcher.group(group); + } else { + throw new IllegalArgumentException(name + " is not a valid wal file 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..2dac5aa --- /dev/null +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALIdentity.java @@ -0,0 +1,83 @@ +/** + * 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.IOException; +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 environment. + * See {@link getName} method. + */ +@InterfaceAudience.Private +@InterfaceStability.Evolving +public interface WALIdentity extends Comparable { + + static WALIdentity UNKNOWN = new WALIdentity() { + + @Override + public long getWalStartTime() { + return 0; + } + + @Override + public String getName() { + return "UNKNOWN"; + } + + @Override + public int compareTo(WALIdentity o) { + if (o == UNKNOWN) { + return 0; + } + return -1; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof WALIdentity)) { + return false; + } + if (compareTo((WALIdentity)o) == 0) { + return true; + } + return false; + } + + @Override + public int hashCode() { + return 0; + } + }; + + /** + * For the FS based path, it will be just a filename of whole path + * For stream based, it will be name of the stream + * @return name of the wal + */ + String getName(); + + /** + * Starting time of the wal which help in sorting against the others + * @return start time of the wal + */ + long getWalStartTime(); + +}