READONLY: when updating a remote node to revoke a delegation, make sure
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 1 Mar 2012 22:43:39 +0000 (09:43 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 1 Mar 2012 22:43:39 +0000 (09:43 +1100)
we dont create thje record if it doesnt exist

server/ctdb_call.c
server/ctdb_persistent.c

index a9e418e259b5a97ba6322582d23feabda7d66c42..2657f8b6f5c777a0221849a6a19758afeb685673 100644 (file)
@@ -1296,6 +1296,7 @@ int ctdb_start_revoke_ro_record(struct ctdb_context *ctdb, struct ctdb_db_contex
        int ret;
 
        header->flags &= ~(CTDB_REC_RO_REVOKING_READONLY|CTDB_REC_RO_HAVE_DELEGATIONS|CTDB_REC_RO_HAVE_READONLY);
+       header->flags |= CTDB_REC_FLAG_MIGRATED_WITH_DATA;
        header->rsn   -= 1;
 
        if ((rc = talloc_zero(ctdb_db, struct revokechild_handle)) == NULL) {
index b95f456ecf52ce24c58193dabef9a85f6b71bbf8..669021a7270bdf7083276b13f7d26163068570d8 100644 (file)
@@ -436,8 +436,11 @@ struct ctdb_persistent_write_state {
        struct ctdb_db_context *ctdb_db;
        struct ctdb_marshall_buffer *m;
        struct ctdb_req_control *c;
+       uint32_t flags;
 };
 
+/* dont create/update records that does not exist locally */
+#define UPDATE_FLAGS_REPLACE_ONLY      1
 
 /*
   called from a child process to write the data
@@ -470,6 +473,19 @@ static int ctdb_persistent_store(struct ctdb_persistent_write_state *state)
                        goto failed;                    
                }
 
+               /* we must check if the record exists or not because
+                  ctdb_ltdb_fetch will unconditionally create a record
+                */
+               if (state->flags & UPDATE_FLAGS_REPLACE_ONLY) {
+                       TDB_DATA rec;
+                       rec = tdb_fetch(state->ctdb_db->ltdb->tdb, key);
+                       if (rec.dsize == 0) {
+                               talloc_free(tmp_ctx);
+                               continue;
+                       }
+                       free(rec.dptr);
+               }
+
                /* fetch the old header and ensure the rsn is less than the new rsn */
                ret = ctdb_ltdb_fetch(state->ctdb_db, key, &oldheader, tmp_ctx, &olddata);
                if (ret != 0) {
@@ -716,6 +732,7 @@ int32_t ctdb_control_update_record(struct ctdb_context *ctdb,
        state->ctdb_db = ctdb_db;
        state->c       = c;
        state->m       = m;
+       state->flags   = UPDATE_FLAGS_REPLACE_ONLY;
 
        /* create a child process to take out a transaction and 
           write the data.