ACCUMULO-3472 Avoid filesystem.equals as it isn't implemented The equals method on FileSystem isn't implemented (at least for DistributedFileSystem) which means that VolumeImpl doesn't work as intended and always falls back to the default volume. Use the filesystem's URI and add some tests.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/2ca91038 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/2ca91038 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/2ca91038 Branch: refs/heads/master Commit: 2ca91038c9788ef156e8fcc35a224a125234728b Parents: 99011d3 Author: Josh Elser <els...@apache.org> Authored: Tue Jan 13 11:58:15 2015 -0500 Committer: Josh Elser <els...@apache.org> Committed: Tue Jan 13 11:58:15 2015 -0500 ---------------------------------------------------------------------- .../apache/accumulo/core/volume/VolumeImpl.java | 30 ++++++- .../accumulo/core/volume/VolumeImplTest.java | 90 ++++++++++++++++++++ .../accumulo/server/fs/VolumeManagerImpl.java | 6 +- 3 files changed, 120 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/2ca91038/core/src/main/java/org/apache/accumulo/core/volume/VolumeImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/volume/VolumeImpl.java b/core/src/main/java/org/apache/accumulo/core/volume/VolumeImpl.java index 9b9a80e..f466463 100644 --- a/core/src/main/java/org/apache/accumulo/core/volume/VolumeImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/volume/VolumeImpl.java @@ -70,17 +70,41 @@ public class VolumeImpl implements Volume { public boolean isValidPath(Path p) { checkNotNull(p); + FileSystem other; try { - if (fs.equals(p.getFileSystem(CachedConfiguration.getInstance()))) { - return p.toUri().getPath().startsWith(basePath); - } + other = p.getFileSystem(CachedConfiguration.getInstance()); } catch (IOException e) { log.warn("Could not determine filesystem from path: " + p); + return false; + } + + if (equivalentFileSystems(other)) { + return equivalentPaths(p); } return false; } + /** + * Test whether the provided {@link FileSystem} object reference the same actual filesystem as the member <code>fs</code>. + * + * @param other + * The filesystem to compare + */ + boolean equivalentFileSystems(FileSystem other) { + return fs.getUri().equals(other.getUri()); + } + + /** + * Tests if the provided {@link Path} is rooted inside this volume, contained within <code>basePath</code>. + * + * @param other + * The path to compare + */ + boolean equivalentPaths(Path other) { + return other.toUri().getPath().startsWith(basePath); + } + @Override public boolean equals(Object o) { if (o instanceof VolumeImpl) { http://git-wip-us.apache.org/repos/asf/accumulo/blob/2ca91038/core/src/test/java/org/apache/accumulo/core/volume/VolumeImplTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/volume/VolumeImplTest.java b/core/src/test/java/org/apache/accumulo/core/volume/VolumeImplTest.java new file mode 100644 index 0000000..ec240f0 --- /dev/null +++ b/core/src/test/java/org/apache/accumulo/core/volume/VolumeImplTest.java @@ -0,0 +1,90 @@ +/* + * 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.accumulo.core.volume; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.net.URI; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.junit.Test; + +public class VolumeImplTest { + + @Test + public void testFileSystemInequivalence() { + FileSystem fs = createMock(FileSystem.class), other = createMock(FileSystem.class); + String basePath = "/accumulo"; + + VolumeImpl volume = new VolumeImpl(fs, basePath); + + expect(fs.getUri()).andReturn(URI.create("hdfs://localhost:8020")).anyTimes(); + expect(other.getUri()).andReturn(URI.create("hdfs://otherhost:8020")).anyTimes(); + + replay(fs, other); + + assertFalse(volume.equivalentFileSystems(other)); + + verify(fs, other); + } + + @Test + public void testFileSystemEquivalence() { + FileSystem fs = createMock(FileSystem.class), other = createMock(FileSystem.class); + String basePath = "/accumulo"; + + VolumeImpl volume = new VolumeImpl(fs, basePath); + + expect(fs.getUri()).andReturn(URI.create("hdfs://myhost:8020")).anyTimes(); + expect(other.getUri()).andReturn(URI.create("hdfs://myhost:8020")).anyTimes(); + + replay(fs, other); + + assertTrue(volume.equivalentFileSystems(other)); + + verify(fs, other); + } + + @Test + public void testBasePathInequivalence() { + FileSystem fs = createMock(FileSystem.class); + + VolumeImpl volume = new VolumeImpl(fs, "/accumulo"); + + assertFalse(volume.equivalentPaths(new Path("/something/accumulo"))); + } + + @Test + public void testBasePathEquivalence() { + FileSystem fs = createMock(FileSystem.class); + + final String basePath = "/accumulo"; + VolumeImpl volume = new VolumeImpl(fs, basePath); + + // Bare path should match + assertTrue(volume.equivalentPaths(new Path(basePath))); + // Prefix should also match + assertTrue(volume.equivalentPaths(new Path(basePath + "/tables/1/F000001.rf"))); + } + +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/2ca91038/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java b/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java index 6e549a2..70332da 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java +++ b/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java @@ -313,11 +313,11 @@ public class VolumeManagerImpl implements VolumeManager { // we could also not find a matching one. We should still provide a Volume with the // correct FileSystem even though we don't know what the proper base dir is // e.g. Files on volumes that are now removed - log.debug("Found candidate Volumes for Path but none of the Paths are valid on the candidates: " + path); + log.debug("Found candidate Volumes for Path but none of the Volumes are valid for the candidates: " + path); + } else { + log.debug("Could not determine volume for Path: " + path); } - log.debug("Could not determine volume for Path: " + path); - return new NonConfiguredVolume(desiredFs); } catch (IOException ex) { throw new RuntimeException(ex);