/* Just try locking/unlocking a single record once */ static void fetch_lock_once(struct ctdb_context *ctdb, struct event_context *ev) { TALLOC_CTX *tmp_ctx = talloc_new(ctdb); TDB_DATA key, data; struct ctdb_record_handle *h; static time_t t = 0, t2; key.dptr = discard_const(TESTKEY); key.dsize = strlen(TESTKEY); // printf("Trying to fetch lock the record ...\n"); h = ctdb_fetch_readonly_lock(ctdb_db, tmp_ctx, key, &data, true); if (h == NULL) { printf("Failed to fetch record '%s' on node %d\n", (const char *)key.dptr, ctdb_get_pnn(ctdb)); talloc_free(tmp_ctx); exit(10); } count++; t2 = time(NULL); if (t != 0 && t != t2) { static int last_count = 0; printf("count : %d\n", count - last_count); last_count = count; } t = t2; talloc_free(tmp_ctx); }
/* Just try locking/unlocking a single record once */ static void fetch_lock_once(struct ctdb_context *ctdb, struct event_context *ev, uint32_t generation) { TALLOC_CTX *tmp_ctx = talloc_new(ctdb); TDB_DATA key, data; struct ctdb_record_handle *h; struct ctdb_ltdb_header *header; int ret; key.dptr = discard_const(TESTKEY); key.dsize = strlen(TESTKEY); printf("Trying to fetch lock the record ...\n"); h = ctdb_fetch_readonly_lock(ctdb_db, tmp_ctx, key, &data, false); if (h == NULL) { printf("Failed to fetch record '%s' on node %d\n", (const char *)key.dptr, ctdb_get_pnn(ctdb)); talloc_free(tmp_ctx); exit(10); } printf("Record fetchlocked.\n"); header = talloc_memdup(tmp_ctx, ctdb_header_from_record_handle(h), sizeof(*header)); printf("RSN:%d\n", (int)header->rsn); talloc_free(h); printf("Record released.\n"); printf("Write new record with RSN+10\n"); header->rsn += 10; data.dptr = (void *)talloc_asprintf(tmp_ctx, "%d", (int)header->rsn); data.dsize = strlen((char *)data.dptr); ret = ctdb_ctrl_updaterecord(ctdb, ctdb, timeval_zero(), CTDB_CURRENT_NODE, ctdb_db, key, header, data); if (ret != 0) { printf("Failed to writerecord, ret==%d\n", ret); exit(1); } printf("re-fetch the record\n"); h = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data); if (h == NULL) { printf("Failed to fetch record '%s' on node %d\n", (const char *)key.dptr, ctdb_get_pnn(ctdb)); talloc_free(tmp_ctx); exit(10); } printf("Record fetchlocked.\n"); header = talloc_memdup(tmp_ctx, ctdb_header_from_record_handle(h), sizeof(*header)); printf("RSN:%d\n", (int)header->rsn); talloc_free(h); printf("Record released.\n"); talloc_free(tmp_ctx); }
/* Just try locking/unlocking a single record once */ static void fetch_readonly_once(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db, TDB_DATA key) { TDB_DATA data; struct ctdb_record_handle *h; printf("Trying to readonly fetch lock the record ...\n"); h = ctdb_fetch_readonly_lock(ctdb_db, ctdb, key, &data, 1); if (h == NULL) { fprintf(stderr, "Failed to get readonly lock\n"); exit(1); } talloc_free(h); printf("Record released.\n"); }