return 0;
}
-/*
- a traverse function for pulling all relevent records from pulldb
- */
-struct pulldb_data {
- struct ctdb_context *ctdb;
- struct ctdb_db_context *ctdb_db;
- struct ctdb_marshall_buffer *pulldata;
- uint32_t len;
- uint32_t allocated_len;
- bool failed;
-};
-
-static int traverse_pulldb(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *p)
-{
- struct pulldb_data *params = (struct pulldb_data *)p;
- struct ctdb_rec_data_old *rec;
- struct ctdb_context *ctdb = params->ctdb;
- struct ctdb_db_context *ctdb_db = params->ctdb_db;
-
- /* add the record to the blob */
- rec = ctdb_marshall_record(params->pulldata, 0, key, NULL, data);
- if (rec == NULL) {
- params->failed = true;
- return -1;
- }
- if (params->len + rec->length >= params->allocated_len) {
- params->allocated_len = rec->length + params->len + ctdb->tunable.pulldb_preallocation_size;
- params->pulldata = talloc_realloc_size(NULL, params->pulldata, params->allocated_len);
- }
- if (params->pulldata == NULL) {
- DEBUG(DEBUG_CRIT,(__location__ " Failed to expand pulldb_data to %u\n", rec->length + params->len));
- ctdb_fatal(params->ctdb, "failed to allocate memory for recovery. shutting down\n");
- }
- params->pulldata->count++;
- memcpy(params->len+(uint8_t *)params->pulldata, rec, rec->length);
- params->len += rec->length;
-
- if (ctdb->tunable.db_record_size_warn != 0 && rec->length > ctdb->tunable.db_record_size_warn) {
- DEBUG(DEBUG_ERR,("Data record in %s is big. Record size is %d bytes\n", ctdb_db->db_name, (int)rec->length));
- }
-
- talloc_free(rec);
-
- return 0;
-}
-
-/*
- pull a bunch of records from a ltdb, filtering by lmaster
- */
-int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DATA *outdata)
-{
- struct ctdb_pulldb *pull;
- struct ctdb_db_context *ctdb_db;
- struct pulldb_data params;
- struct ctdb_marshall_buffer *reply;
-
- pull = (struct ctdb_pulldb *)indata.dptr;
-
- ctdb_db = find_ctdb_db(ctdb, pull->db_id);
- if (!ctdb_db) {
- DEBUG(DEBUG_ERR,(__location__ " Unknown db 0x%08x\n", pull->db_id));
- return -1;
- }
-
- if (!ctdb_db_frozen(ctdb_db)) {
- DEBUG(DEBUG_ERR,
- ("rejecting ctdb_control_pull_db when not frozen\n"));
- return -1;
- }
-
- reply = talloc_zero(outdata, struct ctdb_marshall_buffer);
- CTDB_NO_MEMORY(ctdb, reply);
-
- reply->db_id = pull->db_id;
-
- params.ctdb = ctdb;
- params.ctdb_db = ctdb_db;
- params.pulldata = reply;
- params.len = offsetof(struct ctdb_marshall_buffer, data);
- params.allocated_len = params.len;
- params.failed = false;
-
- if (ctdb_db->unhealthy_reason) {
- /* this is just a warning, as the tdb should be empty anyway */
- DEBUG(DEBUG_WARNING,("db(%s) unhealty in ctdb_control_pull_db: %s\n",
- ctdb_db->db_name, ctdb_db->unhealthy_reason));
- }
-
- /* If the records are invalid, we are done */
- if (ctdb_db->invalid_records) {
- goto done;
- }
-
- if (ctdb_lockdb_mark(ctdb_db) != 0) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to get lock on entire db - failing\n"));
- return -1;
- }
-
- if (tdb_traverse_read(ctdb_db->ltdb->tdb, traverse_pulldb, ¶ms) == -1) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to get traverse db '%s'\n", ctdb_db->db_name));
- ctdb_lockdb_unmark(ctdb_db);
- talloc_free(params.pulldata);
- return -1;
- }
-
- ctdb_lockdb_unmark(ctdb_db);
-
-done:
- outdata->dptr = (uint8_t *)params.pulldata;
- outdata->dsize = params.len;
-
- if (ctdb->tunable.db_record_count_warn != 0 && params.pulldata->count > ctdb->tunable.db_record_count_warn) {
- DEBUG(DEBUG_ERR,("Database %s is big. Contains %d records\n", ctdb_db->db_name, params.pulldata->count));
- }
- if (ctdb->tunable.db_size_warn != 0 && outdata->dsize > ctdb->tunable.db_size_warn) {
- DEBUG(DEBUG_ERR,("Database %s is big. Contains %d bytes\n", ctdb_db->db_name, (int)outdata->dsize));
- }
-
-
- return 0;
-}
-
struct db_pull_state {
struct ctdb_context *ctdb;
struct ctdb_db_context *ctdb_db;
return 0;
}
-/*
- push a bunch of records into a ltdb, filtering by rsn
- */
-int32_t ctdb_control_push_db(struct ctdb_context *ctdb, TDB_DATA indata)
-{
- struct ctdb_marshall_buffer *reply = (struct ctdb_marshall_buffer *)indata.dptr;
- struct ctdb_db_context *ctdb_db;
- unsigned int i;
- int ret;
- struct ctdb_rec_data_old *rec;
-
- if (indata.dsize < offsetof(struct ctdb_marshall_buffer, data)) {
- DEBUG(DEBUG_ERR,(__location__ " invalid data in pulldb reply\n"));
- return -1;
- }
-
- ctdb_db = find_ctdb_db(ctdb, reply->db_id);
- if (!ctdb_db) {
- DEBUG(DEBUG_ERR,(__location__ " Unknown db 0x%08x\n", reply->db_id));
- return -1;
- }
-
- if (!ctdb_db_frozen(ctdb_db)) {
- DEBUG(DEBUG_ERR,
- ("rejecting ctdb_control_push_db when not frozen\n"));
- return -1;
- }
-
- if (ctdb_lockdb_mark(ctdb_db) != 0) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to get lock on entire db - failing\n"));
- return -1;
- }
-
- rec = (struct ctdb_rec_data_old *)&reply->data[0];
-
- DEBUG(DEBUG_INFO,("starting push of %u records for dbid 0x%x\n",
- reply->count, reply->db_id));
-
- for (i=0;i<reply->count;i++) {
- TDB_DATA key, data;
- struct ctdb_ltdb_header *hdr;
-
- key.dptr = &rec->data[0];
- key.dsize = rec->keylen;
- data.dptr = &rec->data[key.dsize];
- data.dsize = rec->datalen;
-
- if (data.dsize < sizeof(struct ctdb_ltdb_header)) {
- DEBUG(DEBUG_CRIT,(__location__ " bad ltdb record\n"));
- goto failed;
- }
- hdr = (struct ctdb_ltdb_header *)data.dptr;
- /* strip off any read only record flags. All readonly records
- are revoked implicitely by a recovery
- */
- hdr->flags &= ~CTDB_REC_RO_FLAGS;
-
- data.dptr += sizeof(*hdr);
- data.dsize -= sizeof(*hdr);
-
- ret = ctdb_ltdb_store(ctdb_db, key, hdr, data);
- if (ret != 0) {
- DEBUG(DEBUG_CRIT, (__location__ " Unable to store record\n"));
- goto failed;
- }
-
- rec = (struct ctdb_rec_data_old *)(rec->length + (uint8_t *)rec);
- }
-
- DEBUG(DEBUG_DEBUG,("finished push of %u records for dbid 0x%x\n",
- reply->count, reply->db_id));
-
- if (ctdb_db_readonly(ctdb_db)) {
- DEBUG(DEBUG_CRIT,("Clearing the tracking database for dbid 0x%x\n",
- ctdb_db->db_id));
- if (tdb_wipe_all(ctdb_db->rottdb) != 0) {
- DEBUG(DEBUG_ERR,("Failed to wipe tracking database for 0x%x. Dropping read-only delegation support\n", ctdb_db->db_id));
- tdb_close(ctdb_db->rottdb);
- ctdb_db->rottdb = NULL;
- ctdb_db_reset_readonly(ctdb_db);
- }
- while (ctdb_db->revokechild_active != NULL) {
- talloc_free(ctdb_db->revokechild_active);
- }
- }
-
- ctdb_lockdb_unmark(ctdb_db);
- return 0;
-
-failed:
- ctdb_lockdb_unmark(ctdb_db);
- return -1;
-}
-
struct db_push_state {
struct ctdb_context *ctdb;
struct ctdb_db_context *ctdb_db;