[Sheepdog] [PATCH] sheep: add an option to disable object cache
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Wed May 9 20:46:55 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 who cannot accept the limitation
(e.g. sheep requires additional store on the gateway nodes,
writethrough and writeback cannot be mixed to the same image, 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 | 3 ++-
sheep/ops.c | 8 ++++++--
sheep/sdnet.c | 3 ++-
sheep/sheep.c | 17 +++++++++++++++--
sheep/sheep_priv.h | 4 +++-
sheep/store.c | 14 +++++++++-----
6 files changed, 37 insertions(+), 12 deletions(-)
diff --git a/sheep/group.c b/sheep/group.c
index c7fd387..c781a6f 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -1033,7 +1033,8 @@ static void process_request_queue(void)
if (copies > req->vnodes->nr_zones)
copies = req->vnodes->nr_zones;
- if (!(req->rq.flags & SD_FLAG_CMD_IO_LOCAL) &&
+ if (sys->enable_write_cache &&
+ !(req->rq.flags & SD_FLAG_CMD_IO_LOCAL) &&
object_is_cached(hdr->oid)) {
/* If we have cache of it we are at its service. */
list_add_tail(&req->r_wlist, &sys->outstanding_req_list);
diff --git a/sheep/ops.c b/sheep/ops.c
index b6f8eb2..30c5d01 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 8aad8f9..730bed7 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -214,7 +214,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 2275a93..05949a2 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -107,6 +107,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;
@@ -224,7 +226,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 f8bf404..2500d9c 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -424,7 +424,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);
@@ -810,7 +810,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;
@@ -842,9 +842,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;
}
--
1.7.2.5
More information about the sheepdog
mailing list