]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
- send the record header from the client to the daemon when doing a
authorAndrew Tridgell <tridge@samba.org>
Tue, 17 Apr 2007 06:20:32 +0000 (16:20 +1000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 17 Apr 2007 06:20:32 +0000 (16:20 +1000)
  fetch, to avoid the daemon re-reading it

- suffix the database name with the node name so that testing on
  loopback doesn't result in a name collision in the database open

(This used to be ctdb commit ad30a4db75450643ff146c40faa306a021de3dd2)

ctdb/common/ctdb_call.c
ctdb/common/ctdb_client.c
ctdb/common/ctdb_daemon.c
ctdb/common/ctdb_ltdb.c
ctdb/include/ctdb_private.h
ctdb/tests/ctdb_fetch.c

index 8cc97c8269ec63e67e69b9a4c850083f28cfea1f..1969a3704d97cd54f62c8590f25dcdcd024a27e8 100644 (file)
@@ -592,34 +592,17 @@ struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
   This constructs a ctdb_call request and queues it for processing. 
   This call never blocks.
 */
-struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db, 
-                                             struct ctdb_call *call)
+struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db, 
+                                                    struct ctdb_call *call, 
+                                                    struct ctdb_ltdb_header *header)
 {
        uint32_t len;
        struct ctdb_call_state *state;
-       int ret;
-       struct ctdb_ltdb_header header;
-       TDB_DATA data;
        struct ctdb_context *ctdb = ctdb_db->ctdb;
 
-       /*
-         if we are the dmaster for this key then we don't need to
-         send it off at all, we can bypass the network and handle it
-         locally. To find out if we are the dmaster we need to look
-         in our ltdb
-       */
-       ret = ctdb_ltdb_fetch(ctdb_db, call->key, &header, ctdb_db, &data);
-       if (ret != 0) return NULL;
-
-       if (header.dmaster == ctdb->vnn && !(ctdb->flags & CTDB_FLAG_SELF_CONNECT)) {
-               return ctdb_call_local_send(ctdb_db, call, &header, &data);
-       }
-
        state = talloc_zero(ctdb_db, struct ctdb_call_state);
        CTDB_NO_MEMORY_NULL(ctdb, state);
 
-       talloc_steal(state, data.dptr);
-
        len = offsetof(struct ctdb_req_call, data) + call->key.dsize + call->call_data.dsize;
        state->c = ctdb->methods->allocate_pkt(ctdb, len);
        CTDB_NO_MEMORY_NULL(ctdb, state->c);
@@ -630,7 +613,7 @@ struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db,
        state->c->hdr.ctdb_magic = CTDB_MAGIC;
        state->c->hdr.ctdb_version = CTDB_VERSION;
        state->c->hdr.operation = CTDB_REQ_CALL;
-       state->c->hdr.destnode  = header.dmaster;
+       state->c->hdr.destnode  = header->dmaster;
        state->c->hdr.srcnode   = ctdb->vnn;
        /* this limits us to 16k outstanding messages - not unreasonable */
        state->c->hdr.reqid     = idr_get_new(ctdb->idr, state, 0xFFFF);
@@ -646,9 +629,9 @@ struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db,
        state->call.call_data.dptr = &state->c->data[call->key.dsize];
        state->call.key.dptr       = &state->c->data[0];
 
-       state->node   = ctdb->nodes[header.dmaster];
+       state->node   = ctdb->nodes[header->dmaster];
        state->state  = CTDB_CALL_WAIT;
-       state->header = header;
+       state->header = *header;
        state->ctdb_db = ctdb_db;
 
        talloc_set_destructor(state, ctdb_call_destructor);
@@ -660,6 +643,38 @@ struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db,
        return state;
 }
 
+/*
+  make a remote ctdb call - async send. Called in daemon context.
+
+  This constructs a ctdb_call request and queues it for processing. 
+  This call never blocks.
+*/
+struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db, 
+                                             struct ctdb_call *call)
+{
+       int ret;
+       struct ctdb_ltdb_header header;
+       TDB_DATA data;
+       struct ctdb_context *ctdb = ctdb_db->ctdb;
+
+       /*
+         if we are the dmaster for this key then we don't need to
+         send it off at all, we can bypass the network and handle it
+         locally. To find out if we are the dmaster we need to look
+         in our ltdb
+       */
+       ret = ctdb_ltdb_fetch(ctdb_db, call->key, &header, ctdb_db, &data);
+       if (ret != 0) return NULL;
+
+       if (header.dmaster == ctdb->vnn && !(ctdb->flags & CTDB_FLAG_SELF_CONNECT)) {
+               return ctdb_call_local_send(ctdb_db, call, &header, &data);
+       }
+
+       talloc_free(data.dptr);
+
+       return ctdb_daemon_call_send_remote(ctdb_db, call, &header);
+}
+
 
 /*
   make a remote ctdb call - async recv - called in daemon context
index 94dec19d56dbac4d6b78d05794363a1eb1884f12..48c22acf57bee81fd21c8e96a44fd77b1e90bcd1 100644 (file)
@@ -432,7 +432,8 @@ void ctdb_connect_wait(struct ctdb_context *ctdb)
 
 static struct ctdb_fetch_lock_state *ctdb_client_fetch_lock_send(struct ctdb_db_context *ctdb_db, 
                                                                 TALLOC_CTX *mem_ctx, 
-                                                                TDB_DATA key)
+                                                                TDB_DATA key, 
+                                                                struct ctdb_ltdb_header *header)
 {
        struct ctdb_fetch_lock_state *state;
        struct ctdb_context *ctdb = ctdb_db->ctdb;
@@ -468,6 +469,7 @@ static struct ctdb_fetch_lock_state *ctdb_client_fetch_lock_send(struct ctdb_db_
        req->hdr.reqid       = idr_get_new(ctdb->idr, state, 0xFFFF);
        req->db_id           = ctdb_db->db_id;
        req->keylen          = key.dsize;
+       req->header          = *header;
        memcpy(&req->key[0], key.dptr, key.dsize);
        
        res = ctdb_client_queue_pkt(ctdb, &req->hdr);
@@ -572,7 +574,7 @@ struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALL
        }
 
        /* we're not the dmaster - ask the ctdb daemon to make us dmaster */
