summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/gfdb/gfdb_data_store.c
diff options
context:
space:
mode:
authorGluster Ant <bugzilla-bot@gluster.org>2018-09-12 17:52:45 +0530
committerNigel Babu <nigelb@redhat.com>2018-09-12 17:52:45 +0530
commite16868dede6455cab644805af6fe1ac312775e13 (patch)
tree15aebdb4fff2d87cf8a72f836816b3aa634da58d /libglusterfs/src/gfdb/gfdb_data_store.c
parent45a71c0548b6fd2c757aa2e7b7671a1411948894 (diff)
Land part 2 of clang-format changes
Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4 Signed-off-by: Nigel Babu <nigelb@redhat.com>
Diffstat (limited to 'libglusterfs/src/gfdb/gfdb_data_store.c')
-rw-r--r--libglusterfs/src/gfdb/gfdb_data_store.c1005
1 files changed, 463 insertions, 542 deletions
diff --git a/libglusterfs/src/gfdb/gfdb_data_store.c b/libglusterfs/src/gfdb/gfdb_data_store.c
index 78fd22ee252..426596c571e 100644
--- a/libglusterfs/src/gfdb/gfdb_data_store.c
+++ b/libglusterfs/src/gfdb/gfdb_data_store.c
@@ -30,11 +30,10 @@
* gfdb_conn_node_t is an opaque structure.
* */
struct gfdb_conn_node_t {
- gfdb_connection_t gfdb_connection;
- struct list_head conn_list;
+ gfdb_connection_t gfdb_connection;
+ struct list_head conn_list;
};
-
/*
* db_conn_list is the circular linked list which
* will have all the database connections for the process
@@ -48,173 +47,168 @@ static gfdb_conn_node_t *db_conn_list;
* */
static pthread_mutex_t db_conn_mutex = PTHREAD_MUTEX_INITIALIZER;
-
/*Checks the sanity of the connection node*/
-#define CHECK_CONN_NODE(_conn_node)\
-do {\
- GF_ASSERT (_conn_node);\
- GF_ASSERT (_conn_node->gfdb_connection.gf_db_connection);\
-} while (0)
+#define CHECK_CONN_NODE(_conn_node) \
+ do { \
+ GF_ASSERT(_conn_node); \
+ GF_ASSERT(_conn_node->gfdb_connection.gf_db_connection); \
+ } while (0)
/* Checks the sanity of the connection node and goto */
-#define CHECK_CONN_NODE_GOTO(_conn_node, label)\
-do {\
- if (!_conn_node) {\
- goto label;\
- };\
- if (!_conn_node->gfdb_connection.gf_db_connection) {\
- goto label;\
- };\
-} while (0)
+#define CHECK_CONN_NODE_GOTO(_conn_node, label) \
+ do { \
+ if (!_conn_node) { \
+ goto label; \
+ }; \
+ if (!_conn_node->gfdb_connection.gf_db_connection) { \
+ goto label; \
+ }; \
+ } while (0)
/*Check if the conn node is first in the list*/
-#define IS_FIRST_NODE(db_conn_list, _conn_node)\
- ((_conn_node == db_conn_list) ? _gf_true : _gf_false)
-
+#define IS_FIRST_NODE(db_conn_list, _conn_node) \
+ ((_conn_node == db_conn_list) ? _gf_true : _gf_false)
/*Check if the conn node is the only node in the list*/
-#define IS_THE_ONLY_NODE(_conn_node)\
-((_conn_node->conn_list.next == _conn_node->conn_list.prev)\
- ? _gf_true : _gf_false)
-
-
+#define IS_THE_ONLY_NODE(_conn_node) \
+ ((_conn_node->conn_list.next == _conn_node->conn_list.prev) ? _gf_true \
+ : _gf_false)
/*Internal Function: Adds connection node to the end of
* the db connection list.*/
static int
-add_connection_node (gfdb_conn_node_t *_conn_node) {
- int ret = -1;
-
- GF_ASSERT (_conn_node);
-
- /*Lock the list*/
- ret = pthread_mutex_lock (&db_conn_mutex);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, ret,
- LG_MSG_LOCK_LIST_FAILED, "Failed lock db connection "
- "list %s", strerror(ret));
- ret = -1;
- goto out;
- }
-
- if (db_conn_list == NULL) {
- db_conn_list = _conn_node;
- } else {
- list_add_tail (&_conn_node->conn_list,
- &db_conn_list->conn_list);
- }
-
- /*unlock the list*/
- ret = pthread_mutex_unlock (&db_conn_mutex);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, ret,
- LG_MSG_UNLOCK_LIST_FAILED, "Failed unlock db "
- "connection list %s", strerror(ret));
- ret = -1;
- goto out;
- /*TODO What if the unlock fails.
- * Will it lead to deadlock?
- * Most of the gluster code
- * no check for unlock or destroy of mutex!*/
- }
- ret = 0;
+add_connection_node(gfdb_conn_node_t *_conn_node)
+{
+ int ret = -1;
+
+ GF_ASSERT(_conn_node);
+
+ /*Lock the list*/
+ ret = pthread_mutex_lock(&db_conn_mutex);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, ret, LG_MSG_LOCK_LIST_FAILED,
+ "Failed lock db connection "
+ "list %s",
+ strerror(ret));
+ ret = -1;
+ goto out;
+ }
+
+ if (db_conn_list == NULL) {
+ db_conn_list = _conn_node;
+ } else {
+ list_add_tail(&_conn_node->conn_list, &db_conn_list->conn_list);
+ }
+
+ /*unlock the list*/
+ ret = pthread_mutex_unlock(&db_conn_mutex);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, ret, LG_MSG_UNLOCK_LIST_FAILED,
+ "Failed unlock db "
+ "connection list %s",
+ strerror(ret));
+ ret = -1;
+ goto out;
+ /*TODO What if the unlock fails.
+ * Will it lead to deadlock?
+ * Most of the gluster code
+ * no check for unlock or destroy of mutex!*/
+ }
+ ret = 0;
out:
- return ret;
+ return ret;
}
-
/*Internal Function:
* Delete connection node from the list*/
static int
-delete_conn_node (gfdb_conn_node_t *_conn_node)
+delete_conn_node(gfdb_conn_node_t *_conn_node)
{
- int ret = -1;
-
- GF_ASSERT (_conn_node);
-
- /*Lock of the list*/
- ret = pthread_mutex_lock (&db_conn_mutex);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, ret,
- LG_MSG_LOCK_LIST_FAILED, "Failed lock on db connection"
- " list %s", strerror(ret));
- goto out;
+ int ret = -1;
+
+ GF_ASSERT(_conn_node);
+
+ /*Lock of the list*/
+ ret = pthread_mutex_lock(&db_conn_mutex);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, ret, LG_MSG_LOCK_LIST_FAILED,
+ "Failed lock on db connection"
+ " list %s",
+ strerror(ret));
+ goto out;
+ }
+
+ /*Remove the connection object from list*/
+ if (IS_THE_ONLY_NODE(_conn_node)) {
+ db_conn_list = NULL;
+ GF_FREE(_conn_node);
+ } else {
+ if (IS_FIRST_NODE(db_conn_list, _conn_node)) {
+ db_conn_list = list_entry(db_conn_list->conn_list.next,
+ gfdb_conn_node_t, conn_list);
}
-
- /*Remove the connection object from list*/
- if (IS_THE_ONLY_NODE(_conn_node)) {
- db_conn_list = NULL;
- GF_FREE (_conn_node);
- } else {
- if (IS_FIRST_NODE(db_conn_list, _conn_node)) {
- db_conn_list = list_entry (db_conn_list->conn_list.next,
- gfdb_conn_node_t, conn_list);
- }
- list_del(&_conn_node->conn_list);
- GF_FREE (_conn_node);
- }
-
- /*Release the list lock*/
- ret = pthread_mutex_unlock (&db_conn_mutex);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_WARNING, ret,
- LG_MSG_UNLOCK_LIST_FAILED, "Failed unlock on db "
- "connection list %s", strerror(ret));
- /*TODO What if the unlock fails.
- * Will it lead to deadlock?
- * Most of the gluster code
- * no check for unlock or destroy of mutex!*/
- ret = -1;
- goto out;
- }
- ret = 0;
+ list_del(&_conn_node->conn_list);
+ GF_FREE(_conn_node);
+ }
+
+ /*Release the list lock*/
+ ret = pthread_mutex_unlock(&db_conn_mutex);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_WARNING, ret, LG_MSG_UNLOCK_LIST_FAILED,
+ "Failed unlock on db "
+ "connection list %s",
+ strerror(ret));
+ /*TODO What if the unlock fails.
+ * Will it lead to deadlock?
+ * Most of the gluster code
+ * no check for unlock or destroy of mutex!*/
+ ret = -1;
+ goto out;
+ }
+ ret = 0;
out:
- return ret;
+ return ret;
}
-
/*Internal function: Used initialize/map db operation of
* specified type of db plugin*/
static int
-init_db_operations (gfdb_db_type_t gfdb_db_type,
- gfdb_db_operations_t *gfdb_db_operations)
+init_db_operations(gfdb_db_type_t gfdb_db_type,
+ gfdb_db_operations_t *gfdb_db_operations)
{
+ int ret = -1;
- int ret = -1;
+ GF_ASSERT(gfdb_db_operations);
- GF_ASSERT (gfdb_db_operations);
-
- /*Clear the gfdb_db_operations*/
- gfdb_db_operations = memset(gfdb_db_operations, 0,
- sizeof(*gfdb_db_operations));
- switch (gfdb_db_type) {
+ /*Clear the gfdb_db_operations*/
+ gfdb_db_operations = memset(gfdb_db_operations, 0,
+ sizeof(*gfdb_db_operations));
+ switch (gfdb_db_type) {
case GFDB_SQLITE3:
- gf_sqlite3_fill_db_operations (gfdb_db_operations);
- ret = 0;
- break;
+ gf_sqlite3_fill_db_operations(gfdb_db_operations);
+ ret = 0;
+ break;
case GFDB_HYPERDEX:
case GFDB_HASH_FILE_STORE:
case GFDB_ROCKS_DB:
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_UNSUPPORTED_PLUGIN, "Plugin not supported");
- break;
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_UNSUPPORTED_PLUGIN,
+ "Plugin not supported");
+ break;
case GFDB_INVALID_DB:
case GFDB_DB_END:
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_INVALID_DB_TYPE, "Invalid DB Type");
- break;
- }
- return ret;
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_INVALID_DB_TYPE,
+ "Invalid DB Type");
+ break;
+ }
+ return ret;
}
-
/******************************************************************************
*
* LIBGFDB API Functions
*
* ****************************************************************************/
-
/*Libgfdb API Function: Used to initialize a db connection
* (Constructor function for db connection object)
* Arguments:
@@ -225,85 +219,79 @@ init_db_operations (gfdb_db_type_t gfdb_db_type,
* Returns : if successful return the GFDB Connection node to the caller or
* NULL in case of failure*/
gfdb_conn_node_t *
-init_db (dict_t *args, gfdb_db_type_t gfdb_db_type)
+init_db(dict_t *args, gfdb_db_type_t gfdb_db_type)
{
- int ret = -1;
- gfdb_conn_node_t *_conn_node = NULL;
- gfdb_db_operations_t *db_operations_t = NULL;
-
- /*Create data base connection object*/
- _conn_node = GF_CALLOC (1, sizeof(gfdb_conn_node_t),
- gf_mt_db_conn_node_t);
- if (!_conn_node) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, ENOMEM,
- LG_MSG_NO_MEMORY, "Failed mem alloc for "
- "gfdb_conn_node_t");
- goto alloc_failed;
- }
-
- /*Init the list component of db connection object*/
- INIT_LIST_HEAD (&_conn_node->conn_list);
-
-
- /*Add created connection node to the list*/
- ret = add_connection_node (_conn_node);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_ADD_TO_LIST_FAILED, "Failed to add connection "
- "node to list");
- goto _conn_failed;
- }
-
- db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
-
- /*init the db ops object of db connection object*/
- ret = init_db_operations(gfdb_db_type, db_operations_t);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_INIT_DB_FAILED, "Failed initializing database "
- "operation failed.");
- goto init_db_failed;
- }
-
- /*Calling the init_db_op of the respected db type*/
- GF_ASSERT (db_operations_t->init_db_op);
- ret = db_operations_t->init_db_op (args, &_conn_node->gfdb_connection.
- gf_db_connection);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_INIT_DB_FAILED, "Failed initializing database");
- goto init_db_failed;
- }
- _conn_node->gfdb_connection.gfdb_db_type = gfdb_db_type;
- ret = 0;
-
- return _conn_node;
-
- /*****Error Handling********/
- /* If init_db_operations or init_db of plugin failed delete
- * conn node from the list.
- * connection node will be free by delete_conn_node*/
+ int ret = -1;
+ gfdb_conn_node_t *_conn_node = NULL;
+ gfdb_db_operations_t *db_operations_t = NULL;
+
+ /*Create data base connection object*/
+ _conn_node = GF_CALLOC(1, sizeof(gfdb_conn_node_t), gf_mt_db_conn_node_t);
+ if (!_conn_node) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, ENOMEM, LG_MSG_NO_MEMORY,
+ "Failed mem alloc for "
+ "gfdb_conn_node_t");
+ goto alloc_failed;
+ }
+
+ /*Init the list component of db connection object*/
+ INIT_LIST_HEAD(&_conn_node->conn_list);
+
+ /*Add created connection node to the list*/
+ ret = add_connection_node(_conn_node);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_ADD_TO_LIST_FAILED,
+ "Failed to add connection "
+ "node to list");
+ goto _conn_failed;
+ }
+
+ db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
+
+ /*init the db ops object of db connection object*/
+ ret = init_db_operations(gfdb_db_type, db_operations_t);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_INIT_DB_FAILED,
+ "Failed initializing database "
+ "operation failed.");
+ goto init_db_failed;
+ }
+
+ /*Calling the init_db_op of the respected db type*/
+ GF_ASSERT(db_operations_t->init_db_op);
+ ret = db_operations_t->init_db_op(
+ args, &_conn_node->gfdb_connection.gf_db_connection);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_INIT_DB_FAILED,
+ "Failed initializing database");
+ goto init_db_failed;
+ }
+ _conn_node->gfdb_connection.gfdb_db_type = gfdb_db_type;
+ ret = 0;
+
+ return _conn_node;
+
+ /*****Error Handling********/
+ /* If init_db_operations or init_db of plugin failed delete
+ * conn node from the list.
+ * connection node will be free by delete_conn_node*/
init_db_failed:
- ret = delete_conn_node (_conn_node);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_DELETE_FROM_LIST_FAILED, "Failed deleting "
- "connection node from list");
- }
- return NULL;
- /*if adding to the list failed free connection node*/
+ ret = delete_conn_node(_conn_node);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DELETE_FROM_LIST_FAILED,
+ "Failed deleting "
+ "connection node from list");
+ }
+ return NULL;
+ /*if adding to the list failed free connection node*/
_conn_failed:
- GF_FREE (_conn_node);
- /*if allocation failed*/
+ GF_FREE(_conn_node);
+ /*if allocation failed*/
alloc_failed:
- return NULL;
- /*****Error Handling********/
+ return NULL;
+ /*****Error Handling********/
}
-
-
-
-
/*Libgfdb API Function: Used to terminate/de-initialize db connection
* (Destructor function for db connection object)
* Arguments:
@@ -311,43 +299,38 @@ alloc_failed:
* Returns : if successful return 0 or
* -ve value in case of failure*/
int
-fini_db (gfdb_conn_node_t *_conn_node)
+fini_db(gfdb_conn_node_t *_conn_node)
{
- int ret = -1;
- gfdb_db_operations_t *db_operations_t = NULL;
-
- CHECK_CONN_NODE_GOTO (_conn_node, empty);
-
- db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
-
- GF_ASSERT (db_operations_t->fini_db_op);
-
- ret = db_operations_t->fini_db_op(&_conn_node->gfdb_connection.
- gf_db_connection);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_CLOSE_CONNECTION_FAILED, "Failed close the db "
- "connection");
- goto out;
- }
-
- ret = delete_conn_node (_conn_node);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_DELETE_FROM_LIST_FAILED, "Failed deleting "
- "connection node from list");
- }
+ int ret = -1;
+ gfdb_db_operations_t *db_operations_t = NULL;
+
+ CHECK_CONN_NODE_GOTO(_conn_node, empty);
+
+ db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
+
+ GF_ASSERT(db_operations_t->fini_db_op);
+
+ ret = db_operations_t->fini_db_op(
+ &_conn_node->gfdb_connection.gf_db_connection);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_CLOSE_CONNECTION_FAILED,
+ "Failed close the db "
+ "connection");
+ goto out;
+ }
+
+ ret = delete_conn_node(_conn_node);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DELETE_FROM_LIST_FAILED,
+ "Failed deleting "
+ "connection node from list");
+ }
empty:
- ret = 0;
+ ret = 0;
out:
- return ret;
+ return ret;
}
-
-
-
-
-
/*Libgfdb API Function: Used to insert/update records in the database
* NOTE: In current gfdb_sqlite plugin we use that
* same function to delete the record. Set the
@@ -364,36 +347,32 @@ out:
* Returns : if successful return 0 or
* -ve value in case of failure*/
int
-insert_record (gfdb_conn_node_t *_conn_node,
- gfdb_db_record_t *gfdb_db_record)
+insert_record(gfdb_conn_node_t *_conn_node, gfdb_db_record_t *gfdb_db_record)
{
- int ret = 0;
- gfdb_db_operations_t *db_operations_t = NULL;
- void *gf_db_connection = NULL;
+ int ret = 0;
+ gfdb_db_operations_t *db_operations_t = NULL;
+ void *gf_db_connection = NULL;
- CHECK_CONN_NODE(_conn_node);
+ CHECK_CONN_NODE(_conn_node);
- db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
- gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
+ db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
+ gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
- if (db_operations_t->insert_record_op) {
-
- ret = db_operations_t->insert_record_op (gf_db_connection,
- gfdb_db_record);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, _gfdb_log_level (GF_LOG_ERROR,
- gfdb_db_record->ignore_errors), 0,
- LG_MSG_INSERT_OR_UPDATE_FAILED, "Insert/Update"
- " operation failed");
- }
+ if (db_operations_t->insert_record_op) {
+ ret = db_operations_t->insert_record_op(gf_db_connection,
+ gfdb_db_record);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE,
+ _gfdb_log_level(GF_LOG_ERROR, gfdb_db_record->ignore_errors),
+ 0, LG_MSG_INSERT_OR_UPDATE_FAILED,
+ "Insert/Update"
+ " operation failed");
}
+ }
- return ret;
+ return ret;
}
-
-
-
/*Libgfdb API Function: Used to delete record from the database
* NOTE: In the current gfdb_sqlite3 plugin
* implementation this function is dummy.
@@ -405,31 +384,28 @@ insert_record (gfdb_conn_node_t *_conn_node,
* Returns : if successful return 0 or
* -ve value in case of failure*/
int
-delete_record (gfdb_conn_node_t *_conn_node,
- gfdb_db_record_t *gfdb_db_record)
+delete_record(gfdb_conn_node_t *_conn_node, gfdb_db_record_t *gfdb_db_record)
{
- int ret = 0;
- gfdb_db_operations_t *db_operations_t = NULL;
- void *gf_db_connection = NULL;
-
- CHECK_CONN_NODE(_conn_node);
+ int ret = 0;
+ gfdb_db_operations_t *db_operations_t = NULL;
+ void *gf_db_connection = NULL;
- db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
- gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
+ CHECK_CONN_NODE(_conn_node);
- if (db_operations_t->delete_record_op) {
-
- ret = db_operations_t->delete_record_op (gf_db_connection,
- gfdb_db_record);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_DELETE_FAILED, "Delete operation "
- "failed");
- }
+ db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
+ gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
+ if (db_operations_t->delete_record_op) {
+ ret = db_operations_t->delete_record_op(gf_db_connection,
+ gfdb_db_record);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DELETE_FAILED,
+ "Delete operation "
+ "failed");
}
+ }
- return ret;
+ return ret;
}
/*Libgfdb API Function: Compact the database.
@@ -441,38 +417,31 @@ delete_record (gfdb_conn_node_t *_conn_node,
* Returns : if successful return 0 or
* -ve value in case of failure*/
int
-compact_db (gfdb_conn_node_t *_conn_node, gf_boolean_t _compact_active,
- gf_boolean_t _compact_mode_switched)
+compact_db(gfdb_conn_node_t *_conn_node, gf_boolean_t _compact_active,
+ gf_boolean_t _compact_mode_switched)
{
- int ret = 0;
- gfdb_db_operations_t *db_operations_t = NULL;
- void *gf_db_connection = NULL;
+ int ret = 0;
+ gfdb_db_operations_t *db_operations_t = NULL;
+ void *gf_db_connection = NULL;
- CHECK_CONN_NODE(_conn_node);
+ CHECK_CONN_NODE(_conn_node);
- db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
- gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
-
- if (db_operations_t->compact_db_op) {
-
- ret = db_operations_t->compact_db_op (gf_db_connection,
- _compact_active,
- _compact_mode_switched);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_COMPACT_FAILED, "Compaction operation "
- "failed");
- }
+ db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
+ gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
+ if (db_operations_t->compact_db_op) {
+ ret = db_operations_t->compact_db_op(gf_db_connection, _compact_active,
+ _compact_mode_switched);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_COMPACT_FAILED,
+ "Compaction operation "
+ "failed");
}
+ }
- return ret;
+ return ret;
}
-
-
-
-
/*Libgfdb API Function: Query all the records from the database
* Arguments:
* _conn_node : GFDB Connection node
@@ -484,37 +453,30 @@ compact_db (gfdb_conn_node_t *_conn_node, gf_boolean_t _compact_active,
* Returns : if successful return 0 or
* -ve value in case of failure*/
int
-find_all (gfdb_conn_node_t *_conn_node,
- gf_query_callback_t query_callback,
- void *_query_cbk_args,
- int query_limit)
+find_all(gfdb_conn_node_t *_conn_node, gf_query_callback_t query_callback,
+ void *_query_cbk_args, int query_limit)
{
- int ret = 0;
- gfdb_db_operations_t *db_operations_t = NULL;
- void *gf_db_connection = NULL;
-
- CHECK_CONN_NODE(_conn_node);
-
- db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
- gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
-
- if (db_operations_t->find_all_op) {
- ret = db_operations_t->find_all_op (gf_db_connection,
- query_callback,
- _query_cbk_args,
- query_limit);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_FIND_OP_FAILED, "Find all operation "
- "failed");
- }
+ int ret = 0;
+ gfdb_db_operations_t *db_operations_t = NULL;
+ void *gf_db_connection = NULL;
- }
+ CHECK_CONN_NODE(_conn_node);
- return ret;
-}
+ db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
+ gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
+ if (db_operations_t->find_all_op) {
+ ret = db_operations_t->find_all_op(gf_db_connection, query_callback,
+ _query_cbk_args, query_limit);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED,
+ "Find all operation "
+ "failed");
+ }
+ }
+ return ret;
+}
/*Libgfdb API Function: Query records/files that have not changed/accessed
* from a time in past to current time
@@ -529,35 +491,30 @@ find_all (gfdb_conn_node_t *_conn_node,
* Returns : if successful return 0 or
* -ve value in case of failure*/
int
-find_unchanged_for_time(gfdb_conn_node_t *_conn_node,
- gf_query_callback_t query_callback,
- void *_query_cbk_args,
- gfdb_time_t *for_time)
+find_unchanged_for_time(gfdb_conn_node_t *_conn_node,
+ gf_query_callback_t query_callback,
+ void *_query_cbk_args, gfdb_time_t *for_time)
{
+ int ret = 0;
+ gfdb_db_operations_t *db_operations_t = NULL;
+ void *gf_db_connection = NULL;
- int ret = 0;
- gfdb_db_operations_t *db_operations_t = NULL;
- void *gf_db_connection = NULL;
-
- CHECK_CONN_NODE(_conn_node);
-
- db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
- gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
-
- if (db_operations_t->find_unchanged_for_time_op) {
+ CHECK_CONN_NODE(_conn_node);
- ret = db_operations_t->find_unchanged_for_time_op
- (gf_db_connection, query_callback,
- _query_cbk_args, for_time);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_FIND_OP_FAILED, "Find unchanged "
- "operation failed");
- }
+ db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
+ gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
+ if (db_operations_t->find_unchanged_for_time_op) {
+ ret = db_operations_t->find_unchanged_for_time_op(
+ gf_db_connection, query_callback, _query_cbk_args, for_time);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED,
+ "Find unchanged "
+ "operation failed");
}
+ }
- return ret;
+ return ret;
}
/*Libgfdb API Function: Query records/files that have changed/accessed from a
@@ -573,36 +530,29 @@ find_unchanged_for_time(gfdb_conn_node_t *_conn_node,
* Returns : if successful return 0 or
* -ve value in case of failure*/
int
-find_recently_changed_files(gfdb_conn_node_t *_conn_node,
+find_recently_changed_files(gfdb_conn_node_t *_conn_node,
gf_query_callback_t query_callback,
- void *_query_cbk_args,
- gfdb_time_t *from_time)
+ void *_query_cbk_args, gfdb_time_t *from_time)
{
+ int ret = 0;
+ gfdb_db_operations_t *db_operations_t = NULL;
+ void *gf_db_connection = NULL;
- int ret = 0;
- gfdb_db_operations_t *db_operations_t = NULL;
- void *gf_db_connection = NULL;
-
- CHECK_CONN_NODE(_conn_node);
-
- db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
- gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
+ CHECK_CONN_NODE(_conn_node);
- if (db_operations_t->find_recently_changed_files_op) {
-
- ret = db_operations_t->find_recently_changed_files_op (
- gf_db_connection, query_callback,
- _query_cbk_args, from_time);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_FIND_OP_FAILED,
- "Find changed operation failed");
- }
+ db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
+ gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
+ if (db_operations_t->find_recently_changed_files_op) {
+ ret = db_operations_t->find_recently_changed_files_op(
+ gf_db_connection, query_callback, _query_cbk_args, from_time);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED,
+ "Find changed operation failed");
}
+ }
- return ret;
-
+ return ret;
}
/*Libgfdb API Function: Query records/files that have not changed/accessed
@@ -624,38 +574,31 @@ find_recently_changed_files(gfdb_conn_node_t *_conn_node,
* -ve value in case of failure*/
int
find_unchanged_for_time_freq(gfdb_conn_node_t *_conn_node,
- gf_query_callback_t query_callback,
- void *_query_cbk_args,
- gfdb_time_t *for_time,
- int write_freq_thresold,
- int read_freq_thresold,
- gf_boolean_t _clear_counters)
+ gf_query_callback_t query_callback,
+ void *_query_cbk_args, gfdb_time_t *for_time,
+ int write_freq_thresold, int read_freq_thresold,
+ gf_boolean_t _clear_counters)
{
- int ret = 0;
- gfdb_db_operations_t *db_operations_t = NULL;
- void *gf_db_connection = NULL;
-
- CHECK_CONN_NODE(_conn_node);
+ int ret = 0;
+ gfdb_db_operations_t *db_operations_t = NULL;
+ void *gf_db_connection = NULL;
- db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
- gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
+ CHECK_CONN_NODE(_conn_node);
- if (db_operations_t->find_unchanged_for_time_freq_op) {
-
- ret = db_operations_t->find_unchanged_for_time_freq_op(
- gf_db_connection, query_callback,
- _query_cbk_args, for_time,
- write_freq_thresold, read_freq_thresold,
- _clear_counters);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_FIND_OP_FAILED,
- "Find unchanged with freq operation failed");
- }
+ db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
+ gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
+ if (db_operations_t->find_unchanged_for_time_freq_op) {
+ ret = db_operations_t->find_unchanged_for_time_freq_op(
+ gf_db_connection, query_callback, _query_cbk_args, for_time,
+ write_freq_thresold, read_freq_thresold, _clear_counters);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED,
+ "Find unchanged with freq operation failed");
}
+ }
- return ret;
+ return ret;
}
/*Libgfdb API Function: Query records/files that have changed/accessed from a
@@ -677,44 +620,34 @@ find_unchanged_for_time_freq(gfdb_conn_node_t *_conn_node,
* -ve value in case of failure*/
int
find_recently_changed_files_freq(gfdb_conn_node_t *_conn_node,
- gf_query_callback_t query_callback,
- void *_query_cbk_args,
- gfdb_time_t *from_time,
- int write_freq_thresold,
- int read_freq_thresold,
- gf_boolean_t _clear_counters)
+ gf_query_callback_t query_callback,
+ void *_query_cbk_args, gfdb_time_t *from_time,
+ int write_freq_thresold,
+ int read_freq_thresold,
+ gf_boolean_t _clear_counters)
{
+ int ret = 0;
+ gfdb_db_operations_t *db_operations_t = NULL;
+ void *gf_db_connection = NULL;
- int ret = 0;
- gfdb_db_operations_t *db_operations_t = NULL;
- void *gf_db_connection = NULL;
-
- CHECK_CONN_NODE(_conn_node);
-
- db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
- gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
+ CHECK_CONN_NODE(_conn_node);
- if (db_operations_t->find_recently_changed_files_freq_op) {
-
- ret = db_operations_t->find_recently_changed_files_freq_op(
- gf_db_connection, query_callback,
- _query_cbk_args, from_time,
- write_freq_thresold, read_freq_thresold,
- _clear_counters);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_FIND_OP_FAILED,
- "Find changed with freq operation failed");
- }
+ db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
+ gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;
+ if (db_operations_t->find_recently_changed_files_freq_op) {
+ ret = db_operations_t->find_recently_changed_files_freq_op(
+ gf_db_connection, query_callback, _query_cbk_args, from_time,
+ write_freq_thresold, read_freq_thresold, _clear_counters);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED,
+ "Find changed with freq operation failed");
}
+ }
- return ret;
-
+ return ret;
}
-
-
/*Libgfdb API Function: Clear the heat for all the files
*
* Arguments:
@@ -725,30 +658,29 @@ find_recently_changed_files_freq(gfdb_conn_node_t *_conn_node,
**/
int
-clear_files_heat (gfdb_conn_node_t *conn_node)
+clear_files_heat(gfdb_conn_node_t *conn_node)
{
- int ret = 0;
- gfdb_db_operations_t *db_operations = NULL;
- void *gf_db_connection = NULL;
-
- CHECK_CONN_NODE(conn_node);
-
- db_operations = &conn_node->gfdb_connection.gfdb_db_operations;
- gf_db_connection = conn_node->gfdb_connection.gf_db_connection;
-
- if (db_operations->clear_files_heat_op) {
- ret = db_operations->clear_files_heat_op (gf_db_connection);
- if (ret) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_INSERT_OR_UPDATE_FAILED,
- "Clear files heat operation failed");
- }
+ int ret = 0;
+ gfdb_db_operations_t *db_operations = NULL;
+ void *gf_db_connection = NULL;
+
+ CHECK_CONN_NODE(conn_node);
+
+ db_operations = &conn_node->gfdb_connection.gfdb_db_operations;
+ gf_db_connection = conn_node->gfdb_connection.gf_db_connection;
+
+ if (db_operations->clear_files_heat_op) {
+ ret = db_operations->clear_files_heat_op(gf_db_connection);
+ if (ret) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0,
+ LG_MSG_INSERT_OR_UPDATE_FAILED,
+ "Clear files heat operation failed");
}
+ }
- return ret;
+ return ret;
}
-
/* Libgfdb API Function: Function to extract version of the db
* Input:
* gfdb_conn_node_t *conn_node : GFDB Connection node
@@ -761,122 +693,111 @@ clear_files_heat (gfdb_conn_node_t *conn_node)
* On failure return -1
* */
int
-get_db_version (gfdb_conn_node_t *conn_node, char **version)
+get_db_version(gfdb_conn_node_t *conn_node, char **version)
{
- int ret = 0;
- gfdb_db_operations_t *db_operations = NULL;
- void *gf_db_connection = NULL;
-
- CHECK_CONN_NODE(conn_node);
-
- db_operations = &conn_node->gfdb_connection.gfdb_db_operations;
- gf_db_connection = conn_node->gfdb_connection.gf_db_connection;
-
- if (db_operations->get_db_version) {
- ret = db_operations->get_db_version (gf_db_connection,
- version);
- if (ret < 0) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_FIND_OP_FAILED,
- "Get version failed");
- }
+ int ret = 0;
+ gfdb_db_operations_t *db_operations = NULL;
+ void *gf_db_connection = NULL;
+
+ CHECK_CONN_NODE(conn_node);
+
+ db_operations = &conn_node->gfdb_connection.gfdb_db_operations;
+ gf_db_connection = conn_node->gfdb_connection.gf_db_connection;
+
+ if (db_operations->get_db_version) {
+ ret = db_operations->get_db_version(gf_db_connection, version);
+ if (ret < 0) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED,
+ "Get version failed");
}
+ }
- return ret;
+ return ret;
}
int
-get_db_params (gfdb_conn_node_t *conn_node, char *param_key,
- char **param_value)
+get_db_params(gfdb_conn_node_t *conn_node, char *param_key, char **param_value)
{
- int ret = -1;
- gfdb_db_operations_t *db_operations = NULL;
- void *gf_db_connection = NULL;
-
- CHECK_CONN_NODE(conn_node);
-
- db_operations = &conn_node->gfdb_connection.gfdb_db_operations;
- gf_db_connection = conn_node->gfdb_connection.gf_db_connection;
-
- if (db_operations->get_db_params) {
- ret = db_operations->get_db_params (gf_db_connection,
- param_key,
- param_value);
- if (ret < 0) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_FIND_OP_FAILED,
- "Get setting failed");
- }
+ int ret = -1;
+ gfdb_db_operations_t *db_operations = NULL;
+ void *gf_db_connection = NULL;
+
+ CHECK_CONN_NODE(conn_node);
+
+ db_operations = &conn_node->gfdb_connection.gfdb_db_operations;
+ gf_db_connection = conn_node->gfdb_connection.gf_db_connection;
+
+ if (db_operations->get_db_params) {
+ ret = db_operations->get_db_params(gf_db_connection, param_key,
+ param_value);
+ if (ret < 0) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED,
+ "Get setting failed");
}
+ }
- return ret;
+ return ret;
}
-
int
-set_db_params (gfdb_conn_node_t *conn_node, char *param_key,
- char *param_value)
+set_db_params(gfdb_conn_node_t *conn_node, char *param_key, char *param_value)
{
- int ret = -1;
- gfdb_db_operations_t *db_operations = NULL;
- void *gf_db_connection = NULL;
-
- CHECK_CONN_NODE(conn_node);
-
- db_operations = &conn_node->gfdb_connection.gfdb_db_operations;
- gf_db_connection = conn_node->gfdb_connection.gf_db_connection;
-
- if (db_operations->set_db_params) {
- ret = db_operations->set_db_params (gf_db_connection,
- param_key,
- param_value);
- if (ret < 0) {
- gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
- LG_MSG_INSERT_OR_UPDATE_FAILED,
- "Failed to set database setting");
- }
+ int ret = -1;
+ gfdb_db_operations_t *db_operations = NULL;
+ void *gf_db_connection = NULL;
+
+ CHECK_CONN_NODE(conn_node);
+
+ db_operations = &conn_node->gfdb_connection.gfdb_db_operations;
+ gf_db_connection = conn_node->gfdb_connection.gf_db_connection;
+
+ if (db_operations->set_db_params) {
+ ret = db_operations->set_db_params(gf_db_connection, param_key,
+ param_value);
+ if (ret < 0) {
+ gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0,
+ LG_MSG_INSERT_OR_UPDATE_FAILED,
+ "Failed to set database setting");
}
+ }
- return ret;
+ return ret;
}
-
-
-
-static const
-char *get_db_path_key()
+static const char *
+get_db_path_key()
{
- return GFDB_SQL_PARAM_DBPATH;
+ return GFDB_SQL_PARAM_DBPATH;
}
-void get_gfdb_methods (gfdb_methods_t *methods)
+void
+get_gfdb_methods(gfdb_methods_t *methods)
{
- methods->init_db = init_db;
- methods->fini_db = fini_db;
- methods->find_all = find_all;
- methods->find_unchanged_for_time = find_unchanged_for_time;
- methods->find_recently_changed_files = find_recently_changed_files;
- methods->find_unchanged_for_time_freq = find_unchanged_for_time_freq;
- methods->find_recently_changed_files_freq =
- find_recently_changed_files_freq;
- methods->clear_files_heat = clear_files_heat;
- methods->get_db_version = get_db_version;
- methods->get_db_params = get_db_params;
- methods->set_db_params = set_db_params;
- methods->get_db_path_key = get_db_path_key;
-
- /* Query Record related functions */
- methods->gfdb_query_record_new = gfdb_query_record_new;
- methods->gfdb_query_record_free = gfdb_query_record_free;
- methods->gfdb_add_link_to_query_record = gfdb_add_link_to_query_record;
- methods->gfdb_write_query_record = gfdb_write_query_record;
- methods->gfdb_read_query_record = gfdb_read_query_record;
-
- /* Link info related functions */
- methods->gfdb_link_info_new = gfdb_link_info_new;
- methods->gfdb_link_info_free = gfdb_link_info_free;
-
- /* Compaction related functions */
- methods->compact_db = compact_db;
+ methods->init_db = init_db;
+ methods->fini_db = fini_db;
+ methods->find_all = find_all;
+ methods->find_unchanged_for_time = find_unchanged_for_time;
+ methods->find_recently_changed_files = find_recently_changed_files;
+ methods->find_unchanged_for_time_freq = find_unchanged_for_time_freq;
+ methods
+ ->find_recently_changed_files_freq = find_recently_changed_files_freq;
+ methods->clear_files_heat = clear_files_heat;
+ methods->get_db_version = get_db_version;
+ methods->get_db_params = get_db_params;
+ methods->set_db_params = set_db_params;
+ methods->get_db_path_key = get_db_path_key;
+
+ /* Query Record related functions */
+ methods->gfdb_query_record_new = gfdb_query_record_new;
+ methods->gfdb_query_record_free = gfdb_query_record_free;
+ methods->gfdb_add_link_to_query_record = gfdb_add_link_to_query_record;
+ methods->gfdb_write_query_record = gfdb_write_query_record;
+ methods->gfdb_read_query_record = gfdb_read_query_record;
+
+ /* Link info related functions */
+ methods->gfdb_link_info_new = gfdb_link_info_new;
+ methods->gfdb_link_info_free = gfdb_link_info_free;
+
+ /* Compaction related functions */
+ methods->compact_db = compact_db;
}
-