automake: enable 'make V=0'
PATCH 1/1 automake: enable 'make V=0'
From: Noah Watkins <[email protected]>
Enables silent mode for automake generated Makefiles, and silent mode is _off_ by default. Using V=0 the output is much easier to read when trying to find warnings:
nwatkins@piha:~/Projects/ceph/ceph$ make -j8 V=0 make[3]: Entering directory `/users/nwatkins/Projects/ceph/ceph/src' CC locks.o CXX journal.o CXX Server.o CXX Mutation.o CXX MDCache.o CXX Locker.o CXX Migrator.o CXX MDBalancer.o CXX CDentry.o CXX CDir.o CXX CInode.o CXX LogEvent.o CXX MDSTable.o
--- configure.ac | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
configure.ac +3 -0
@@ -20,6 +20,9 @@ AM_INIT_AUTOMAKE AM_PROG_CC_C_O AM_PROG_LIBTOOL +# Enable make V=0 +AM_SILENT_RULES([yes]) + # Platform case "${target_os}" in darwin*)
Signature · 1 line
1.7.1
PATCH 1/4 client: return stripe address replicas
From: Noah Watkins <[email protected]>
Changes ceph_get_file_stripe_address to return a vector of entity_addr_t's for the primary and the replicas. libcephfs is updated to return the associated sockaddr_storage for each address.
--- src/client/Client.cc | 17 +++++++---------- src/client/Client.h | 2 +- src/include/cephfs/libcephfs.h | 4 ++-- src/libcephfs.cc | 30 ++++++++++++++++++------------ 4 files changed, 28 insertions(+), 25 deletions(-)
src/client/Client.cc +7 -10
@@ -6829,7 +6829,7 @@ int Client::get_pool_replication(int64_t pool) return osdmap->get_pg_pool(pool)->get_size(); } -int Client::get_file_stripe_address(int fd, loff_t offset, string& address) +int Client::get_file_stripe_address(int fd, loff_t offset, vector<entity_addr_t>& address) { Mutex::Locker lock(client_lock);
@@ -6848,15 +6848,12 @@ int Client::get_file_stripe_address(int fd, loff_t offset, string& address) osdmap->pg_to_acting_osds(pg, osds); if (!osds.size()) return -EINVAL; - - // now we have the osd(s) - entity_addr_t addr = osdmap->get_addr(osds[0]); - - // now we need to turn it into a string - char foo[30]; - __u8 *quad = (__u8*) &addr.in4_addr().sin_addr; - snprintf(foo, sizeof(foo), "%d.%d.%d.%d", (int)quad[0], (int)quad[1], (int)quad[2], (int)quad[3]); - address = foo; + + for (unsigned i = 0; i < osds.size(); i++) { + entity_addr_t addr = osdmap->get_addr(osds[i]); + address.push_back(addr); + } + return 0; }
src/client/Client.h +1 -1
@@ -607,7 +607,7 @@ public:// expose file layout int describe_layout (int fd,ceph_file_layout * layout); - int get_file_stripe_address(int fd, loff_t offset, string& address); + int get_file_stripe_address(int fd, loff_t offset, vector<entity_addr_t>& address);// expose osdmap int get_local_osd ();
src/include/cephfs/libcephfs.h +2 -2
@@ -156,8 +156,8 @@ int ceph_lsetxattr(struct ceph_mount_info *cmount, const char *path, const charint ceph_get_file_stripe_unit (struct ceph_mount_info *cmount,int fh);int ceph_get_file_pool (struct ceph_mount_info *cmount,int fh);int ceph_get_file_replication (struct ceph_mount_info *cmount,int fh); -int ceph_get_file_stripe_address (struct ceph_mount_info *cmount,int fd, -loff_t offset,char *buf,int buflen); +int ceph_get_file_stripe_address (struct ceph_mount_info *cmount,int fd,loff_t offset, +struct sockaddr_storage *addr,int naddr);/* set default layout for new files */ int ceph_set_default_file_stripe_unit (struct ceph_mount_info *cmount,int stripe);
src/libcephfs.cc +18 -12
@@ -584,21 +584,27 @@ extern "C" int ceph_set_default_preferred_pg(struct ceph_mount_info *cmount, int } extern "C" int ceph_get_file_stripe_address(struct ceph_mount_info *cmount, int fh, - loff_t offset, char *buf, int buflen) + loff_t offset, struct sockaddr_storage *addr, int naddr) { - string address; - int r = cmount->get_client()->get_file_stripe_address(fh, offset, address); + vector<entity_addr_t> address; + unsigned i; + int r; + + if (naddr < 0) + return -EINVAL; + + r = cmount->get_client()->get_file_stripe_address(fh, offset, address); if (r < 0) - return r; - int len = address.size()+1; - if (len > buflen) { - if (buflen == 0) - return len; + return r; + + for (i = 0; i < (unsigned)naddr && i < address.size(); i++) + memcpy(&addr[i], &address[i].ss_addr(), sizeof(*addr)); + + /* naddr == 0: drop through and return actual size */ + if (naddr && (address.size() > (unsigned)naddr)) return -ERANGE; - } - len = address.copy(buf, len, 0); - buf[len] = '\0'; // write a null char to terminate c-style string - return 0; + + return address.size(); } extern "C" int ceph_localize_reads(struct ceph_mount_info *cmount, int val)
Signature · 1 line
1.7.1
Re: [PATCH 1/4] client: return stripe address replicas
Quoted 2 lines · Noah Watkins
+ /* naddr == 0: drop through and return actual size */
+ if (naddr && (address.size()> (unsigned)naddr))
I have to say I'm not completely comfortable with the magicness of naddr==0, mostly because I haven't seen other APIs do it like that. --
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/4] client: return stripe address replicas
----- Original Message -----
Quoted 7 lines
From: "Tommi Virtanen" <[email protected]>
To: "Noah Watkins" <[email protected]>
Cc: "ceph-devel" <[email protected]>
Sent: Wednesday, November 9, 2011 1:36:28 PM
Subject: Re: [PATCH 1/4] client: return stripe address replicas On Tue, Nov 8, 2011 at 18:39, Noah Watkins <[email protected]> wrote:
Quoted 5 lines
Quoted 2 lines
+ /* naddr == 0: drop through and return actual size */
+ if (naddr && (address.size()> (unsigned)naddr))I have to say I'm not completely comfortable with the magicness of naddr==0, mostly because I haven't seen other APIs do it like that.
I'm with you, I haven't seen it -- atleast I couldn't find a good example in libc. I guess it's technically a special case as 0 would be too small and the user would expect ERANGE. I'm pretty neutral on this as it's for pretty specialized users.
Re: [PATCH 1/4] client: return stripe address replicas
In reply to Tommi VirtanenQuoted 6 lines · Tommi Virtanen
Quoted 2 lines · Noah Watkins
+ /* naddr == 0: drop through and return actual size */
+ if (naddr && (address.size()> (unsigned)naddr))I have to say I'm not completely comfortable with the magicness of naddr==0, mostly because I haven't seen other APIs do it like that.
getxattr(2) and listxattr(2) are the ones I've seen:
"An empty buffer of size zero can be passed into these calls to return the current size of the list of extended attribute names, which can be used to estimate the size of a buffer which is sufficiently large to hold the list of names."
PATCH 2/4 hadoop: handle new ceph_get_file_stripe_address
In reply to Noah WatkinsFrom: Noah Watkins <[email protected]>
Updates the Hadoop JNI/CephFileSystem to handle the new version of ceph_get_file_stripe_address which returns the locations of replicas in addition to the primary.
--- src/client/hadoop/CephFSInterface.cc | 74 +++++++++++++++++++++------- src/client/hadoop/CephFSInterface.h | 4 +- src/client/hadoop/ceph/CephFS.java | 4 +- src/client/hadoop/ceph/CephFaker.java | 6 +- src/client/hadoop/ceph/CephFileSystem.java | 6 +- src/client/hadoop/ceph/CephTalker.java | 2 +- 6 files changed, 67 insertions(+), 29 deletions(-)
src/client/hadoop/CephFSInterface.cc +56 -18
@@ -759,35 +759,73 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephTalker_ceph_1replicati /* * Class: org_apache_hadoop_fs_ceph_CephTalker * Method: ceph_hosts - * Signature: (IJ)Ljava/lang/String; + * Signature: (IJ)[Ljava/lang/String; * Find the IP:port addresses of the primary OSD for a given file and offset. * Inputs: * jint j_fh: The filehandle for the file. * jlong j_offset: The offset to get the location of. * Returns: a jstring of the location as IP, or NULL if there is an error. */ -JNIEXPORT jstring JNICALL Java_org_apache_hadoop_fs_ceph_CephTalker_ceph_1hosts +JNIEXPORT jobjectArray JNICALL Java_org_apache_hadoop_fs_ceph_CephTalker_ceph_1hosts (JNIEnv *env, jobject obj, jint j_fh, jlong j_offset) { - //get the address - const static int IP_ADDR_LENGTH = 24;//a buffer size; may want to up for IPv6. - char *address = new char[IP_ADDR_LENGTH]; struct ceph_mount_info *cmount = get_ceph_mount_t(env, obj); - int r = ceph_get_file_stripe_address(cmount, j_fh, j_offset, - address, IP_ADDR_LENGTH); - if (r == -ERANGE) {//buffer's too small - delete [] address; - int size = ceph_get_file_stripe_address(cmount, j_fh, j_offset, address, 0); - address = new char[size]; - r = ceph_get_file_stripe_address(cmount, j_fh, j_offset, address, size); + struct sockaddr_storage *ss; + char address[30]; + jobjectArray addr_array; + jclass string_cls; + jstring j_addr; + int r, n = 3; /* initial guess at # of replicas */ + + for (;;) { + ss = new struct sockaddr_storage[n]; + r = ceph_get_file_stripe_address(cmount, j_fh, j_offset, ss, n); + if (r < 0) { + if (r == -ERANGE) { + delete [] ss; + n *= 2; + continue; + } + return NULL; + } + n = r; + break; } - if (r != 0) { //some rather worse problem - if (r == -EINVAL) return NULL; //ceph thinks there are no OSDs + + /* TODO: cache this */ + string_cls = env->FindClass("java/lang/String"); + if (!string_cls) + goto out; + + addr_array = env->NewObjectArray(n, string_cls, NULL); + if (!addr_array) + goto out; + + for (r = 0; r < n; r++) { + /* Hadoop only deals with IPv4 */ + if (ss[r].ss_family != AF_INET) + goto out; + + memset(address, 0, sizeof(address)); + + inet_ntop(ss[r].ss_family, &((struct sockaddr_in *)&ss[r])->sin_addr, + address, sizeof(address)); + + j_addr = env->NewStringUTF(address); + + env->SetObjectArrayElement(addr_array, r, j_addr); + if (env->ExceptionOccurred()) + goto out; + + env->DeleteLocalRef(j_addr); } - //make java String of address - jstring j_addr = env->NewStringUTF(address); - delete [] address; - return j_addr; + + delete [] ss; + return addr_array; + +out: + delete [] ss; + return NULL; } /*
src/client/hadoop/CephFSInterface.h +2 -2
@@ -185,9 +185,9 @@ JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephTalker_ceph_1replicati/* * Class: org_apache_hadoop_fs_ceph_CephTalker * Method: ceph_hosts -* Signature: (IJ)Ljava/lang/String; +* Signature: (IJ)[Ljava/lang/String; */ -JNIEXPORT jstring JNICALL Java_org_apache_hadoop_fs_ceph_CephTalker_ceph_1hosts +JNIEXPORT jobjectArray JNICALL Java_org_apache_hadoop_fs_ceph_CephTalker_ceph_1hosts (JNIEnv *,jobject ,jint ,jlong );/*
src/client/hadoop/ceph/CephFS.java +2 -2
@@ -193,9 +193,9 @@ abstract class CephFS { * Inputs: * int fh: The filehandle for the file. * long offset: The offset to get the location of. - * Returns: a String of the location as IP, or NULL if there is an error. + * Returns: an array of String of the location as IP, or NULL if there is an error. */ - abstract protected String ceph_hosts(int fh, long offset); + abstract protected String[] ceph_hosts(int fh, long offset); /* * Set the mtime and atime for a given path.
src/client/hadoop/ceph/CephFaker.java +3 -3
@@ -348,15 +348,15 @@ class CephFaker extends CephFS { return ret; } - protected String ceph_hosts(int fh, long offset) { - String ret = null; + protected String[] ceph_hosts(int fh, long offset) { + String[] ret = null; try { BlockLocation[] locs = localFS.getFileBlockLocations( localFS.getFileStatus(new Path(filenames.get(new Integer(fh)))), offset, 1); - ret = locs[0].getNames()[0]; + ret = locs[0].getNames(); } catch (IOException e) {} catch (NullPointerException f) {} return ret; }
src/client/hadoop/ceph/CephFileSystem.java +3 -3
@@ -626,14 +626,14 @@ public class CephFileSystem extends FileSystem { LOG.trace( "getFileBlockLocations:call ceph_hosts from Java on fh " + fh + " and offset " + offset); - String host = ceph.ceph_hosts(fh, offset); + String host[] = ceph.ceph_hosts(fh, offset); LOG.trace( "getFileBlockLocations:return from ceph_hosts to Java with host " - + host); + + host[0]); String[] hostArray = new String[1]; - hostArray[0] = host; + hostArray[0] = host[0]; locations[i] = new BlockLocation(hostArray, hostArray, start + i * blockSize - (start % blockSize), blockSize); }
src/client/hadoop/ceph/CephTalker.java +1 -1
@@ -77,7 +77,7 @@ class CephTalker extends CephFS { protected native int ceph_replication(String Path); - protected native String ceph_hosts(int fh, long offset); + protected native String[] ceph_hosts(int fh, long offset); protected native int ceph_setTimes(String path, long mtime, long atime);
Signature · 1 line
1.7.1
PATCH 3/4 hadoop: return all replica hostnames
In reply to Noah WatkinsFrom: Noah Watkins <[email protected]>
Updates CephFileSystem to return all replica locations, and in addition attempts to use reverse DNS to convert the OSD IPs into hostnames. Hadoop does not do well at comparing the IP with hostnames, and locality is lost.
--- src/client/hadoop/ceph/CephFileSystem.java | 72 +++++++++++++++------------- 1 files changed, 38 insertions(+), 34 deletions(-)
src/client/hadoop/ceph/CephFileSystem.java +38 -34
@@ -25,8 +25,10 @@ import java.io.IOException; import java.io.FileNotFoundException; import java.io.OutputStream; import java.net.URI; +import java.net.InetAddress; import java.util.EnumSet; import java.lang.Math; +import java.util.ArrayList; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
@@ -41,6 +43,7 @@ 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.net.DNS; /**
@@ -72,6 +75,10 @@ public class CephFileSystem extends FileSystem { private final Path root; private CephFS ceph = null; + private static String CEPH_NAMESERVER; + private static final String CEPH_NAMESERVER_KEY = "fs.ceph.nameserver"; + private static final String CEPH_NAMESERVER_DEFAULT = "localhost"; + /** * Create a new CephFileSystem. */
@@ -115,6 +122,9 @@ public class CephFileSystem extends FileSystem { if (ceph == null) { ceph = new CephTalker(conf, LOG); } + + CEPH_NAMESERVER = conf.get(CEPH_NAMESERVER_KEY, CEPH_NAMESERVER_DEFAULT); + // build up the arguments for Ceph String arguments = "CephFSInterface";
@@ -580,6 +590,25 @@ public class CephFileSystem extends FileSystem { return result; } + /* + * Attempt to convert an IP into its hostname + */ + private String[] ips2Hosts(String[] ips) { + ArrayList<String> hosts = new ArrayList<String>(); + for (String ip : ips) { + try { + String host = DNS.reverseDns(InetAddress.getByName(ip), CEPH_NAMESERVER); + if (host.charAt(host.length()-1) == '.') { + host = host.substring(0, host.length()-1); + } + hosts.add(host); /* append */ + } catch (Exception e) { + LOG.error("reverseDns ["+ip+"] failed: "+ e); + } + } + return hosts.toArray(new String[hosts.size()]); + } + /** * Get a BlockLocation object for each block in a file. *
@@ -595,52 +624,27 @@ public class CephFileSystem extends FileSystem { */ @Override public BlockLocation[] getFileBlockLocations(FileStatus file, long start, long len) throws IOException { - LOG.debug( - "getFileBlockLocations:enter with path " + file.getPath() - + ", start pos " + start + ", length " + len); - // sanitize and get the filehandle Path abs_path = makeAbsolute(file.getPath()); - LOG.trace("getFileBlockLocations:call ceph_open_for_read from Java"); int fh = ceph.ceph_open_for_read(getCephPath(abs_path)); - - LOG.trace( - "getFileBlockLocations:return from ceph_open_for_read to Java with fh " - + fh); if (fh < 0) { - LOG.error( - "getFileBlockLocations:got error " + fh - + ", exiting and returning null!"); + LOG.error("getFileBlockLocations:got error " + fh + ", exiting and returning null!"); return null; } - // get the block size - LOG.trace("getFileBlockLocations:call ceph_getblocksize from Java"); - long blockSize = ceph.ceph_getblocksize(getCephPath(abs_path)); - LOG.trace("getFileBlockLocations:return from ceph_getblocksize"); + long blockSize = ceph.ceph_getblocksize(getCephPath(abs_path)); BlockLocation[] locations = new BlockLocation[(int) Math.ceil(len / (float) blockSize)]; - long offset; for (int i = 0; i < locations.length; ++i) { - offset = start + i * blockSize; - LOG.trace( - "getFileBlockLocations:call ceph_hosts from Java on fh " + fh - + " and offset " + offset); - String host[] = ceph.ceph_hosts(fh, offset); - - LOG.trace( - "getFileBlockLocations:return from ceph_hosts to Java with host " - + host[0]); - String[] hostArray = new String[1]; - - hostArray[0] = host[0]; - locations[i] = new BlockLocation(hostArray, hostArray, - start + i * blockSize - (start % blockSize), blockSize); + long offset = start + i * blockSize; + long blockStart = start + i * blockSize - (start % blockSize); + String ips[] = ceph.ceph_hosts(fh, offset); + String hosts[] = ips2Hosts(ips); + locations[i] = new BlockLocation(null, hosts, blockStart, blockSize); + LOG.debug("getFileBlockLocations: location[" + i + "]: " + locations[i]); } - LOG.trace("getFileBlockLocations:call ceph_close from Java on fh " + fh); + ceph.ceph_close(fh); - LOG.debug( - "getFileBlockLocations:return with " + locations.length + " locations"); return locations; }
Signature · 1 line
1.7.1
PATCH 4/4 hadoop: make listStatus quiet
In reply to Noah WatkinsFrom: Noah Watkins <[email protected]>
--- src/client/hadoop/ceph/CephFileSystem.java | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
src/client/hadoop/ceph/CephFileSystem.java +1 -1
@@ -356,7 +356,7 @@ public class CephFileSystem extends FileSystem { * null if path does not exist. */ public FileStatus[] listStatus(Path path) throws IOException { - LOG.warn("listStatus:enter with path " + path); + LOG.debug("listStatus:enter with path " + path); Path abs_path = makeAbsolute(path); Path[] paths = listPaths(abs_path);
Signature · 1 line
1.7.1
Ah, much nicer. Applied!
sage
Quoted 50 lines · Noah Watkins
From: Noah Watkins <[email protected]>
Enables silent mode for automake generated Makefiles, and silent mode is _off_ by default. Using V=0 the output is much easier to read when trying to find warnings:
nwatkins@piha:~/Projects/ceph/ceph$ make -j8 V=0 make[3]: Entering directory `/users/nwatkins/Projects/ceph/ceph/src' CC locks.o CXX journal.o CXX Server.o CXX Mutation.o CXX MDCache.o CXX Locker.o CXX Migrator.o CXX MDBalancer.o CXX CDentry.o CXX CDir.o CXX CInode.o CXX LogEvent.o CXX MDSTable.oSigned-off-by Noah Watkins <[email protected]>--- configure.ac | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)configure.ac +3
-0@@ -20,6 +20,9 @@ AM_INIT_AUTOMAKE AM_PROG_CC_C_O AM_PROG_LIBTOOL +# Enable make V=0 +AM_SILENT_RULES([yes]) + # Platform case "${target_os}" in darwin*)Signature · 6 lines
1.7.1 -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html