------------------------------------------------------------ revno: 104 revision-id: [EMAIL PROTECTED] parent: [EMAIL PROTECTED] parent: [EMAIL PROTECTED] committer: Andrew Tridgell <[EMAIL PROTECTED]> branch nick: tridge timestamp: Sat 2007-04-14 20:44:43 +1000 message: merge from ronnie modified: common/ctdb_client.c ctdb_client.c-20070411010216-3kd8v37k61steeya-1 common/ctdb_daemon.c ctdb_daemon.c-20070409200331-3el1kqgdb9m4ib0g-1 tests/ctdb_fetch1.c ctdb_fetch1.c-20070412111848-xawz6wqk9r0v8jdk-1 ------------------------------------------------------------ merged: [EMAIL PROTECTED] parent: [EMAIL PROTECTED] committer: Ronnie sahlberg <[EMAIL PROTECTED]> branch nick: ctdb timestamp: Fri 2007-04-13 20:37:41 +1000 message: add missing code to store_unlock so that the data that a client writes is stored in ltdb this makes it possible to do fetch_lock and store_unlock across a domain socket to read/write data. note that the actual locking is NOT implemented yet === modified file 'common/ctdb_client.c' --- a/common/ctdb_client.c 2007-04-13 10:38:24 +0000 +++ b/common/ctdb_client.c 2007-04-14 10:44:43 +0000 @@ -586,7 +586,7 @@ This is called when the program wants to wait for a ctdb_fetch_lock to complete and get the results. This call will block unless the call has already completed. */ -struct ctdb_record_handle *ctdb_client_fetch_lock_recv(struct ctdb_call_state *state, TALLOC_CTX *mem_ctx, TDB_DATA key) +struct ctdb_record_handle *ctdb_client_fetch_lock_recv(struct ctdb_call_state *state, TALLOC_CTX *mem_ctx, TDB_DATA key, TDB_DATA *data) { struct ctdb_record_handle *rec; @@ -609,6 +609,9 @@ rec->data->dsize = state->call.reply_data.dsize; rec->data->dptr = talloc_memdup(rec, state->call.reply_data.dptr, rec->data->dsize); + if (data) { + *data = *rec->data; + } return rec; } @@ -633,13 +636,14 @@ struct ctdb_record_handle *ctdb_client_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, - TDB_DATA key, TDB_DATA *data) + TDB_DATA key, + TDB_DATA *data) { struct ctdb_call_state *state; struct ctdb_record_handle *rec; state = ctdb_client_fetch_lock_send(ctdb_db, mem_ctx, key); - rec = ctdb_client_fetch_lock_recv(state, mem_ctx, key); + rec = ctdb_client_fetch_lock_recv(state, mem_ctx, key, data); return rec; }
=== modified file 'common/ctdb_daemon.c' --- a/common/ctdb_daemon.c 2007-04-13 10:38:24 +0000 +++ b/common/ctdb_daemon.c 2007-04-14 10:44:43 +0000 @@ -214,12 +214,36 @@ { struct ctdb_db_context *ctdb_db; struct ctdb_reply_store_unlock r; + uint32_t caller = ctdb_get_vnn(client->ctdb); + struct ctdb_ltdb_header header; + TDB_DATA key, data; int res; ctdb_db = find_ctdb_db(client->ctdb, f->db_id); + /* write the data to ltdb */ -/*XXX*/ - + key.dsize = f->keylen; + key.dptr = &f->data[0]; + res = ctdb_ltdb_fetch(ctdb_db, key, &header, NULL, NULL); + if (res) { + ctdb_set_error(ctdb_db->ctdb, "Fetch of locally held record failed"); + res = -1; + goto done; + } + if (header.laccessor != caller) { + header.lacount = 0; + } + header.laccessor = caller; + header.lacount++; + data.dsize = f->datalen; + data.dptr = &f->data[f->keylen]; + res = ctdb_ltdb_store(ctdb_db, key, &header, data); + if ( res != 0) { + ctdb_set_error(ctdb_db->ctdb, "ctdb_call tdb_store failed\n"); + } + + +done: /* now send the reply */ ZERO_STRUCT(r); @@ -228,7 +252,7 @@ r.hdr.ctdb_version = CTDB_VERSION; r.hdr.operation = CTDB_REPLY_STORE_UNLOCK; r.hdr.reqid = f->hdr.reqid; - r.state = CTDB_CALL_DONE; + r.state = res; res = ctdb_queue_send(client->queue, (uint8_t *)&r.hdr, r.hdr.length); if (res != 0) { === modified file 'tests/ctdb_fetch1.c' --- a/tests/ctdb_fetch1.c 2007-04-13 10:38:24 +0000 +++ b/tests/ctdb_fetch1.c 2007-04-14 10:44:43 +0000 @@ -42,7 +42,7 @@ const char *myaddress = NULL; int self_connect=0; int daemon_mode=0; - TDB_DATA key, *data, *data2, store_data; + TDB_DATA key, data, data2, store_data; struct ctdb_record_handle *rh; struct poptOption popt_options[] = { @@ -137,26 +137,29 @@ ctdb_connect_wait(ctdb); key.dptr = "Record"; - key.dsize = strlen(key.dptr); - data = NULL; - rh = ctdb_fetch_lock(ctdb_db, ctdb_db, key, data); + key.dsize = strlen(key.dptr)+1; + rh = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data); store_data.dptr = "data to store"; store_data.dsize = strlen(store_data.dptr)+1; ret = ctdb_store_unlock(rh, store_data); - printf("ctdb_store_unlock ret:%d\n",ret); - - data2 = NULL; - rh = ctdb_fetch_lock(ctdb_db, ctdb_db, key, data2); -/* hopefully data2 will now contain the record written above */ - + + rh = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data2); + /* hopefully data2 will now contain the record written above */ + if (!strcmp("data to store", data2.dptr)) { + printf("woohoo we read back the data we stored\n"); + } else { + printf("ERROR: we read back different data than we stored\n"); + } + /* just write it back to unlock it */ - ret = ctdb_store_unlock(rh, data2); - printf("ctdb_store_unlock ret:%d\n",ret); + ret = ctdb_store_unlock(rh, store_data); +#if 0 while (1) { event_loop_once(ev); } +#endif /* shut it down */ talloc_free(ctdb);