Skip to contentSkip to conversation

client: return stripe address replicas

RFC PATCH In review Noah Watkins 4 participants 12 messages Nov 7, 2011 – Nov 9, 2011

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 client: return stripe address replicas

The patch below is a first attempt at updating the libcephfs API to return replica locations. I wanted to get opinions on the interface. The short version of the patch is the API changes:

Client.h: returns vector of entity_addr_t
-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)

libcephfs.h: returns array of sockaddr_storage
int ceph_get_file_stripe_address(struct ceph_mount_info *cmount, int fd,
- loff_t offset, char *buf, int buflen);
+ loff_t offset, struct sockaddr_storage *addr, int naddr);

Thanks,
Noah

=========================================================

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 |    2 +-
 src/libcephfs.cc               |   28 +++++++++++++++-------------
 4 files changed, 24 insertions(+), 25 deletions(-)
src/client/Client.cc +7 -10
index 816fe83..1f01b80 100644
@@ -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
index bc98ac5..a30b73c 100644
@@ -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 +1 -1
index 4b2b64f..6a4a20b 100644
@@ -157,7 +157,7 @@ int 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);
+				 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 +15 -13
index 153348c..378ce7e 100644
@@ -584,21 +584,23 @@ 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 -ERANGE;
-  }
-  len = address.copy(buf, len, 0);
-  buf[len] = '\0'; // write a null char to terminate c-style string
-  return 0;
+    return r;
+
+  for (i = 0; i < (unsigned)naddr && i < address.size(); i++)
+    memcpy(&addr[i], &address[i].ss_addr(), sizeof(*addr));
+
+  return address.size();
 }
 
 extern "C" int ceph_localize_reads(struct ceph_mount_info *cmount, int val)
Signature · 1 line
1.7.1
#1 lore raw
Quoted 119 lines · Noah Watkins

The patch below is a first attempt at updating the libcephfs API to return replica locations. I wanted to get opinions on the interface. The short version of the patch is the API changes:

Client.h: returns vector of entity_addr_t
 -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)

libcephfs.h: returns array of sockaddr_storage
 int ceph_get_file_stripe_address(struct ceph_mount_info *cmount, int fd,
 -                              loff_t offset, char *buf, int buflen);
 +                              loff_t offset, struct sockaddr_storage *addr, int naddr);

Thanks,
Noah

=========================================================

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 |    2 +- src/libcephfs.cc               |   28 +++++++++++++++-------------

 4 files changed, 24 insertions(+), 25 deletions(-)
src/client/Client.cc +7 -10
index 816fe83..1f01b80 100644
@@ -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
index bc98ac5..a30b73c 100644
@@ -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 +1 -1
index 4b2b64f..6a4a20b 100644
@@ -157,7 +157,7 @@ int 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);
+                                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 +9 -12
index 153348c..378ce7e 100644
@@ -584,21 +584,23 @@ 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 -ERANGE;
-  }
-  len = address.copy(buf, len, 0);
-  buf[len] = '\0'; // write a null char to terminate c-style string

src/libcephfs.cc extern "C" int ceph_set_default_preferred_pg(struct ceph_mount_info *cmount, int · line 606

Quoted 10 lines
src/libcephfs.cc +6 -1
-  return 0;
+    return r;
+
+  for (i = 0; i < (unsigned)naddr && i < address.size(); i++)
+    memcpy(&addr[i], &address[i].ss_addr(), sizeof(*addr));
+
+  return address.size();
  }
 
  extern "C" int ceph_localize_reads(struct ceph_mount_info *cmount, int val)

This generally looks good to me, but that return statement is weirding me out a bit. I guess you're trying to compress the information about the number of returned addresses, and whether or not you got all the addresses, into that one value? It seems more idiomatic to me to send back the number of filled-in addresses, or an error code if there wasn't enough space for all of them.
I'm not sure if that idiom is worth applying here, but it was my one thought about the interface. :)
-Greg
--
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

