* Create a new CephFileSystem.
*/
public CephFileSystem() {
- debug("CephFileSystem:enter");
+ if(debug) debug("CephFileSystem:enter");
root = new Path("/");
- debug("CephFileSystem:exit");
+ if(debug) debug("CephFileSystem:exit");
}
/**
*/
public URI getUri() {
if (!initialized) return null;
- debug("getUri:enter");
- debug("getUri:exit with return " + uri);
+ if(debug) debug("getUri:enter");
+ if(debug) debug("getUri:exit with return " + uri);
return uri;
}
*/
@Override
public void initialize(URI uri, Configuration conf) throws IOException {
- debug("initialize:enter");
+ if(debug) debug("initialize:enter");
if (!initialized) {
System.load(conf.get("fs.ceph.libDir")+"/libhadoopcephfs.so");
System.load(conf.get("fs.ceph.libDir")+"/libceph.so");
arguments += " -m ";
arguments += conf.get("fs.ceph.monAddr");
}
+ arguments += " --client-readahead-max-periods="
+ + conf.get("fs.ceph.readahead", "1");
//make sure they gave us a ceph monitor address or conf file
if ( (conf.get("fs.ceph.monAddr") == null) &&
(arguments.indexOf("-m") == -1) &&
(arguments.indexOf("-c") == -1) ) {
- debug("You need to specify a Ceph monitor address.");
+ if(debug) debug("You need to specify a Ceph monitor address.");
throw new IOException("You must specify a Ceph monitor address or config file!");
}
// Initialize the client
if (!ceph_initializeClient(arguments,
conf.getInt("fs.ceph.blockSize", 1<<26))) {
- debug("Ceph initialization failed!");
+ if(debug) debug("Ceph initialization failed!");
throw new IOException("Ceph initialization failed!");
}
initialized = true;
- debug("Initialized client. Setting cwd to /");
+ if(debug) debug("Initialized client. Setting cwd to /");
ceph_setcwd("/");
}
- debug("initialize:exit");
+ if(debug) debug("initialize:exit");
}
/**
public void close() throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("close:enter");
+ if(debug) debug("close:enter");
super.close();//this method does stuff, make sure it's run!
ceph_kill_client();
- debug("close:exit");
+ if(debug) debug("close:exit");
}
/**
Progressable progress) throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("append:enter with path " + file + " bufferSize " + bufferSize);
+ if(debug) debug("append:enter with path " + file + " bufferSize " + bufferSize);
Path abs_path = makeAbsolute(file);
if (progress!=null) progress.progress();
int fd = ceph_open_for_append(abs_path.toString());
abs_path.toString() + "\"");
}
CephOutputStream cephOStream = new CephOutputStream(getConf(), fd);
- debug("append:exit");
+ if(debug) debug("append:exit");
return new FSDataOutputStream(cephOStream);
}
@Deprecated
public String getName() {
if (!initialized) return null;
- debug("getName:enter");
- debug("getName:exit with value " + getUri().toString());
+ if(debug) debug("getName:enter");
+ if(debug) debug("getName:exit with value " + getUri().toString());
return getUri().toString();
}
*/
public Path getWorkingDirectory() {
if (!initialized) return null;
- debug("getWorkingDirectory:enter");
- debug("Working directory is " + ceph_getcwd());
- debug("getWorkingDirectory:exit");
+ if(debug) debug("getWorkingDirectory:enter");
+ if(debug) debug("Working directory is " + ceph_getcwd());
+ if(debug) debug("getWorkingDirectory:exit");
return new Path(fs_default_name + ceph_getcwd());
}
@Override
public void setWorkingDirectory(Path dir) {
if (!initialized) return;
- debug("setWorkingDirecty:enter with new working dir " + dir);
+ if(debug) debug("setWorkingDirecty:enter with new working dir " + dir);
Path abs_path = makeAbsolute(dir);
- debug("calling ceph_setcwd from Java");
+ if(debug) debug("calling ceph_setcwd from Java");
if (!ceph_setcwd(abs_path.toString()))
- debug("Warning:ceph_setcwd failed for some reason on path " + abs_path);
- debug("returned from ceph_setcwd to Java" );
- debug("setWorkingDirectory:exit");
+ if(debug) debug("Warning:ceph_setcwd failed for some reason on path " + abs_path);
+ if(debug) debug("returned from ceph_setcwd to Java" );
+ if(debug) debug("setWorkingDirectory:exit");
}
/**
public boolean exists(Path path) throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("exists:enter with path " + path);
+ if(debug) debug("exists:enter with path " + path);
boolean result;
Path abs_path = makeAbsolute(path);
if (abs_path.toString().equals("/")) {
result = true;
}
else {
- debug("Calling ceph_exists from Java on path "
+ if(debug) debug("Calling ceph_exists from Java on path "
+ abs_path.toString() + ":");
result = ceph_exists(abs_path.toString());
- debug("Returned from ceph_exists to Java");
+ if(debug) debug("Returned from ceph_exists to Java");
}
- debug("exists:exit with value " + result);
+ if(debug) debug("exists:exit with value " + result);
return result;
}
public boolean mkdirs(Path path, FsPermission perms) throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("mkdirs:enter with path " + path);
+ if(debug) debug("mkdirs:enter with path " + path);
Path abs_path = makeAbsolute(path);
- debug("calling ceph_mkdirs from Java");
+ if(debug) debug("calling ceph_mkdirs from Java");
int result = ceph_mkdirs(abs_path.toString(), (int)perms.toShort());
- debug("Returned from ceph_mkdirs to Java with result " + result);
- debug("mkdirs:exit with result " + result);
+ if(debug) debug("Returned from ceph_mkdirs to Java with result " + result);
+ if(debug) debug("mkdirs:exit with result " + result);
if (result != 0)
return false;
else return true;
public boolean isFile(Path path) throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("isFile:enter with path " + path);
+ if(debug) debug("isFile:enter with path " + path);
Path abs_path = makeAbsolute(path);
boolean result;
if (abs_path.toString().equals("/")) {
else {
result = ceph_isfile(abs_path.toString());
}
- debug("isFile:exit with result " + result);
+ if(debug) debug("isFile:exit with result " + result);
return result;
}
public boolean isDirectory(Path path) throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("isDirectory:enter with path " + path);
+ if(debug) debug("isDirectory:enter with path " + path);
Path abs_path = makeAbsolute(path);
boolean result;
if (abs_path.toString().equals(root)) {
result = true;
}
else {
- debug("calling ceph_isdirectory from Java");
+ if(debug) debug("calling ceph_isdirectory from Java");
result = ceph_isdirectory(abs_path.toString());
- debug("Returned from ceph_isdirectory to Java");
+ if(debug) debug("Returned from ceph_isdirectory to Java");
}
- debug("isDirectory:exit with result " + result);
+ if(debug) debug("isDirectory:exit with result " + result);
return result;
}
public FileStatus getFileStatus(Path path) throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("getFileStatus:enter with path " + path);
+ if(debug) debug("getFileStatus:enter with path " + path);
Path abs_path = makeAbsolute(path);
//sadly, Ceph doesn't really do uids/gids just yet, but
//everything else is filled
+ path + " does not exist or could not be accessed");
}
- debug("getFileStatus:exit");
+ if(debug) debug("getFileStatus:exit");
return status;
}
public FileStatus[] listStatus(Path path) throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("listStatus:enter with path " + path);
+ if(debug) debug("listStatus:enter with path " + path);
Path abs_path = makeAbsolute(path);
Path[] paths = listPaths(abs_path);
if (paths != null) {
for (int i = 0; i < paths.length; ++i) {
statuses[i] = getFileStatus(paths[i]);
}
- debug("listStatus:exit");
+ if(debug) debug("listStatus:exit");
return statuses;
}
if (!isFile(path)) throw new FileNotFoundException(); //if we get here, listPaths returned null
) throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("create:enter with path " + path);
+ if(debug) debug("create:enter with path " + path);
Path abs_path = makeAbsolute(path);
if (progress!=null) progress.progress();
// We ignore replication since that's not configurable here, and
if (progress!=null) progress.progress();
}
// Step 3: open the file
- debug("calling ceph_open_for_overwrite from Java");
+ if(debug) debug("calling ceph_open_for_overwrite from Java");
int fh = ceph_open_for_overwrite(abs_path.toString(), (int)permission.toShort());
if (progress!=null) progress.progress();
- debug("Returned from ceph_open_for_overwrite to Java with fh " + fh);
+ if(debug) debug("Returned from ceph_open_for_overwrite to Java with fh " + fh);
if (fh < 0) {
throw new IOException("create: Open for overwrite failed on path \"" +
path.toString() + "\"");
// Step 4: create the stream
OutputStream cephOStream = new CephOutputStream(getConf(), fh);
- debug("create:exit");
+ if(debug) debug("create:exit");
return new FSDataOutputStream(cephOStream);
}
public FSDataInputStream open(Path path, int bufferSize) throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("open:enter with path " + path);
+ if(debug) debug("open:enter with path " + path);
Path abs_path = makeAbsolute(path);
int fh = ceph_open_for_read(abs_path.toString());
" but succeeded in opening file. Something bizarre is going on.");
}
FSInputStream cephIStream = new CephInputStream(getConf(), fh, size);
- debug("open:exit");
+ if(debug) debug("open:exit");
return new FSDataInputStream(cephIStream);
}
public boolean rename(Path src, Path dst) throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("rename:enter");
- debug("calling ceph_rename from Java");
+ if(debug) debug("rename:enter");
+ if(debug) debug("calling ceph_rename from Java");
Path abs_src = makeAbsolute(src);
Path abs_dst = makeAbsolute(dst);
boolean result = ceph_rename(abs_src.toString(), abs_dst.toString());
- debug("return from ceph_rename to Java with result " + result);
- debug("rename:exit");
+ if(debug) debug("return from ceph_rename to Java with result " + result);
+ if(debug) debug("rename:exit");
return result;
}
public FsStatus getStatus (Path path) throws IOException {
if (!initialized) throw new IOException("You have to initialize the"
+ " CephFileSystem before calling other methods.");
- debug("getStatus:enter");
+ if(debug) debug("getStatus:enter");
Path abs_path = makeAbsolute(path);
//currently(Ceph .12) Ceph actually ignores the path
CephStat ceph_stat = new CephStat();
int result = ceph_statfs(abs_path.toString(), ceph_stat);
if (result!=0) throw new IOException("Somehow failed to statfs the Ceph filesystem. Error code: " + result);
- debug("getStatus:exit");
+ if(debug) debug("getStatus:exit");
return new FsStatus(ceph_stat.capacity,
ceph_stat.used, ceph_stat.remaining);
} */
public boolean delete(Path path, boolean recursive) throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("delete:enter");
+ if(debug) debug("delete:enter");
Path abs_path = makeAbsolute(path);
- //debug("delete: Deleting path " + abs_path.toString());
+ if(debug) debug("delete: Deleting path " + abs_path.toString());
// sanity check
if (abs_path.toString().equals(root))
throw new IOException("Error: deleting the root directory is a Bad Idea.");
// if the path is a file, try to delete it.
if (isFile(abs_path)) {
boolean result = ceph_unlink(abs_path.toString());
- /* if(!result) {
- debug("delete: failed to delete file \"" +
- abs_path.toString() + "\".");
- } */
- debug("delete:exit");
+ if(!result)
+ if(debug) debug("delete: failed to delete file \"" +
+ abs_path.toString() + "\".");
+ if(debug) debug("delete:exit");
return result;
}
//get the entries; listPaths will remove . and .. for us
Path[] contents = listPaths(abs_path);
if (contents == null) {
- // debug("delete: Failed to read contents of directory \"" +
- // abs_path.toString() + "\" while trying to delete it");
- debug("delete:exit");
+ if(debug) debug("delete: Failed to read contents of directory \"" +
+ abs_path.toString() + "\" while trying to delete it");
+ if(debug) debug("delete:exit");
return false;
}
// delete the entries
Path parent = abs_path.getParent();
for (Path p : contents) {
if (!delete(p, true)) {
- // debug("delete: Failed to delete file \"" +
- // p.toString() + "\" while recursively deleting \""
- // + abs_path.toString() + "\"" );
- debug("delete:exit");
+ if(debug) debug("delete: Failed to delete file \"" +
+ p.toString() + "\" while recursively deleting \""
+ + abs_path.toString() + "\"" );
+ if(debug) debug("delete:exit");
return false;
}
}
//if we've come this far it's a now-empty directory, so delete it!
boolean result = ceph_rmdir(abs_path.toString());
if (!result)
- debug("delete: failed to delete \"" + abs_path.toString() + "\"");
- debug("delete:exit");
+ if(debug) debug("delete: failed to delete \"" + abs_path.toString() + "\"");
+ if(debug) debug("delete:exit");
return result;
}
public long getBlockSize(Path path) throws IOException {
if (!initialized) throw new IOException ("You have to initialize the"
+"CephFileSystem before calling other methods.");
- debug("getBlockSize:enter with path " + path);
+ if(debug) debug("getBlockSize:enter with path " + path);
Path abs_path = makeAbsolute(path);
long result = ceph_getblocksize(abs_path.toString());
throw new IOException("org.apache.hadoop.fs.ceph.CephFileSystem.getBlockSize: File or directory "
+ path.toString() + " does not exist.");
- debug("getBlockSize:exit with result " + result);
+ if(debug) debug("getBlockSize:exit with result " + result);
return result;
}
// Makes a Path absolute. In a cheap, dirty hack, we're
// also going to strip off any fs_default_name prefix we see.
private Path makeAbsolute(Path path) {
- debug("makeAbsolute:enter with path " + path);
+ if(debug) debug("makeAbsolute:enter with path " + path);
if (path == null) return new Path("/");
// first, check for the prefix
if (path.toString().startsWith(fs_default_name)) {
Path stripped_path = new Path(path.toString().substring(fs_default_name.length()));
- debug("makeAbsolute:exit with path " + stripped_path);
+ if(debug) debug("makeAbsolute:exit with path " + stripped_path);
return stripped_path;
}
if (path.isAbsolute()) {
- debug("makeAbsolute:exit with path " + path);
+ if(debug) debug("makeAbsolute:exit with path " + path);
return path;
}
Path new_path = new Path(ceph_getcwd(), path);
- debug("makeAbsolute:exit with path " + new_path);
+ if(debug) debug("makeAbsolute:exit with path " + new_path);
return new_path;
}
private Path[] listPaths(Path path) throws IOException {
- debug("listPaths:enter with path " + path);
+ if(debug) debug("listPaths:enter with path " + path);
String dirlist[];
Path abs_path = makeAbsolute(path);
// If it's a directory, get the listing. Otherwise, complain and give up.
- debug("calling ceph_getdir from Java with path " + abs_path);
+ if(debug) debug("calling ceph_getdir from Java with path " + abs_path);
dirlist = ceph_getdir(abs_path.toString());
- debug("returning from ceph_getdir to Java");
+ if(debug) debug("returning from ceph_getdir to Java");
if (dirlist == null) {
throw new IOException("listPaths: path " + path.toString() + " is not a directory.");
// convert the strings to Paths
Path[] paths = new Path[dirlist.length];
for (int i = 0; i < dirlist.length; ++i) {
- debug("Raw enumeration of paths in \"" + abs_path.toString() + "\": \"" +
+ if(debug) debug("Raw enumeration of paths in \"" + abs_path.toString() + "\": \"" +
dirlist[i] + "\"");
// convert each listing to an absolute path
Path raw_path = new Path(dirlist[i]);
else
paths[i] = new Path(abs_path, raw_path);
}
- debug("listPaths:exit");
+ if(debug) debug("listPaths:exit");
return paths;
}
private void debug(String statement) {
- if (debug) System.err.println(statement);
+ System.err.println(statement);
}
private class Stat {