From ba31462a2c4866f8565f2a92ea8916d79de19628 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 14 Jul 2011 12:43:25 -0700 Subject: [PATCH] rgw: configurable way to enable/disable cache --- src/common/config.cc | 1 + src/common/config.h | 3 +++ src/rgw/rgw_access.cc | 25 +++++++++++++++---------- src/rgw/rgw_access.h | 2 ++ src/rgw/rgw_cache.h | 13 +++++++++++++ src/rgw/rgw_rados.cc | 6 ++---- src/rgw/rgw_rados.h | 2 +- 7 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/common/config.cc b/src/common/config.cc index 03a08eeaa05b8..d542612f8dbc2 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -416,6 +416,7 @@ struct config_option config_optionsp[] = { OPTION(bdev_fake_mb, OPT_INT, 0), OPTION(bdev_fake_max_mb, OPT_INT, 0), OPTION(rgw_log, OPT_INT, 20), // log level for the Rados gateway + OPTION(rgw_cache_enabled, OPT_BOOL, false), // rgw cache enabled }; const int NUM_CONFIG_OPTIONS = sizeof(config_optionsp) / sizeof(config_option); diff --git a/src/common/config.h b/src/common/config.h index af14ffa324b48..1848fbf366474 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -502,7 +502,10 @@ public: bool bdev_debug_check_io_overlap; int bdev_fake_mb; int bdev_fake_max_mb; + + // rgw int rgw_log; + bool rgw_cache_enabled; }; typedef enum { diff --git a/src/rgw/rgw_access.cc b/src/rgw/rgw_access.cc index b27613acd083f..83d94d7d286f5 100644 --- a/src/rgw/rgw_access.cc +++ b/src/rgw/rgw_access.cc @@ -4,13 +4,10 @@ #include "rgw_rados.h" #include "rgw_cache.h" -#if 1 -static RGWCache fs_provider; -static RGWCache rados_provider; -#else +static RGWCache cached_fs_provider; +static RGWCache cached_rados_provider; static RGWFS fs_provider; static RGWRados rados_provider; -#endif RGWAccess* RGWAccess::store; @@ -20,12 +17,20 @@ RGWAccess::~RGWAccess() RGWAccess *RGWAccess::init_storage_provider(const char *type, CephContext *cct) { - if (strcmp(type, "rados") == 0) { - store = &rados_provider; - } else if (strcmp(type, "fs") == 0) { - store = &fs_provider; + int use_cache = cct->_conf->rgw_cache_enabled; + store = NULL; + if (!use_cache) { + if (strcmp(type, "rados") == 0) { + store = &rados_provider; + } else if (strcmp(type, "fs") == 0) { + store = &fs_provider; + } } else { - store = NULL; + if (strcmp(type, "rados") == 0) { + store = &cached_rados_provider; + } else if (strcmp(type, "fs") == 0) { + store = &cached_fs_provider; + } } if (store->initialize(cct) < 0) diff --git a/src/rgw/rgw_access.h b/src/rgw/rgw_access.h index ecc994c0951ed..05a1b1be26ee1 100644 --- a/src/rgw/rgw_access.h +++ b/src/rgw/rgw_access.h @@ -76,6 +76,8 @@ public: return ret; } + virtual int init_watch() { return -ENOTSUP; } + virtual void finalize_watch() {} virtual int distribute(bufferlist& bl) { return -ENOTSUP; } virtual int aio_wait(void *handle) { return -ENOTSUP; } diff --git a/src/rgw/rgw_cache.h b/src/rgw/rgw_cache.h index 47f88cac49374..1c8e248c2bdd2 100644 --- a/src/rgw/rgw_cache.h +++ b/src/rgw/rgw_cache.h @@ -127,6 +127,19 @@ class RGWCache : public T return normal_name(obj.bucket, obj.object); } + int initialize(CephContext *cct) { + int ret; + ret = T::initialize(cct); + if (ret < 0) + return ret; + + ret = T::init_watch(); + return ret; + } + + void finalize() { + T::finalize_watch(); + } int distribute(rgw_obj& obj, ObjectCacheInfo& obj_info, int op); int watch_cb(int opcode, uint64_t ver, bufferlist& bl); public: diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 3c994b2bc3906..b6b4aeb904b7e 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -54,12 +54,10 @@ int RGWRados::initialize(CephContext *cct) if (ret < 0) return ret; - ret = init_watch(); - return ret; } -void RGWRados::finalize() +void RGWRados::finalize_watch() { control_pool_ctx.unwatch(notify_oid, watch_handle); } @@ -1169,7 +1167,7 @@ int RGWRados::append_async(rgw_obj& obj, size_t size, bufferlist& bl) int RGWRados::distribute(bufferlist& bl) { - RGW_LOG(0) << "JJJ sending notification oid=" << notify_oid << " bl.length()=" << bl.length() << dendl; + RGW_LOG(0) << "sending notification oid=" << notify_oid << " bl.length()=" << bl.length() << dendl; int r = control_pool_ctx.notify(notify_oid, 0, bl); return r; } diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 59028893eee7d..804d8c58e042e 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -33,7 +33,6 @@ public: /** Initialize the RADOS instance and prepare to do other ops */ virtual int initialize(CephContext *cct); - virtual void finalize(); /** set up a bucket listing. id is ignored, handle is filled in. */ virtual int list_buckets_init(std::string& id, RGWAccessHandle *handle); /** @@ -127,6 +126,7 @@ public: virtual int append_async(rgw_obj& obj, size_t size, bufferlist& bl); virtual int init_watch(); + virtual void finalize_watch(); virtual int distribute(bufferlist& bl); virtual int watch_cb(int opcode, uint64_t ver, bufferlist& bl) { return 0; } }; -- 2.39.5