This tracking database is lockless, using TDB_NOLOCK, and is only ever accessed by the main ctdbd daemon.
The lockless nature and the fact that no other process ever access this TDB means we are guranteed non-blocking access to records in the trcking database.
-The ctdb_call PDU is allocated with two new flags WANT_READONLY and WITH_HEADER.
+The ctdb_call PDU is allocated with a new flags WANT_READONLY and possibly also a new callid: CTDB_FETCH_WITH_HEADER_FUNC.
+This new function returns not only the record, as CTDB_FETCH_FUNC does, but also returns the HEADER prepended to the record.
+This function is optional, clients that do not care what the header is can continue using just CTDB_FETCH_FUNC
+
This first flag is used to explicitely requesting a read-only record from the DMASTER/LMASTER.
The second flag is used to request that the fetch operation will return not only the data for the record but also
the record header.
goto finished
else
unlock record
- ask ctdb for read-only copy (WANT_READONLY|WITH_HEADER)
+ ask ctdb for read-only copy (WANT_READONLY[|WITH_HEADER])
if failed to get read-only copy (*A)
ask ctdb to migrate the record onto the node
goto try_again
struct ctdb_reply_call *reply;
TDB_DATA data;
- /* OK, we've received reply to fetch-with-header migration */
- reply = unpack_reply_call(req, CTDB_FETCH_WITH_HEADER_FUNC);
+ /* OK, we've received reply to fetch migration */
+ reply = unpack_reply_call(req, CTDB_FETCH_FUNC);
if (!reply || reply->status != 0) {
if (reply) {
DEBUG(ctdb, LOG_ERR,
"ctdb_readrecordlock_async(async):"
- " FETCH_WITH_HEADER_FUNC returned %i", reply->status);
+ " FETCH returned %i", reply->status);
}
lock->callback(lock->ctdb_db, NULL, tdb_null, private);
ctdb_request_free(req); /* Also frees lock. */
req->hdr.call->flags = CTDB_IMMEDIATE_MIGRATION;
}
req->hdr.call->db_id = ctdb_db->id;
- req->hdr.call->callid = CTDB_FETCH_WITH_HEADER_FUNC;
+ req->hdr.call->callid = CTDB_FETCH_FUNC;
req->hdr.call->hopcount = 0;
req->hdr.call->keylen = key.dsize;
req->hdr.call->calldatalen = 0;
uint32_t reqid;
struct ctdb_call *call;
struct timeval start_time;
+
+ /* readonly request ? */
+ uint32_t readonly_fetch;
+ uint32_t client_callid;
};
/*
}
length = offsetof(struct ctdb_reply_call, data) + dstate->call->reply_data.dsize;
+ /* If the client asked for readonly FETCH, we remapped this to
+ FETCH_WITH_HEADER when calling the daemon. So we must
+ strip the extra header off the reply data before passing
+ it back to the client.
+ */
+ if (dstate->readonly_fetch
+ && dstate->client_callid == CTDB_FETCH_FUNC) {
+ length -= sizeof(struct ctdb_ltdb_header);
+ }
+
r = ctdbd_allocate_pkt(client->ctdb, dstate, CTDB_REPLY_CALL,
length, struct ctdb_reply_call);
if (r == NULL) {
return;
}
r->hdr.reqid = dstate->reqid;
- r->datalen = dstate->call->reply_data.dsize;
r->status = dstate->call->status;
- memcpy(&r->data[0], dstate->call->reply_data.dptr, r->datalen);
+
+ if (dstate->readonly_fetch
+ && dstate->client_callid == CTDB_FETCH_FUNC) {
+ /* client only asked for a FETCH so we must strip off
+ the extra ctdb_ltdb header
+ */
+ r->datalen = dstate->call->reply_data.dsize - sizeof(struct ctdb_ltdb_header);
+ memcpy(&r->data[0], dstate->call->reply_data.dptr + sizeof(struct ctdb_ltdb_header), r->datalen);
+ } else {
+ r->datalen = dstate->call->reply_data.dsize;
+ memcpy(&r->data[0], dstate->call->reply_data.dptr, r->datalen);
+ }
res = daemon_queue_send(client, &r->hdr);
if (res == -1) {
return;
}
+ dstate->readonly_fetch = 0;
call->call_id = c->callid;
call->key = key;
call->call_data.dptr = c->data + c->keylen;
call->call_data.dsize = c->calldatalen;
call->flags = c->flags;
+ if (c->flags & CTDB_WANT_READONLY) {
+ /* client wants readonly record, so translate this into a
+ fetch with header. remember what the client asked for
+ so we can remap the reply back to the proper format for
+ the client in the reply
+ */
+ dstate->client_callid = call->call_id;
+ call->call_id = CTDB_FETCH_WITH_HEADER_FUNC;
+ dstate->readonly_fetch = 1;
+ }
+
if (header.dmaster == ctdb->pnn) {
state = ctdb_call_local_send(ctdb_db, call, &header, &data);
} else {