-       state = ctdb_client_fetch_lock_send(ctdb_db, mem_ctx, key);
+       state = ctdb_client_fetch_lock_send(ctdb_db, mem_ctx, key, &h->header);
        ret = ctdb_client_fetch_lock_recv(state, mem_ctx, key, &h->header, data);
        if (ret != 0) {
                talloc_free(h);
index 67653202af2c2786715b1c6659c52548a304c99d..aa1f12474a10e8f6701ed5dccddf6f616a00d919 100644 (file)
@@ -125,7 +125,8 @@ static void daemon_request_register_message_handler(struct ctdb_client *client,
 
 static struct ctdb_call_state *ctdb_daemon_fetch_lock_send(struct ctdb_db_context *ctdb_db, 
                                                           TALLOC_CTX *mem_ctx, 
-                                                          TDB_DATA key, TDB_DATA *data)
+                                                          TDB_DATA key, struct ctdb_ltdb_header *header,
+                                                          TDB_DATA *data)
 {
        struct ctdb_call *call;
        struct ctdb_record_handle *rec;
@@ -141,13 +142,12 @@ static struct ctdb_call_state *ctdb_daemon_fetch_lock_send(struct ctdb_db_contex
        call->key = key;
        call->flags = CTDB_IMMEDIATE_MIGRATION;
 
-
        rec->ctdb_db = ctdb_db;
        rec->key = key;
        rec->key.dptr = talloc_memdup(rec, key.dptr, key.dsize);
        rec->data = data;
 
-       state = ctdb_daemon_call_send(ctdb_db, call);
+       state = ctdb_daemon_call_send_remote(ctdb_db, call, header);
        state->fetch_private = rec;
 
        return state;
@@ -192,7 +192,7 @@ static void daemon_fetch_lock_complete(struct ctdb_call_state *state)
   called when the daemon gets a fetch lock request from a client
  */
 static void daemon_request_fetch_lock(struct ctdb_client *client, 
-                                       struct ctdb_req_fetch_lock *f)
+                                     struct ctdb_req_fetch_lock *f)
 {
        struct ctdb_call_state *state;
        TDB_DATA key, *data;
@@ -226,7 +226,7 @@ static void daemon_request_fetch_lock(struct ctdb_client *client,
        data->dptr  = NULL;
        data->dsize = 0;
 
-       state = ctdb_daemon_fetch_lock_send(ctdb_db, client, key, data);
+       state = ctdb_daemon_fetch_lock_send(ctdb_db, client, key, &f->header, data);
        talloc_steal(state, data);
 
        fl_data = talloc(state, struct client_fetch_lock_data);
index e2aa47e4cdda7898df64e8aa13caabfdd12ee2a0..a1e45efb0254750680ffd834244316c35214bde1 100644 (file)
@@ -82,6 +82,10 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name,
                }
        }
 
+       /* add the node id to the database name, so when we run on loopback
+          we don't conflict in the local filesystem */
+       name = talloc_asprintf(ctdb_db, "%s.%u", name, ctdb_get_vnn(ctdb));
+
        /* when we have a separate daemon this will need to be a real
           file, not a TDB_INTERNAL, so the parent can access it to
           for ltdb bypass */
index 181200e485c13cc4d0403aa1ed6cf6293efe0bf0..be0fbf85ae0a9acc4a269ff0894c349dd6d1bb62 100644 (file)
@@ -306,6 +306,7 @@ struct ctdb_reply_connect_wait {
 
 struct ctdb_req_fetch_lock {
        struct ctdb_req_header hdr;
+       struct ctdb_ltdb_header header;
        uint32_t db_id;
        uint32_t keylen;
        uint8_t key[1]; /* key[] */
@@ -439,4 +440,8 @@ struct ctdb_call_state *ctdb_daemon_call_send(struct ctdb_db_context *ctdb_db,
 
 int ctdb_daemon_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
 
+struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db, 
+                                                    struct ctdb_call *call, 
+                                                    struct ctdb_ltdb_header *header);
+
 #endif
index 35ab9892994cf8fb5ac2cab4c2b66d4bc7c6b923..1ae8e8aafda1a1d9d5be963d86d55dee1cb40fe8 100644 (file)
@@ -94,8 +94,6 @@ static void bench_fetch_1node(struct ctdb_context *ctdb)
                printf("Failed to store record\n");
        }
 
-       printf("DATA IS NOW:%s\n", (const char *)data.dptr);
-
        talloc_free(tmp_ctx);
 
        /* tell the next node to do the same */