[sheepdog] [PATCH v9 2/4] collie: let collie use sockfd cache
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Wed Jul 31 10:44:43 CEST 2013
From: Hitoshi Mitake <mitake.hitoshi at gmail.com>
This patch lets collie use sockfd cache. Because the sockfd caching
mechanism is now in libsheepdog, collie can enjoy it on some
subcommands which issue many requests to sheep.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
v8:
- fix an unsuitable error message of collie
v5:
- trivial cleaning. remove an old prototype of function
v4:
- remove the redundant function, collie_exec_req_nid()
collie/collie.c | 6 ++++++
collie/common.c | 22 +++++++++++++---------
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/collie/collie.c b/collie/collie.c
index 2f8e9d0..d6eef73 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -17,6 +17,7 @@
#include "sheep.h"
#include "collie.h"
#include "util.h"
+#include "sockfd_cache.h"
#define EPOLL_SIZE 4096
@@ -418,6 +419,11 @@ int main(int argc, char **argv)
exit(EXIT_SYSFAIL);
}
+ if (sockfd_init()) {
+ fprintf(stderr, "sockfd_init() failed\n");
+ exit(EXIT_SYSFAIL);
+ }
+
ret = command_fn(argc, argv);
if (ret == EXIT_USAGE)
subcommand_usage(argv[1], argv[2], EXIT_USAGE);
diff --git a/collie/common.c b/collie/common.c
index b2b9fb1..8c032ba 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -11,6 +11,7 @@
#include "collie.h"
#include "sha1.h"
+#include "sockfd_cache.h"
char *size_to_str(uint64_t _size, char *str, int str_size)
{
@@ -169,13 +170,18 @@ out:
return ret;
}
-int collie_exec_req(const char *host, int port, struct sd_req *hdr, void *data)
+int collie_exec_req(const char *host, int port, struct sd_req *hdr, void *buf)
{
- int fd, ret;
- struct sd_rsp *rsp = (struct sd_rsp *)hdr;
+ struct node_id nid;
+ struct sockfd *sfd;
+ int ret;
+
+ memset(&nid, 0, sizeof(nid));
+ str_to_addr(host, nid.addr);
+ nid.port = port;
- fd = connect_to(host, port);
- if (fd < 0)
+ sfd = sockfd_cache_get(&nid);
+ if (!sfd)
return -1;
/*
@@ -183,11 +189,9 @@ int collie_exec_req(const char *host, int port, struct sd_req *hdr, void *data)
* 1. We can't get the newest epoch
* 2. Some operations might take unexpected long time
*/
- ret = exec_req(fd, hdr, data, NULL, 0, UINT32_MAX);
- close(fd);
+ ret = exec_req(sfd->fd, hdr, buf, NULL, 0, UINT32_MAX);
- if (ret)
- return -1;
+ sockfd_cache_put(&nid, sfd);
return rsp->result;
}
--
1.7.10.4
More information about the sheepdog
mailing list