#2 lore raw
Quoted 8 lines · Gregory Farnum

This generally looks good to me, but that return statement is weirding me out a bit. I guess you're trying to compress the information about the number of returned addresses, and whether or not you got all the addresses, into that one value? It seems more idiomatic to me to send back the number of filled-in addresses, or an error code if there wasn't enough space for all of them.
I'm not sure if that idiom is worth applying here, but it was my one thought about the interface. :)

The value in returning the number that *would have been written* is in that now the caller can reallocate a buffer of exactly the right size (barring races). Like snprintf() and friends. With just a generic -ENOBUFS/-EMSGSIZE/whatever you cram in there, the caller must do a series of increasing guesses.

But yes, the function is tricky to use right. Gets a 3 on the Rusty scale I'd say..

http://ozlabs.org/~rusty/index.cgi/tech/2008-03-30.html

Maybe instead of

extern "C" int ceph_get_file_stripe_address(struct ceph_mount_info *cmount, int fh,
loff_t offset, struct
sockaddr_storage *addr, int naddr)

it should be

extern "C" int ceph_get_file_stripe_address(struct ceph_mount_info *cmount, int fh,
loff_t offset, struct
sockaddr_storage *addr, int naddr, int *naddr_out)

and the return value is just 0 or -errno, gets -ESOMETHING if all entries won't fit, and naddr_out (if not NULL) is set to be the number of entries that would have been returned. More moving parts but harder to get wrong by forgetting to check ret < naddr.

#3 lore raw

----- Original Message -----

Quoted 8 lines

From: "Tommi Virtanen" <[email protected]>

The value in returning the number that *would have been written* is in that now the caller can reallocate a buffer of exactly the right size (barring races). Like snprintf() and friends. With just a generic -ENOBUFS/-EMSGSIZE/whatever you cram in there, the caller must do a series of increasing guesses.

Thanks for the feedback. I ended up using -ERANGE, and allow naddr=0 for querying the actual size.

-Noah

#4 lore raw
Quoted 10 lines · Noah Watkins

----- Original Message -----

Quoted 8 lines

From: "Tommi Virtanen" <[email protected]>

The value in returning the number that *would have been written* is in that now the caller can reallocate a buffer of exactly the right size (barring races). Like snprintf() and friends. With just a generic -ENOBUFS/-EMSGSIZE/whatever you cram in there, the caller must do a series of increasing guesses.

Quoted 2 lines

Thanks for the feedback. I ended up using -ERANGE, and allow naddr=0 for querying the actual size.

The only issue with this is that, in the event that you don't guess a sufficiently large array on the first call, you may need to call again, and in some cases that may mean multiple MDS requests. Normally that's not the case. And a smart caller should guess 4 and only pass 0 and then N if 4 failed. But a naive caller will always make two calls, first with 0 and then with N, and in some cases that's actually slower.

Does it matter?

sage

#5 lore raw
Quoted 8 lines · Sage Weil

On Tue, 8 Nov 2011, Noah Watkins wrote:

The only issue with this is that, in the event that you don't guess a sufficiently large array on the first call, you may need to call again, and in some cases that may mean multiple MDS requests.  Normally that's not the case.  And a smart caller should guess 4 and only pass 0 and then N if 4 failed.  But a naive caller will always make two calls, first with 0 and then with N, and in some cases that's actually slower.

The code I'm using makes a large guess, and an alternative is for the user to cache the replication factor for a file? A similar approach using ERANGE is used by listxattr (well, it communicates ERANGE via errno). In any case, even with Tommi's *naddr_out approach, a certain amount of precise documentation on it's semantics is needed.

- Noah
--
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

#6 lore raw
Quoted 10 lines · Noah Watkins
Quoted 8 lines · Sage Weil

On Tue, 8 Nov 2011, Noah Watkins wrote:

The only issue with this is that, in the event that you don't guess a sufficiently large array on the first call, you may need to call again, and in some cases that may mean multiple MDS requests.  Normally that's not the case.  And a smart caller should guess 4 and only pass 0 and then N if 4 failed.  But a naive caller will always make two calls, first with 0 and then with N, and in some cases that's actually slower.

