Skip to content
Snippets Groups Projects
Commit 07b8db00 authored by Alexandr Mruchok's avatar Alexandr Mruchok
Browse files

Merge branch 'master' of...

Merge branch 'master' of https://gitlab.demlabs.net/cellframe/libdap-chain-global-db into feature-2648
parents eed3f1e2 8c6bbf44
No related branches found
No related tags found
1 merge request!16Feature 2648
...@@ -9,7 +9,6 @@ if(WIN32) ...@@ -9,7 +9,6 @@ if(WIN32)
include_directories(../3rdparty/wepoll/include/) include_directories(../3rdparty/wepoll/include/)
include_directories(../3rdparty/uthash/src/) include_directories(../3rdparty/uthash/src/)
include_directories(../3rdparty/libjson-c/) include_directories(../3rdparty/libjson-c/)
include_directories(../3rdparty/libmagic/src/)
include_directories(../3rdparty/curl/include/) include_directories(../3rdparty/curl/include/)
include_directories(../3rdparty/libsqlite3/) include_directories(../3rdparty/libsqlite3/)
endif() endif()
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <pthread.h> #include <pthread.h>
#include <time.h> #include <time.h>
#include <assert.h> #include <assert.h>
#include <string.h> //#include <string.h>
#include "uthash.h" #include "uthash.h"
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#ifdef WIN32 #ifdef WIN32
#include "registry.h" #include "registry.h"
#include <string.h>
#endif #endif
#ifndef MAX_PATH #ifndef MAX_PATH
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <pthread.h> #include <pthread.h>
#include <assert.h>
#include "dap_common.h" #include "dap_common.h"
#include "dap_strfuncs.h" #include "dap_strfuncs.h"
......
...@@ -151,10 +151,8 @@ pcdb_instance dap_cdb_init_group(char *a_group, int a_flags) { ...@@ -151,10 +151,8 @@ pcdb_instance dap_cdb_init_group(char *a_group, int a_flags) {
l_cdb_i = DAP_NEW(cdb_instance); l_cdb_i = DAP_NEW(cdb_instance);
l_cdb_i->local_group = dap_strdup(a_group); l_cdb_i->local_group = dap_strdup(a_group);
l_cdb_i->cdb = cdb_new(); l_cdb_i->cdb = cdb_new();
memset(l_cdb_path, '\0', strlen(s_cdb_path) + strlen(a_group) + 2); memset(l_cdb_path, '\0', sizeof(l_cdb_path));
strcat(l_cdb_path, s_cdb_path); dap_snprintf(l_cdb_path, sizeof(l_cdb_path), "%s/%s", s_cdb_path, a_group);
strcat(l_cdb_path, "/");
strcat(l_cdb_path, a_group);
cdb_options l_opts = { 1000000, 128, 1024 }; cdb_options l_opts = { 1000000, 128, 1024 };
if (cdb_option(l_cdb_i->cdb, l_opts.hsize, l_opts.pcacheMB, l_opts.rcacheMB) != CDB_SUCCESS) { if (cdb_option(l_cdb_i->cdb, l_opts.hsize, l_opts.pcacheMB, l_opts.rcacheMB) != CDB_SUCCESS) {
log_it(L_ERROR, "Options are inacceptable: \"%s\"", cdb_errmsg(cdb_errno(l_cdb_i->cdb))); log_it(L_ERROR, "Options are inacceptable: \"%s\"", cdb_errmsg(cdb_errno(l_cdb_i->cdb)));
...@@ -245,70 +243,60 @@ pcdb_instance dap_cdb_get_db_by_group(const char *a_group) { ...@@ -245,70 +243,60 @@ pcdb_instance dap_cdb_get_db_by_group(const char *a_group) {
} }
int dap_cdb_add_group(const char *a_group) { int dap_cdb_add_group(const char *a_group) {
char* l_cdb_path = malloc(strlen(s_cdb_path) + strlen(a_group) + 2); char l_cdb_path[strlen(s_cdb_path) + strlen(a_group) + 2];
memset(l_cdb_path, '\0', strlen(s_cdb_path) + strlen(a_group) + 2); memset(l_cdb_path, '\0', sizeof(l_cdb_path));
strcat(l_cdb_path, s_cdb_path); dap_snprintf(l_cdb_path, sizeof(l_cdb_path), "%s/%s", s_cdb_path, a_group);
strcat(l_cdb_path, "/");
strcat(l_cdb_path, a_group);
#ifdef _WIN32 #ifdef _WIN32
mkdir(l_cdb_path); mkdir(l_cdb_path);
#else #else
mkdir(l_cdb_path, 0755); mkdir(l_cdb_path, 0755);
#endif #endif
free(l_cdb_path);
return 0; return 0;
} }
int dap_db_driver_cdb_deinit() { int dap_db_driver_cdb_deinit() {
cdb_instance *cur_cdb, *tmp; pcdb_instance cur_cdb, tmp;
pthread_mutex_lock(&cdb_mutex);
HASH_ITER(hh, s_cdb, cur_cdb, tmp) { HASH_ITER(hh, s_cdb, cur_cdb, tmp) {
DAP_DELETE(cur_cdb->local_group); DAP_DELETE(cur_cdb->local_group);
cdb_destroy(cur_cdb->cdb); cdb_destroy(cur_cdb->cdb);
HASH_DEL(s_cdb, cur_cdb); HASH_DEL(s_cdb, cur_cdb);
DAP_DELETE(cur_cdb); DAP_DELETE(cur_cdb);
} }
pthread_mutex_unlock(&cdb_mutex);
if (s_cdb_path) { if (s_cdb_path) {
DAP_DELETE(s_cdb_path); DAP_DELETE(s_cdb_path);
} }
return CDB_SUCCESS; return CDB_SUCCESS;
} }
int dap_db_driver_cdb_flush(void){ int dap_db_driver_cdb_flush(void) {
log_it(L_DEBUG, "Start flush cuttdb."); int ret = 0;
//CLOSE log_it(L_INFO, "Flushing CDB to disk");
cdb_instance *cur_cdb, *tmp; cdb_instance *cur_cdb, *tmp;
pthread_mutex_lock(&cdb_mutex);
HASH_ITER(hh, s_cdb, cur_cdb, tmp) { HASH_ITER(hh, s_cdb, cur_cdb, tmp) {
DAP_DELETE(cur_cdb->local_group); cdb_close(cur_cdb->cdb);
cdb_destroy(cur_cdb->cdb); char l_cdb_path[strlen(s_cdb_path) + strlen(cur_cdb->local_group) + 2];
HASH_DEL(s_cdb, cur_cdb); memset(l_cdb_path, '\0', sizeof(l_cdb_path));
DAP_DELETE(cur_cdb); dap_snprintf(l_cdb_path, sizeof(l_cdb_path), "%s/%s", s_cdb_path, cur_cdb->local_group);
} // Re-application of options might be required
//SYNC cdb_options l_opts = { 1000000, 128, 1024 };
#ifndef _WIN32 if (cdb_option(cur_cdb->cdb, l_opts.hsize, l_opts.pcacheMB, l_opts.rcacheMB) != CDB_SUCCESS) {
sync(); log_it(L_ERROR, "Options are inacceptable: \"%s\"", cdb_errmsg(cdb_errno(cur_cdb->cdb)));
#endif ret = -1;
//OPEN goto RET;
struct dirent *d;
DIR *dir = opendir(s_cdb_path);
if (!dir) {
log_it(L_ERROR, "Couldn't open db directory");
return -1;
}
for (d = readdir(dir); d; d = readdir(dir)) {
if (!dap_strcmp(d->d_name, ".") || !dap_strcmp(d->d_name, "..")) {
continue;
} }
pcdb_instance l_cdb_i = dap_cdb_init_group(d->d_name, CDB_CREAT | CDB_PAGEWARMUP); if(cdb_open(cur_cdb->cdb, l_cdb_path, CDB_CREAT | CDB_PAGEWARMUP) != CDB_SUCCESS) {
if (!l_cdb_i) { log_it(L_ERROR, "An error occured while opening CDB: \"%s\"", cdb_errmsg(cdb_errno(cur_cdb->cdb)));
dap_db_driver_cdb_deinit(); ret = -2;
closedir(dir); goto RET;
return -2;
} }
} }
closedir(dir); log_it(L_INFO, "All data dumped");
return 0; RET:
pthread_mutex_unlock(&cdb_mutex);
return ret;
} }
dap_store_obj_t *dap_db_driver_cdb_read_last_store_obj(const char* a_group) { dap_store_obj_t *dap_db_driver_cdb_read_last_store_obj(const char* a_group) {
......
/* /*
* Authors: * Authors:
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* Alexander Lysikov <alexander.lysikov@demlabs.net> * Alexander Lysikov <alexander.lysikov@demlabs.net>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* Kelvin Project https://github.com/kelvinblockchain * CellFrame https://cellframe.net
* Copyright (c) 2019 * Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019
* All rights reserved. * All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project This file is part of CellFrame SDK the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify CellFrame SDK is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
DAP is distributed in the hope that it will be useful, CellFrame SDK is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. along with any CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#ifdef DAP_OS_UNIX
#include <unistd.h>
#endif
#include "dap_common.h" #include "dap_common.h"
#include "dap_hash.h" #include "dap_hash.h"
#include "dap_strfuncs.h" #include "dap_strfuncs.h"
......
/* /*
* Authors: * Authors:
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* Alexander Lysikov <alexander.lysikov@demlabs.net> * Alexander Lysikov <alexander.lysikov@demlabs.net>
* DeM Labs Inc. https://demlabs.net * DeM Labs Inc. https://demlabs.net
* Kelvin Project https://github.com/kelvinblockchain * CellFrame https://cellframe.net
* Copyright (c) 2019 * Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019
* All rights reserved. * All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project This file is part of CellFrame SDK the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify CellFrame SDK is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
DAP is distributed in the hope that it will be useful, CellFrame SDK is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. along with any CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "sqlite3.h" #include "sqlite3.h"
#include "dap_chain_global_db_driver.h" #include "dap_chain_global_db_driver.h"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment