FILE *f = (FILE *)p;
struct ctdb_ltdb_header *h = (struct ctdb_ltdb_header *)data.dptr;
- fprintf(f, "dmaster: %u\n", h->dmaster);
- fprintf(f, "rsn: %llu\n", (unsigned long long)h->rsn);
-
fprintf(f, "key(%u) = \"", (unsigned)key.dsize);
for (i=0;i<key.dsize;i++) {
if (ISASCII(key.dptr[i])) {
}
fprintf(f, "\"\n");
+ fprintf(f, "dmaster: %u\n", h->dmaster);
+ fprintf(f, "rsn: %llu\n", (unsigned long long)h->rsn);
+
fprintf(f, "data(%u) = \"", (unsigned)data.dsize);
for (i=sizeof(*h);i<data.dsize;i++) {
if (ISASCII(data.dptr[i])) {
}
fprintf(f, "\"\n");
+ fprintf(f, "\n");
+
return 0;
}
/**
* check whether a transaction is active on a given db on a given node
*/
-static int32_t ctdb_ctrl_transaction_active(struct ctdb_context *ctdb,
- uint32_t destnode,
- uint32_t db_id)
+int32_t ctdb_ctrl_transaction_active(struct ctdb_context *ctdb,
+ uint32_t destnode,
+ uint32_t db_id)
{
int32_t status;
int ret;
}
again:
+ tmp_ctx = talloc_new(h);
+
+ rh = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, NULL);
+ if (rh == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to fetch_lock database\n"));
+ talloc_free(tmp_ctx);
+ return -1;
+ }
+
status = ctdb_ctrl_transaction_active(ctdb_db->ctdb,
CTDB_CURRENT_NODE,
ctdb_db->db_id);
if (status == 1) {
+ unsigned long int usec = (1000 + random()) % 100000;
DEBUG(DEBUG_NOTICE, (__location__ " transaction is active "
- "on db_id[%u]. waiting for 1 second\n",
- ctdb_db->db_id));
- sleep(1);
+ "on db_id[0x%08x]. waiting for %lu "
+ "microseconds\n",
+ ctdb_db->db_id, usec));
+ talloc_free(tmp_ctx);
+ usleep(usec);
goto again;
}
- tmp_ctx = talloc_new(h);
-
- rh = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, NULL);
- if (rh == NULL) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to fetch_lock database\n"));
- talloc_free(tmp_ctx);
- return -1;
- }
/*
* store the pid in the database:
* it is not enough that the node is dmaster...
&timeout, NULL);
if (ret != 0 || status != 0) {
tdb_transaction_cancel(h->ctdb_db->ltdb->tdb);
+ DEBUG(DEBUG_WARNING, (__location__ " transaction commit%s failed"
+ ", retrying after 1 second...\n",
+ (retries==0)?"":"retry "));
sleep(1);
if (ret != 0) {