1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-19 18:50:24 +03:00

add some tests in the daemon that a REQ_CALL that a client sent us has valid srcnode and destnode

update ctdbd_test.c to show how to force a migration onto the local node

(This used to be ctdb commit fe313cee4927075be311e28ea106bd5cc035f217)
This commit is contained in:
Ronnie sahlberg 2007-04-19 12:33:13 +10:00
parent 9f0c8b566c
commit 63e513aeeb
2 changed files with 29 additions and 15 deletions

View File

@ -306,6 +306,18 @@ static void daemon_request_call_from_client(struct ctdb_client *client,
struct daemon_call_state *dstate;
struct ctdb_call *call;
/* check that the client filled in the correct vnn for the local node */
if (ctdb_get_vnn(client->ctdb) != c->hdr.srcnode) {
DEBUG(0, (__location__ "Wrong srcnode in CTDB_REQ_CALL from client was:%d should be :%d\n", c->hdr.srcnode, ctdb_get_vnn(client->ctdb)));
return;
}
/* verify that the destnode makes sense */
if (c->hdr.destnode >= client->ctdb->num_nodes) {
DEBUG(0, (__location__ "Wrong dstnode in CTDB_REQ_CALL from client was:%d but there are only %d nodes in the cluster\n", c->hdr.destnode, client->ctdb->num_nodes));
return;
}
ctdb_db = find_ctdb_db(client->ctdb, c->db_id);
if (!ctdb_db) {
DEBUG(0, (__location__ " Unknown database in request. db_id==0x%08x",

View File

@ -186,26 +186,32 @@ uint32_t ctdb_hash(const TDB_DATA *key)
/* ask the daemon to migrate a record over so that the local node is the dmaster the client must not have the record locked when performing this call.
see ctdb_client.c/ctdb_fetch_lock() for the full procedure
when the daemon has responded this node should be the dmaster (unless it has migrated off again)
*/
void fetch_lock(int fd, uint32_t db_id, TDB_DATA key)
void fetch_record(int fd, uint32_t db_id, TDB_DATA key, int thisnode, int destnode)
{
struct ctdb_req_fetch_lock *req;
struct ctdb_reply_fetch_lock *rep;
struct ctdb_req_call *req;
struct ctdb_reply_call *rep;
uint32_t length;
int len, cnt, tot;
len = offsetof(struct ctdb_req_fetch_lock, key) + key.dsize;
len = offsetof(struct ctdb_req_call, data) + key.dsize;
req = malloc(len);
req->hdr.length = len;
req->hdr.ctdb_magic = CTDB_MAGIC;
req->hdr.ctdb_version = CTDB_VERSION;
req->hdr.operation = CTDB_REQ_FETCH_LOCK;
req->hdr.operation = CTDB_REQ_CALL;
req->hdr.destnode = destnode;
req->hdr.srcnode = thisnode;
req->hdr.reqid = 1;
req->flags = CTDB_IMMEDIATE_MIGRATION;
req->db_id = db_id;
req->callid = CTDB_NULL_FUNC;
req->keylen = key.dsize;
memcpy(&req->key[0], key.dptr, key.dsize);
req->calldatalen = 0;
memcpy(&req->data[0], key.dptr, key.dsize);
cnt=write(fd, req, len);
@ -231,7 +237,7 @@ void fetch_lock(int fd, uint32_t db_id, TDB_DATA key)
cnt+=numread;
}
}
printf("fetch lock reply: state:%d\n",rep->state);
printf("fetch record reply: operation:%d state:%d\n",rep->hdr.operation,rep->status);
}
int main(int argc, const char *argv[])
@ -287,17 +293,13 @@ int main(int argc, const char *argv[])
printf("the has for the database id is 0x%08x\n",db_id);
printf("\n");
/* send a fetch lock */
/* send a request to migrate a record to the local node */
key.dptr=discard_const("TestKey");
key.dsize=strlen((const char *)(key.dptr));
printf("fetch the test key:[%s]\n",key.dptr);
fetch_lock(fd, db_id, key);
printf("\n");
/* send a fetch lock */
printf("fetch the test key:[%s]\n",key.dptr);
fetch_lock(fd, db_id, key);
/* say that we are vnn:55 and we want to send to vnn:57 */
fetch_record(fd, db_id, key, 0, 1);
printf("\n");