]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Splt rados_init into rados_create + rados_connect
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 23 Feb 2011 12:43:12 +0000 (04:43 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 23 Feb 2011 18:17:30 +0000 (10:17 -0800)
Splt rados_init into rados_create and rados_connect.  The pattern will
be for users to call create, set configuration, and then connect. Rename
rados_release to rados_destroy, to be more symmetrical with
rados_create. You can't reconnect after calling destroy.

Don't create the messenger inside the RadosClient constructor. Instead,
wait until RadosClient::connect().

Rename rados_conf_apply to rados_reopen_log. Add comment about SIGHUP.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/include/rados/librados.h
src/librados.cc
src/testrados.c

index a240881ea40a439ea02e1a989c52e6d2654c5246..33cd30bfa5718d59e8f53816d2c1d8d31b673a06 100644 (file)
@@ -51,8 +51,13 @@ struct rados_statfs_t {
 void rados_version(int *major, int *minor, int *extra);
 
 /* initialization */
-int rados_init(rados_t *cluster);
-void rados_release(rados_t cluster);
+int rados_create(rados_t *cluster);
+
+/* Connect to the cluster */
+int rados_connect(rados_t cluster);
+
+/* destroy the cluster instance */
+void rados_destroy(rados_t cluster);
 
 /* Config
  *
@@ -66,8 +71,12 @@ int rados_conf_read_file(rados_t cluster, const char *path);
  * Returns 0 on success, error code otherwise. */
 int rados_conf_set(rados_t cluster, const char *option, const char *value);
 
-/* Applies any configuration changes */
-int rados_conf_apply(void);
+/* Reopens the log file.
+ * You must do this after changing the logging configuration.
+ * It is also good practice to call this from your SIGHUP signal handler, so that users can send you
+ * a SIGHUP to reopen the log.
+ */
+int rados_reopen_log(void);
 
 /* Returns a configuration value as a string.
  * If len is positive, that is the maximum number of bytes we'll write into the
index 569e09b81c049e45df9c973ade46cf9308a85425..3fb7dae02a62188e7d0a9d6b3b93d6932390dc2e 100644 (file)
@@ -79,13 +79,13 @@ class RadosClient : public Dispatcher
   SafeTimer timer;
 
 public:
-  RadosClient() : messenger(NULL), lock("radosclient"), timer(lock),
-                  max_watch_cookie(0) {
-    messenger = new SimpleMessenger();
+  RadosClient() : messenger(NULL), objecter(NULL),
+           lock("radosclient"), timer(lock), max_watch_cookie(0)
+  {
   }
 
   ~RadosClient();
-  int init();
+  int connect();
   void shutdown();
 
   struct PoolCtx {
@@ -484,14 +484,14 @@ public:
   }
 };
 
-int RadosClient::init()
+int RadosClient::connect()
 {
   // get monmap
   int ret = monclient.build_initial_monmap();
   if (ret < 0)
     return ret;
 
-  assert_warn(messenger);
+  messenger = new SimpleMessenger();
   if (!messenger)
     return -ENOMEM;
 
@@ -1827,8 +1827,7 @@ int Rados::initialize(int argc, const char *argv[])
   common_set_defaults(false);
   common_init(args, "librados", STARTUP_FLAG_INIT_KEYS);
 
-  client = new RadosClient();
-  return client->init();
+  return 0;
 }
 
 void Rados::shutdown()
@@ -2354,10 +2353,8 @@ void Rados::set_notify_timeout(pool_t pool, uint32_t timeout)
 static Mutex rados_init_mutex("rados_init");
 static int rados_initialized = 0;
 
-extern "C" int rados_init(rados_t *pcluster) 
+extern "C" int rados_create(rados_t *pcluster)
 {
-  int ret = 0;
-
   rados_init_mutex.Lock();
   if (!rados_initialized) {
     // parse environment
@@ -2370,18 +2367,18 @@ extern "C" int rados_init(rados_t *pcluster)
     ++rados_initialized;
   }
   rados_init_mutex.Unlock();
-
   RadosClient *radosp = new RadosClient;
-  ret = radosp->init();
-  if (ret < 0) {
-    delete radosp;
-  } else {
-    *pcluster = (void *)radosp;
-  }
-  return ret;
+  *pcluster = (void *)radosp;
+  return 0;
 }
 
-extern "C" void rados_release(rados_t cluster)
+extern "C" int rados_connect(rados_t cluster)
+{
+  RadosClient *radosp = (RadosClient *)cluster;
+  return radosp->connect();
+}
+
+extern "C" void rados_destroy(rados_t cluster)
 {
   RadosClient *radosp = (RadosClient *)cluster;
   radosp->shutdown();
@@ -2421,9 +2418,8 @@ extern "C" int rados_conf_set(rados_t cluster, const char *option, const char *v
   return g_conf.set_val(option, value);
 }
 
-extern "C" int rados_conf_apply(void)
+extern "C" int rados_reopen_log(void)
 {
-  // Simulate SIGHUP after a configuration change.
   sighup_handler(SIGHUP);
   return 0;
 }
@@ -2433,7 +2429,6 @@ extern "C" int rados_conf_get(rados_t cluster, const char *option, char **buf, i
   return g_conf.get_val(option, buf, len);
 }
 
-
 extern "C" int rados_lookup_pool(rados_t cluster, const char *name)
 {
   RadosClient *radosp = (RadosClient *)cluster;
index 5259b24e3ee848c23a1b836d083ed6553d12d9d6..1e7dfe3850e379aabff39346233da6f03af7703c 100644 (file)
@@ -28,7 +28,10 @@ int main(int argc, const char **argv)
     exit(1);
   }
 
-  rados_conf_parse_argv(cl, argc, argv);
+  if (rados_connect(cl)) {
+    printf("error connecting\n");
+    exit(1);
+  }
 
   /* create a pool */
   r = rados_create_pool("foo");
@@ -128,7 +131,7 @@ int main(int argc, const char **argv)
   printf("rados_delete_pool = %d\n", r);  
   r = rados_close_pool(pool);
 
-  rados_deinitialize();
+  rados_destroy(cl);
 
   return 0;
 }