ReadOnly: Add "readonly" flag to the ctdb_db_context to indicate if this database...
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 20 Jul 2011 03:15:48 +0000 (13:15 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 23 Aug 2011 00:24:26 +0000 (10:24 +1000)
Assume all databases will support readonly mode for now and se thte flag for all databases. At later stage we will add support to control on a per database level whether delegations will be supported or not.

include/ctdb_private.h
server/ctdb_ltdb_server.c

index 833cdc95d3f4fececad961b1f3b923c589659214..d0f0dc4972f44f01924cead559eb945444537e6a 100644 (file)
@@ -502,9 +502,11 @@ struct ctdb_db_context {
        uint32_t db_id;
        uint32_t priority;
        bool persistent;
+       bool readonly; /* Do we support read-only delegations ? */
        const char *db_name;
        const char *db_path;
        struct tdb_wrap *ltdb;
+       struct tdb_context *rottdb; /* ReadOnly tracking TDB */
        struct ctdb_registered_call *calls; /* list of registered calls */
        uint32_t seqnum;
        struct timed_event *seqnum_update;
index f04b7de4a3aa352f838e198b430f38f032716ccd..82ed0f2b7c087328be6bf48eb0fe6b94da70e38f 100644 (file)
@@ -926,6 +926,33 @@ again:
                }
        }
 
+       /* Assume all non-persistent databases support read only delegations */
+       if (!ctdb_db->persistent) {
+               ctdb_db->readonly = true;
+       }
+
+       if (ctdb_db->readonly) {
+               char *ropath;
+
+               ropath = talloc_asprintf(ctdb_db, "%s.RO", ctdb_db->db_path);
+               if (ropath == NULL) {
+                       DEBUG(DEBUG_CRIT,("Failed to asprintf the tracking database\n"));
+                       talloc_free(ctdb_db);
+                       return -1;
+               }
+               ctdb_db->rottdb = tdb_open(ropath, 
+                                     ctdb->tunable.database_hash_size, 
+                                     TDB_NOLOCK|TDB_CLEAR_IF_FIRST|TDB_NOSYNC,
+                                     O_CREAT|O_RDWR, 0);
+               if (ctdb_db->rottdb == NULL) {
+                       DEBUG(DEBUG_CRIT,("Failed to open/create the tracking database '%s'\n", ropath));
+                       talloc_free(ctdb_db);
+                       return -1;
+               }
+               DEBUG(DEBUG_NOTICE,("OPENED tracking database : '%s'\n", ropath));
+       }
+
+
        DLIST_ADD(ctdb->db_list, ctdb_db);
 
        /* setting this can help some high churn databases */