diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2021-11-26 20:36:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-26 20:36:00 +0200 |
commit | 0586829ee645a672a032b2346d7ea9718e4142af (patch) | |
tree | 8b95d2a031a8e792a8ab446949573ce40435194a /daemon | |
parent | e2bdee968ead738b2af70c3f62ecb71dfa34309e (diff) |
Add commands to check and fix database corruption (#11828)
* Set a flag to do aclk sync thread shutdown
Attempt to dequeue a cmd in case the queue is full and someone is blocked
* Drop tables and recreate instead of deleting
* Add commands to check the database -W check-database, fix-database, compact-database
* Split the database setup to config and cleanup part
* Add checks during database setup and cleanup to detect corruption to the dimension and chart tables
* Add full database check and refactor code
* Change commands to better indicate that the operations refer to the sqlite metadata database (not the metrics dbengine database)
* Add check for table being null (request for entire database check)
* Rename command for better clarity
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/main.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/daemon/main.c b/daemon/main.c index 0826e09d4f..2ec5c33f9e 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -44,6 +44,9 @@ void netdata_cleanup_and_exit(int ret) { // stop everything info("EXIT: stopping static threads..."); +#ifdef ENABLE_NEW_CLOUD_PROTOCOL + aclk_sync_exit_all(); +#endif cancel_main_threads(); // free the database @@ -360,13 +363,16 @@ int help(int exitcode) { " -W stacksize=N Set the stacksize (in bytes).\n\n" " -W debug_flags=N Set runtime tracing to debug.log.\n\n" " -W unittest Run internal unittests and exit.\n\n" + " -W sqlite-check Check metadata database integrity and exit.\n\n" + " -W sqlite-fix Check metadata database integrity, fix if needed and exit.\n\n" + " -W sqlite-compact Reclaim metadata database unused space and exit.\n\n" #ifdef ENABLE_DBENGINE " -W createdataset=N Create a DB engine dataset of N seconds and exit.\n\n" " -W stresstest=A,B,C,D,E,F\n" " Run a DB engine stress test for A seconds,\n" " with B writers and C readers, with a ramp up\n" " time of D seconds for writers, a page cache\n" - " size of E MiB, an optional disk space limit" + " size of E MiB, an optional disk space limit\n" " of F MiB and exit.\n\n" #endif " -W set section option value\n" @@ -801,6 +807,20 @@ int main(int argc, char **argv) { char* createdataset_string = "createdataset="; char* stresstest_string = "stresstest="; #endif + if(strcmp(optarg, "sqlite-check") == 0) { + sql_init_database(DB_CHECK_INTEGRITY); + return 0; + } + + if(strcmp(optarg, "sqlite-fix") == 0) { + sql_init_database(DB_CHECK_FIX_DB); + return 0; + } + + if(strcmp(optarg, "sqlite-compact") == 0) { + sql_init_database(DB_CHECK_RECLAIM_SPACE); + return 0; + } if(strcmp(optarg, "unittest") == 0) { if(unit_test_buffer()) return 1; |