RECOVER: When we pull databases during recovery, we used to reallocate the databuffer...
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 25 May 2012 02:27:59 +0000 (12:27 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 25 May 2012 02:34:06 +0000 (12:34 +1000)
Change this to instead preallocate , by default, 10MByte chunks to the data buffer.
This significantly reduces the number of potential reallocate and move  operations that may be required.

Create a tunable to override/change how much preallocation should be used.

(This used to be ctdb commit 1f262deaad0818f159f9c68330f7fec121679023)

ctdb/include/ctdb_private.h
ctdb/server/ctdb_recover.c
ctdb/server/ctdb_recoverd.c
ctdb/server/ctdb_tunables.c

index 0f494b4b2b0f1d196f9a2ea91cf893b1c7b23f17..7c3fdf0953b98c3adce9b7792207fdc5c5450002 100644 (file)
@@ -134,6 +134,7 @@ struct ctdb_tunable {
        uint32_t db_record_count_warn;
        uint32_t db_record_size_warn;
        uint32_t db_size_warn;
+       uint32_t pulldb_preallocation_size;
 };
 
 /*
index 05f72f90dbbfce1f69c1870627979f78c583e039..e54312f57496b253f84a92ea2cf120be50eb9fa1 100644 (file)
@@ -348,6 +348,7 @@ struct pulldb_data {
        struct ctdb_db_context *ctdb_db;
        struct ctdb_marshall_buffer *pulldata;
        uint32_t len;
+       uint32_t allocated_len;
        bool failed;
 };
 
@@ -364,7 +365,10 @@ static int traverse_pulldb(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
                params->failed = true;
                return -1;
        }
-       params->pulldata = talloc_realloc_size(NULL, params->pulldata, rec->length + params->len);
+       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");
@@ -414,6 +418,7 @@ int32_t ctdb_control_pull_db(struct ctdb_context *ctdb, TDB_DATA indata, TDB_DAT
        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) {
index f73990036a4e411b8672b27bc564b355fbe7241a..b3807464f3b7bfa60baac355bf17d691bb43773e 100644 (file)
@@ -1178,6 +1178,7 @@ struct recdb_data {
        struct ctdb_context *ctdb;
        struct ctdb_marshall_buffer *recdata;
        uint32_t len;
+       uint32_t allocated_len;
        bool failed;
        bool persistent;
 };
@@ -1206,7 +1207,10 @@ static int traverse_recdb(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
                params->failed = true;
                return -1;
        }
-       params->recdata = talloc_realloc_size(NULL, params->recdata, rec->length + params->len);
+       if (params->len + rec->length >= params->allocated_len) {
+               params->allocated_len = rec->length + params->len + params->ctdb->tunable.pulldb_preallocation_size;
+               params->recdata = talloc_realloc_size(NULL, params->recdata, params->allocated_len);
+       }
        if (params->recdata == NULL) {
                DEBUG(DEBUG_CRIT,(__location__ " Failed to expand recdata to %u (%u records)\n", 
                         rec->length + params->len, params->recdata->count));
@@ -1245,6 +1249,7 @@ static int push_recdb_database(struct ctdb_context *ctdb, uint32_t dbid,
        params.ctdb = ctdb;
        params.recdata = recdata;
        params.len = offsetof(struct ctdb_marshall_buffer, data);
+       params.allocated_len = params.len;
        params.failed = false;
        params.persistent = persistent;
 
index 663c38771f38e2ce5b53f7aaa5baf3d88b142685..83c8e52c17c134730f37c621a0f69747d619b982 100644 (file)
@@ -82,7 +82,8 @@ static const struct {
        { "NoIPTakeover",         0,  offsetof(struct ctdb_tunable, no_ip_takeover), false },
        { "DBRecordCountWarn",    100000,  offsetof(struct ctdb_tunable, db_record_count_warn), false },
        { "DBRecordSizeWarn",   10000000,  offsetof(struct ctdb_tunable, db_record_size_warn), false },
-       { "DBSizeWarn",        100000000,  offsetof(struct ctdb_tunable, db_size_warn), false }
+       { "DBSizeWarn",        100000000,  offsetof(struct ctdb_tunable, db_size_warn), false },
+       { "PullDBPreallocation", 10*1024*10240,  offsetof(struct ctdb_tunable, pulldb_preallocation_size), false }
 };
 
 /*