This is an automated email from the ASF dual-hosted git repository. dlmarion pushed a commit to branch 2.1 in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push: new cd89b26921 Add Volume replacement test for logs (#4007) cd89b26921 is described below commit cd89b26921ef54f215b4dc6202fd01353ed3d524 Author: Dave Marion <dlmar...@apache.org> AuthorDate: Fri Dec 1 16:41:03 2023 -0500 Add Volume replacement test for logs (#4007) VolumeUtil.switchVolumes is used to perform volume replacement on LogEntry objects. However, there was no test for it. Related to #4004 --- .../org/apache/accumulo/server/fs/VolumeUtil.java | 2 +- .../apache/accumulo/server/fs/VolumeUtilTest.java | 31 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeUtil.java b/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeUtil.java index 05c49a21d5..35e1fbe1bc 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeUtil.java +++ b/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeUtil.java @@ -89,7 +89,7 @@ public class VolumeUtil { return null; } - private static LogEntry switchVolumes(LogEntry le, List<Pair<Path,Path>> replacements) { + protected static LogEntry switchVolumes(LogEntry le, List<Pair<Path,Path>> replacements) { Path switchedPath = switchVolume(le.filename, FileType.WAL, replacements); String switchedString; int numSwitched = 0; diff --git a/server/base/src/test/java/org/apache/accumulo/server/fs/VolumeUtilTest.java b/server/base/src/test/java/org/apache/accumulo/server/fs/VolumeUtilTest.java index 5222801b23..6770966ae8 100644 --- a/server/base/src/test/java/org/apache/accumulo/server/fs/VolumeUtilTest.java +++ b/server/base/src/test/java/org/apache/accumulo/server/fs/VolumeUtilTest.java @@ -23,10 +23,15 @@ import static org.junit.jupiter.api.Assertions.assertNull; import java.util.ArrayList; import java.util.List; +import java.util.UUID; +import org.apache.accumulo.core.data.TableId; +import org.apache.accumulo.core.dataImpl.KeyExtent; +import org.apache.accumulo.core.tabletserver.log.LogEntry; import org.apache.accumulo.core.util.Pair; import org.apache.accumulo.server.fs.VolumeManager.FileType; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.io.Text; import org.junit.jupiter.api.Test; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -163,4 +168,30 @@ public class VolumeUtilTest { assertEquals(new Path("file:/foo/v8/tables/+r/root_tablet"), VolumeUtil.switchVolume("file:/foo/v1/tables/+r/root_tablet", ft, replacements)); } + + @Test + public void testWalVolumeReplacment() { + List<Pair<Path,Path>> replacements = new ArrayList<>(); + replacements.add(new Pair<>(new Path("hdfs://nn1/accumulo"), new Path("viewfs:/a/accumulo"))); + replacements + .add(new Pair<>(new Path("hdfs://nn1:9000/accumulo"), new Path("viewfs:/a/accumulo"))); + replacements.add(new Pair<>(new Path("hdfs://nn2/accumulo"), new Path("viewfs:/b/accumulo"))); + + String walUUID = UUID.randomUUID().toString(); + KeyExtent ke = new KeyExtent(TableId.of("1"), new Text("z"), new Text("a")); + String fileName = "hdfs://nn1/accumulo/wal/localhost+9997/" + walUUID; + LogEntry le = new LogEntry(ke, 1L, fileName); + LogEntry fixedVolume = VolumeUtil.switchVolumes(le, replacements); + assertEquals("viewfs:/a/accumulo/wal/localhost+9997/" + walUUID, fixedVolume.filename); + + fileName = "hdfs://nn1:9000/accumulo/wal/localhost+9997/" + walUUID; + le = new LogEntry(ke, 1L, fileName); + fixedVolume = VolumeUtil.switchVolumes(le, replacements); + assertEquals("viewfs:/a/accumulo/wal/localhost+9997/" + walUUID, fixedVolume.filename); + + fileName = "hdfs://nn2/accumulo/wal/localhost+9997/" + walUUID; + le = new LogEntry(ke, 1L, fileName); + fixedVolume = VolumeUtil.switchVolumes(le, replacements); + assertEquals("viewfs:/b/accumulo/wal/localhost+9997/" + walUUID, fixedVolume.filename); + } }