ACCUMULO-2050 made it possible to recover logs on viewfs
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/b671fdaa Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/b671fdaa Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/b671fdaa Branch: refs/heads/master Commit: b671fdaa7d8afcff202abe471a203230ba17d176 Parents: cddf04f Author: Keith Turner <ktur...@apache.org> Authored: Thu Dec 19 21:26:59 2013 -0500 Committer: Keith Turner <ktur...@apache.org> Committed: Thu Dec 19 23:00:02 2013 -0500 ---------------------------------------------------------------------- .../apache/accumulo/server/fs/ViewFSUtils.java | 51 ++++++++++++++++++++ .../server/master/recovery/HadoopLogCloser.java | 14 +++++- 2 files changed, 64 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/b671fdaa/server/base/src/main/java/org/apache/accumulo/server/fs/ViewFSUtils.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/fs/ViewFSUtils.java b/server/base/src/main/java/org/apache/accumulo/server/fs/ViewFSUtils.java new file mode 100644 index 0000000..ae7a8ae --- /dev/null +++ b/server/base/src/main/java/org/apache/accumulo/server/fs/ViewFSUtils.java @@ -0,0 +1,51 @@ +/* + * 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.server.fs; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; + +/** + * + */ +public class ViewFSUtils { + public static boolean isViewFS(FileSystem fs) { + return fs.getClass().getName().equals("org.apache.hadoop.fs.viewfs.ViewFileSystem"); + } + + public static Path resolvePath(FileSystem fs, Path path) throws IOException { + // resolve path is new hadoop 2 so call it via reflection + try { + Method method = fs.getClass().getMethod("resolvePath", Path.class); + return (Path) method.invoke(fs, path); + } catch (IllegalArgumentException e) { + throw new IOException(e); + } catch (IllegalAccessException e) { + throw new IOException(e); + } catch (InvocationTargetException e) { + throw new IOException(e); + } catch (SecurityException e) { + throw new IOException(e); + } catch (NoSuchMethodException e) { + throw new IOException(e); + } + } +} http://git-wip-us.apache.org/repos/asf/accumulo/blob/b671fdaa/server/base/src/main/java/org/apache/accumulo/server/master/recovery/HadoopLogCloser.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/master/recovery/HadoopLogCloser.java b/server/base/src/main/java/org/apache/accumulo/server/master/recovery/HadoopLogCloser.java index b3c0934..0006bf9 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/master/recovery/HadoopLogCloser.java +++ b/server/base/src/main/java/org/apache/accumulo/server/master/recovery/HadoopLogCloser.java @@ -21,6 +21,8 @@ import java.io.IOException; import org.apache.accumulo.core.conf.AccumuloConfiguration; import org.apache.accumulo.core.conf.Property; +import org.apache.accumulo.core.util.CachedConfiguration; +import org.apache.accumulo.server.fs.ViewFSUtils; import org.apache.accumulo.server.fs.VolumeManager; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.LocalFileSystem; @@ -35,6 +37,16 @@ public class HadoopLogCloser implements LogCloser { @Override public long close(AccumuloConfiguration conf, VolumeManager fs, Path source) throws IOException { FileSystem ns = fs.getFileSystemByPath(source); + + // if path points to a viewfs path, then resolve to underlying filesystem + if (ViewFSUtils.isViewFS(ns)) { + Path newSource = ViewFSUtils.resolvePath(ns, source); + if (!newSource.equals(source) && newSource.toUri().getScheme() != null) { + ns = newSource.getFileSystem(CachedConfiguration.getInstance()); + source = newSource; + } + } + if (ns instanceof DistributedFileSystem) { DistributedFileSystem dfs = (DistributedFileSystem) ns; try { @@ -53,7 +65,7 @@ public class HadoopLogCloser implements LogCloser { } else if (ns instanceof LocalFileSystem) { // ignore } else { - throw new IllegalStateException("Don't know how to recover a lease for " + fs.getClass().getName()); + throw new IllegalStateException("Don't know how to recover a lease for " + ns.getClass().getName()); } return 0; }