From 261c035c7d0cd1639cc8bd0ead82c30efcc0e93f Mon Sep 17 00:00:00 2001 From: Diogenes Nunez Date: Wed, 27 Jul 2016 11:09:47 -0400 Subject: cluster/tier: Adding compaction option for metadata databases Problem: As metadata in the database fills up, querying the database take a long time. As a result, tier migration slows down. To counteract this, we added a way to enable the compaction methods of the underlying database. The goal is to reduce the size of the underlying file by eliminating database fragmentation. NOTE: There is currently a bug where sometimes a brick will attempt to activate compaction. This happens even compaction is already turned on. The cause is narrowed down to the compact_mode_switch flipping its value. Changes: libglusterfs/src/gfdb - Added a gfdb function to compact the underlying database, compact_db() This is a no-op if the database has no such option. - Added a compaction function for SQLite3 that does the following 1) Changes the auto_vacuum pragma of the database 2) Compacts the database according to the type of compaction requested - Compaction type can be changed by changing the macro GF_SQL_COMPACT_DEF to one of the 4 compaction types in gfdb_sqlite3.h It is currently set to GF_SQL_COMPACT_INCR, or incremental vacuuming. xlators/cluster/dht/src - Added the following command-line option to enable SQLite3 compaction. gluster volume set tier-compact - Added the following command-line option to change the frequency the hot and cold tier are ordered to compact. gluster volume set tier-hot-compact-frequency gluster volume set tier-cold-compact-frequency - tier daemon periodically sends the (new) GFDB_IPC_CTR_SET_COMPACT_PRAGMA IPC to the CTR xlator. The IPC triggers compaction of the database. The inputs are both gf_boolean_t. IPC Input: compact_active: Is compaction currently on for the db. compact_mode_switched: Did we flip the compaction switch recently? IPC Output: 0 if the compaction succeeds. Non-zero otherwise. xlators/features/changetimerecorder/src/ - When the CTR gets the compaction IPC, it launches a thread that will perform the compaction. The IPC ends after the thread is launched. To avoid extra allocations, the parameters are passed using static variables. Change-Id: I5e1433becb9eeff2afe8dcb4a5798977bf5ba0dd Signed-off-by: Diogenes Nunez Reviewed-on: http://review.gluster.org/15031 Reviewed-by: Milind Changire Reviewed-by: Dan Lambright Tested-by: Dan Lambright CentOS-regression: Gluster Build System NetBSD-regression: NetBSD Build System Smoke: Gluster Build System --- xlators/mgmt/glusterd/src/glusterd-messages.h | 1 - xlators/mgmt/glusterd/src/glusterd-volume-set.c | 59 ++++++++++++++++++++----- 2 files changed, 47 insertions(+), 13 deletions(-) (limited to 'xlators/mgmt/glusterd/src') diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h index e520c69add2..2ba1876b6ec 100644 --- a/xlators/mgmt/glusterd/src/glusterd-messages.h +++ b/xlators/mgmt/glusterd/src/glusterd-messages.h @@ -4755,4 +4755,3 @@ /*------------*/ #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages" #endif /* !_GLUSTERD_MESSAGES_H_ */ - diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index ce34ffd2b05..d87082e9e89 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -386,6 +386,14 @@ validate_tier (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, ret = -1; goto out; } + goto out; + } else if (strstr (key, "tier-compact")) { + if (strcmp (value, "on") && + strcmp (value, "off")) { + ret = -1; + goto out; + } + goto out; } @@ -452,7 +460,9 @@ validate_tier (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, strstr (key, "tier-max-mb") || strstr (key, "tier-max-promote-file-size") || strstr (key, "tier-max-files") || - strstr (key, "tier-demote-frequency")) { + strstr (key, "tier-demote-frequency") || + strstr (key, "tier-hot-compact-frequency") || + strstr (key, "tier-cold-compact-frequency")) { if (origin_val < 1) { snprintf (errstr, sizeof (errstr), "%s is not a " " compatible value. %s expects a positive " @@ -464,7 +474,6 @@ validate_tier (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, ret = -1; goto out; } - } out: gf_msg_debug (this->name, 0, "Returning %d", ret); @@ -1589,17 +1598,17 @@ struct volopt_map_entry glusterd_volopt_map[] = { .flags = OPT_FLAG_CLIENT_OPT }, - /* Crypt xlator options */ + /* Crypt xlator options */ - { .key = "features.encryption", - .voltype = "encryption/crypt", - .option = "!feat", - .value = "off", - .op_version = 3, - .description = "enable/disable client-side encryption for " + { .key = "features.encryption", + .voltype = "encryption/crypt", + .option = "!feat", + .value = "off", + .op_version = 3, + .description = "enable/disable client-side encryption for " "the volume.", - .flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_XLATOR_OPT - }, + .flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_XLATOR_OPT + }, { .key = "encryption.master-key", .voltype = "encryption/crypt", @@ -1968,7 +1977,7 @@ struct volopt_map_entry glusterd_volopt_map[] = { .flags = OPT_FLAG_CLIENT_OPT }, - /* Feature translators */ + /* Feature translators */ { .key = "features.uss", .voltype = "features/snapview-server", .op_version = GD_OP_VERSION_3_6_0, @@ -2730,6 +2739,32 @@ struct volopt_map_entry glusterd_volopt_map[] = { .description = "The maximum number of files that may be migrated" " in any direction in a given cycle by a single node." }, + { .key = "cluster.tier-compact", + .voltype = "cluster/tier", + .option = "tier-compact", + .value = "on", + .op_version = GD_OP_VERSION_3_9_0, + .flags = OPT_FLAG_CLIENT_OPT, + .validate_fn = validate_tier, + .description = "Activate or deactivate the compaction of the DB" + " for the volume's metadata." + }, + { .key = "cluster.tier-hot-compact-frequency", + .voltype = "cluster/tier", + .value = "604800", + .option = "tier-hot-compact-frequency", + .op_version = GD_OP_VERSION_3_9_0, + .flags = OPT_FLAG_CLIENT_OPT, + .validate_fn = validate_tier, + }, + { .key = "cluster.tier-cold-compact-frequency", + .voltype = "cluster/tier", + .value = "604800", + .option = "tier-cold-compact-frequency", + .op_version = GD_OP_VERSION_3_9_0, + .flags = OPT_FLAG_CLIENT_OPT, + .validate_fn = validate_tier, + }, { .key = "features.ctr-enabled", .voltype = "features/changetimerecorder", .value = "off", -- cgit