[sheepdog] [PATCH v2 2/2] sheep: add an option to disable object cache
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Wed May 16 03:54:16 CEST 2012
It is highly recommended to read the document carefully before using
the object cache.
https://github.com/collie/sheepdog/wiki/Backend-Stores-and-Object-Cache
This patch is useful for users whose environments don't meet the
requirements (e.g. sheep requires additional store on the gateway
nodes, we shouldn't access the same image from the different nodes
even if it is not the same time, etc). If you are unsure how the
object cache works, it's safe to disable it.
In future, it's better to support multiple cache features because the
requirements for the sheepdog write cache seem to be quite different
among users.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
sheep/group.c | 2 +-
sheep/ops.c | 8 ++++++--
sheep/sdnet.c | 3 ++-
sheep/sheep.c | 17 +++++++++++++++--
sheep/sheep_priv.h | 4 +++-
sheep/store.c | 18 +++++++++++-------
6 files changed, 38 insertions(+), 14 deletions(-)
diff --git a/sheep/group.c b/sheep/group.c
index 54bd8f3..0879bd6 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -1008,7 +1008,7 @@ static int need_consistency_check(struct request *req)
/* only check consistency for data objects */
return 0;
- if (object_is_cached(hdr->oid))
+ if (sys->enable_write_cache && object_is_cached(hdr->oid))
/* we don't check consistency for cached objects */
return 0;
diff --git a/sheep/ops.c b/sheep/ops.c
index ee704c6..9fa65bc 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -162,7 +162,7 @@ static int cluster_del_vdi(const struct sd_req *req, struct sd_rsp *rsp,
ret = del_vdi(hdr->epoch, data, hdr->data_length, &vid,
hdr->snapid, &nr_copies);
- if (ret == SD_RES_SUCCESS)
+ if (sys->enable_write_cache && ret == SD_RES_SUCCESS)
object_cache_delete(vid);
vdi_rsp->vdi_id = vid;
vdi_rsp->copies = nr_copies;
@@ -600,8 +600,12 @@ static int local_flush_vdi(const struct sd_req *req, struct sd_rsp *rsp, void *d
struct sd_obj_req *hdr = (struct sd_obj_req *)req;
uint64_t oid = hdr->oid;
uint32_t vid = oid_to_vid(oid);
- struct object_cache *cache = find_object_cache(vid, 0);
+ struct object_cache *cache;
+
+ if (!sys->enable_write_cache)
+ return SD_RES_SUCCESS;
+ cache = find_object_cache(vid, 0);
if (cache) {
if (!sys->async_flush)
return object_cache_push(cache);
diff --git a/sheep/sdnet.c b/sheep/sdnet.c
index bba023e..73ed8d5 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -199,7 +199,8 @@ static int check_request(struct request *req)
* if we go for a cached object, we don't care if it is busy
* or being recovered.
*/
- if ((hdr->flags & SD_FLAG_CMD_CACHE) && object_is_cached(hdr->oid))
+ if (sys->enable_write_cache && (hdr->flags & SD_FLAG_CMD_CACHE) &&
+ object_is_cached(hdr->oid))
return 0;
if (!req->local_oid && !req->local_cow_oid)
diff --git a/sheep/sheep.c b/sheep/sheep.c
index 4e6e266..5a4ac67 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -47,11 +47,13 @@ static struct option const long_options[] = {
{"stdout", no_argument, NULL, 'o'},
{"port", required_argument, NULL, 'p'},
{"vnodes", required_argument, NULL, 'v'},
+ {"enable-cache", no_argument, NULL, 'w'},
+ {"disable-cache", no_argument, NULL, 'W'},
{"zone", required_argument, NULL, 'z'},
{NULL, 0, NULL, 0},
};
-static const char *short_options = "ac:dDfg:Ghi:l:op:v:z:";
+static const char *short_options = "ac:dDfg:Ghi:l:op:v:wWz:";
static void usage(int status)
{
@@ -75,6 +77,8 @@ Options:\n\
-l, --loglevel specify the level of logging detail\n\
-p, --port specify the TCP port on which to listen\n\
-v, --vnodes specify the number of virtual nodes\n\
+ -w, --enable-cache enable writecache (default)\n\
+ -W, --disable-cache disable writecache\n\
-z, --zone specify the zone id\n\
", PACKAGE_VERSION, program_name);
exit(status);
@@ -111,6 +115,7 @@ int main(int argc, char **argv)
int nr_vnodes = SD_DEFAULT_VNODES;
char *p;
struct cluster_driver *cdrv;
+ int enable_write_cache = 1; /* enabled by default */
signal(SIGPIPE, SIG_IGN);
@@ -184,6 +189,14 @@ int main(int argc, char **argv)
}
sys->this_node.zone = zone;
break;
+ case 'w':
+ vprintf(SDOG_INFO, "enable write cache\n");
+ enable_write_cache = 1;
+ break;
+ case 'W':
+ vprintf(SDOG_INFO, "disable write cache\n");
+ enable_write_cache = 0;
+ break;
case 'v':
nr_vnodes = strtol(optarg, &p, 10);
if (optarg == p || nr_vnodes < 0 || SD_MAX_VNODES < nr_vnodes) {
@@ -234,7 +247,7 @@ int main(int argc, char **argv)
if (ret)
exit(1);
- ret = init_store(dir);
+ ret = init_store(dir, enable_write_cache);
if (ret)
exit(1);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index eb08915..e772397 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -100,6 +100,8 @@ struct cluster_info {
struct cluster_driver *cdrv;
const char *cdrv_option;
+ int enable_write_cache;
+
/* set after finishing the JOIN procedure */
int join_finished;
struct sd_node this_node;
@@ -217,7 +219,7 @@ extern struct objlist_cache obj_list_cache;
int create_listen_port(int port, void *data);
-int init_store(const char *dir);
+int init_store(const char *dir, int enable_write_cache);
int init_base_path(const char *dir);
int add_vdi(uint32_t epoch, char *data, int data_len, uint64_t size,
diff --git a/sheep/store.c b/sheep/store.c
index 718fa97..6b4565a 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -428,7 +428,7 @@ void do_io_request(struct work *work)
if (hdr->flags & SD_FLAG_CMD_IO_LOCAL) {
ret = do_local_io(req, epoch);
} else {
- if (bypass_object_cache(hdr)) {
+ if (!sys->enable_write_cache || bypass_object_cache(hdr)) {
/* fix object consistency when we read the object for the first time */
if (req->check_consistency) {
ret = fix_object_consistency(req);
@@ -814,7 +814,7 @@ static int init_store_driver(void)
return sd_store->init(obj_path);
}
-int init_store(const char *d)
+int init_store(const char *d, int enable_write_cache)
{
int ret;
@@ -846,9 +846,13 @@ int init_store(const char *d)
if (ret)
return ret;
- ret = object_cache_init(d);
- if (ret)
- return 1;
+ if (enable_write_cache) {
+ sys->enable_write_cache = 1;
+ ret = object_cache_init(d);
+ if (ret)
+ return 1;
+ }
+
return ret;
}
@@ -953,7 +957,7 @@ int write_object(struct vnode_info *vnodes, uint32_t node_version,
int i, fd, ret;
char name[128];
- if (object_is_cached(oid)) {
+ if (sys->enable_write_cache && object_is_cached(oid)) {
ret = write_inode_cache(oid, data, datalen, offset,
flags, nr_copies, node_version, create);
if (ret != 0) {
@@ -1087,7 +1091,7 @@ int read_object(struct vnode_info *vnodes, uint32_t node_version,
char name[128];
int i = 0, fd, ret, last_error = SD_RES_SUCCESS;
- if (object_is_cached(oid)) {
+ if (sys->enable_write_cache && object_is_cached(oid)) {
ret = read_object_cache(oid, data, datalen, offset,
nr_copies, node_version);
if (ret != SD_RES_SUCCESS)
--
1.7.2.5
More information about the sheepdog
mailing list