From: Greg Farnum Date: Mon, 10 Oct 2011 15:19:47 +0000 (-0700) Subject: hadoop: bring back Java changes. X-Git-Tag: v0.38~57^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=952be11aaa9ce62df713838c4366f480da70b25b;p=ceph.git hadoop: bring back Java changes. These convert the Hadoop stuff to work on the branch-0.20 API. Signed-off-by: Greg Farnum --- diff --git a/src/client/hadoop/ceph/CephFS.java b/src/client/hadoop/ceph/CephFS.java index f9e1a061c947..fd294c765fa2 100644 --- a/src/client/hadoop/ceph/CephFS.java +++ b/src/client/hadoop/ceph/CephFS.java @@ -198,16 +198,6 @@ abstract class CephFS { */ abstract protected boolean ceph_stat(String path, CephFileSystem.Stat fill); - /* - * Statfs a filesystem in a custom format defined in CephFileSystem. - * Inputs: - * String path: A path on the filesystem that you wish to stat. - * CephStat fill: The CephStat object to fill. - * Returns: 0 if successful and the CephStat is filled; a negative - * error code otherwise. - */ - abstract protected int ceph_statfs(String path, CephFileSystem.CephStat fill); - /* * Check how many times a file should be replicated. If it is, * degraded it may not actually be replicated this often. @@ -215,7 +205,7 @@ abstract class CephFS { * int fh: a file descriptor * Returns: an int containing the number of times replicated. */ - abstract protected int ceph_replication(int fh); + abstract protected int ceph_replication(String path); /* * Find the IP address of the primary OSD for a given file and offset. diff --git a/src/client/hadoop/ceph/CephFaker.java b/src/client/hadoop/ceph/CephFaker.java index 5e638035d87d..00364b732768 100644 --- a/src/client/hadoop/ceph/CephFaker.java +++ b/src/client/hadoop/ceph/CephFaker.java @@ -31,10 +31,8 @@ import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.BlockLocation; -import org.apache.hadoop.fs.FileAlreadyExistsException; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.FsStatus; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.Path; @@ -221,12 +219,12 @@ class CephFaker extends CephFS { if (localFS.mkdirs(new Path(path), new FsPermission((short) mode))) { return 0; } - } catch (FileAlreadyExistsException fe) { - return ENOTDIR; } catch (IOException e) {} - if (ceph_isdirectory(path)) { + if (ceph_isdirectory(path)) { // apparently it already existed return -EEXIST; - } // apparently it already existed + } else if (ceph_isfile(path)) { + return -ENOTDIR; + } return -1; } @@ -341,19 +339,6 @@ class CephFaker extends CephFS { return ret; } - protected int ceph_statfs(String pth, CephFileSystem.CephStat fill) { - pth = prepare_path(pth); - try { - FsStatus stat = localFS.getStatus(); - - fill.capacity = stat.getCapacity(); - fill.used = stat.getUsed(); - fill.remaining = stat.getRemaining(); - return 0; - } catch (Exception e) {} - return -1; // failure; - } - protected int ceph_replication(String path) { path = prepare_path(path); int ret = -1; // -1 for failure diff --git a/src/client/hadoop/ceph/CephFileSystem.java b/src/client/hadoop/ceph/CephFileSystem.java index e57442e889ac..c69707510d9a 100644 --- a/src/client/hadoop/ceph/CephFileSystem.java +++ b/src/client/hadoop/ceph/CephFileSystem.java @@ -30,7 +30,6 @@ import java.lang.Math; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.BlockLocation; -import org.apache.hadoop.fs.FileAlreadyExistsException; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSInputStream; import org.apache.hadoop.fs.FSDataOutputStream; @@ -40,8 +39,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.util.Progressable; import org.apache.hadoop.fs.FileStatus; -import org.apache.hadoop.fs.FsStatus; -import org.apache.hadoop.fs.CreateFlag; /** @@ -330,7 +327,7 @@ public class CephFileSystem extends FileSystem { "mkdirs: make directory " + abs_path + "Failing with result " + result, ceph.WARN); if (ceph.ENOTDIR == result) { - throw new FileAlreadyExistsException("Parent path is not a directory"); + throw new IOException("Parent path is not a directory"); } return false; } else { @@ -518,8 +515,8 @@ public class CephFileSystem extends FileSystem { * Create a new file and open an FSDataOutputStream that's connected to it. * @param path The file to create. * @param permission The permissions to apply to the file. - * @param flag If CreateFlag.OVERWRITE, overwrite any existing - * file with this name; otherwise don't. + * @param overwrite If true, overwrite any existing file with + * this name; otherwise don't. * @param bufferSize Ceph does internal buffering, but you can buffer * in the Java code too if you like. * @param replication Ignored by Ceph. This can be @@ -536,7 +533,6 @@ public class CephFileSystem extends FileSystem { public FSDataOutputStream create(Path path, FsPermission permission, boolean overwrite, - // boolean overwrite, int bufferSize, short replication, long blockSize, @@ -787,39 +783,9 @@ public class CephFileSystem extends FileSystem { return locations; } - /** - * Get usage statistics on the Ceph filesystem. - * @param path A path to the partition you're interested in. - * Ceph doesn't partition, so this is ignored. - * @return FsStatus reporting capacity, usage, and remaining space. - * @throws IOException if initialize() hasn't been called, or the - * stat somehow fails. - */ - @Override - public FsStatus getStatus(Path path) throws IOException { - if (!initialized) { - throw new IOException( - "You have to initialize the " - + "CephFileSystem before calling other methods."); - } - ceph.debug("getStatus:enter with path " + path, ceph.DEBUG); - Path abs_path = makeAbsolute(path); - - // currently(Ceph .16) Ceph actually ignores the path - // but we still pass it in; if Ceph stops ignoring we may need more - // error-checking code. - CephStat ceph_stat = new CephStat(); - - ceph.debug("getStatus:calling ceph_statfs from Java", ceph.TRACE); - int result = ceph.ceph_statfs(abs_path.toString(), ceph_stat); - - if (result != 0) { - throw new IOException( - "Somehow failed to statfs the Ceph filesystem. Error code: " + result); - } - ceph.debug("getStatus:exit successfully", ceph.DEBUG); - return new FsStatus(ceph_stat.capacity, ceph_stat.used, ceph_stat.remaining); - } + public boolean delete(Path path) throws IOException { + return delete(path, false); + } /** * Delete the given path, and optionally its children. @@ -996,13 +962,4 @@ public class CephFileSystem extends FileSystem { public Stat() {} } - - - static class CephStat { - public long capacity; - public long used; - public long remaining; - - public CephStat() {} - } } diff --git a/src/client/hadoop/ceph/CephTalker.java b/src/client/hadoop/ceph/CephTalker.java index 8b52441b60eb..b2e9909c7efe 100644 --- a/src/client/hadoop/ceph/CephTalker.java +++ b/src/client/hadoop/ceph/CephTalker.java @@ -33,8 +33,8 @@ class CephTalker extends CephFS { // we write a constructor so we can load the libraries public CephTalker(Configuration conf, Log log) { super(conf, log); - System.load(conf.get("fs.ceph.libDir") + "/libhadoopcephfs.so"); System.load(conf.get("fs.ceph.libDir") + "/libcephfs.so"); + System.load(conf.get("fs.ceph.libDir") + "/libhadoopcephfs.so"); cluster = 0; } @@ -76,9 +76,7 @@ class CephTalker extends CephFS { protected native boolean ceph_stat(String path, CephFileSystem.Stat fill); - protected native int ceph_statfs(String Path, CephFileSystem.CephStat fill); - - protected native int ceph_replication(int fh); + protected native int ceph_replication(String Path); protected native String ceph_hosts(int fh, long offset);