Quoted 5 lines

The code I'm using makes a large guess, and an alternative is for the user to cache the replication factor for a file? A similar approach using ERANGE is used by listxattr (well, it communicates ERANGE via errno). In any case, even with Tommi's *naddr_out approach, a certain amount of precise documentation on it's semantics is needed.

I can't imagine anybody needing location data inside of a fast path, in any case. So it probably shouldn't matter, and for any bizarre case where it does we can probably expect a certain level of knowledge! -Greg
--
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

#10 lore raw
In reply to Noah Watkins
Quoted 10 lines · Noah Watkins
Quoted 8 lines · Sage Weil

On Tue, 8 Nov 2011, Noah Watkins wrote:

The only issue with this is that, in the event that you don't guess a sufficiently large array on the first call, you may need to call again, and in some cases that may mean multiple MDS requests.  Normally that's not the case.  And a smart caller should guess 4 and only pass 0 and then N if 4 failed.  But a naive caller will always make two calls, first with 0 and then with N, and in some cases that's actually slower.

Quoted 5 lines

The code I'm using makes a large guess, and an alternative is for the user to cache the replication factor for a file? A similar approach using ERANGE is used by listxattr (well, it communicates ERANGE via errno). In any case, even with Tommi's *naddr_out approach, a certain amount of precise documentation on it's semantics is needed.

Actually, I take it back, the 0 query will never need an additional MDS request because the file_layout is immutable for the lifetime of the file (currently at least; and even if it weren't it should very rarely change).

And yeah, I like the consistency wrt listxattr.

Ok!
sage

#7 lore raw
In reply to Gregory Farnum

----- Original Message -----

Quoted 6 lines

From: "Gregory Farnum" <[email protected]>

I can't imagine anybody needing location data inside of a fast path, in any case. So it probably shouldn't matter, and for any bizarre case where it does we can probably expect a certain level of knowledge! -Greg

Interestingly, Hadoop's start-up phase a big time sink. With 64 MB blocks and a 1 TB data set, we'd make something like 16,000 calls to get block location data which is serialized with the start of the job.

-Noah

#8 lore raw
Quoted 11 lines · Noah Watkins

----- Original Message -----

Quoted 6 lines

From: "Gregory Farnum" <[email protected]>

I can't imagine anybody needing location data inside of a fast path, in any case. So it probably shouldn't matter, and for any bizarre case where it does we can probably expect a certain level of knowledge! -Greg

Interestingly, Hadoop's start-up phase a big time sink. With 64 MB blocks and a 1 TB data set, we'd make something like 16,000 calls to get block location data which is serialized with the start of the job.

Hmm, interesting! In our case we jsut need the inodes in the libceph
client cache. If it's doing stats on files it knows are there, that'll
be O(num files), but if it is doing a readdir traversal type scan it'll be O(num directories).

sage

#11 lore raw
In reply to Sage Weil
Quoted 6 lines · Sage Weil

The only issue with this is that, in the event that you don't guess a sufficiently large array on the first call, you may need to call again, and in some cases that may mean multiple MDS requests.  Normally that's not the case.  And a smart caller should guess 4 and only pass 0 and then N if 4 failed.  But a naive caller will always make two calls, first with 0 and then with N, and in some cases that's actually slower.

That's the biggest benefit of the "return number that would be returned" or "int *naddr_out" approaches; if you didn't allocate enough, you get told how much to allocate. No need to 1. try with too small 2. probe for size 3. try with right size.
--
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

#9 lore raw
In reply to Sage Weil

----- Original Message -----

Quoted 4 lines

From: "Sage Weil" <[email protected]>

Hmm, interesting! In our case we jsut need the inodes in the libceph client cache.

I *think* HDFS does an RPC to get this info. So, since the client calculates this info, we might see big start-up perf. gains with large files.