2016-09-13 18:54:26 -07:00
|
|
|
#ifndef DB_H
|
|
|
|
#define DB_H
|
|
|
|
|
2017-12-01 11:41:40 -08:00
|
|
|
#include <vector>
|
|
|
|
|
2016-11-18 19:57:51 -08:00
|
|
|
#include "common.h"
|
2016-09-13 18:54:26 -07:00
|
|
|
#include "event_loop.h"
|
|
|
|
|
2017-02-26 00:32:43 -08:00
|
|
|
typedef struct DBHandle DBHandle;
|
2016-09-13 18:54:26 -07:00
|
|
|
|
2016-11-18 19:57:51 -08:00
|
|
|
/**
|
|
|
|
* Connect to the global system store.
|
|
|
|
*
|
|
|
|
* @param db_address The hostname to use to connect to the database.
|
|
|
|
* @param db_port The port to use to connect to the database.
|
2017-05-18 17:40:41 -07:00
|
|
|
* @param db_shards_addresses The list of database shard IP addresses.
|
|
|
|
* @param db_shards_ports The list of database shard ports, in the same order
|
|
|
|
* as db_shards_addresses.
|
2016-11-18 19:57:51 -08:00
|
|
|
* @param client_type The type of this client.
|
2016-12-20 20:21:35 -08:00
|
|
|
* @param node_ip_address The hostname of the client that is connecting.
|
2017-12-01 11:41:40 -08:00
|
|
|
* @param args A vector of extra arguments strings. They should alternate
|
2016-12-20 20:21:35 -08:00
|
|
|
* between the name of the argument and the value of the argument. For
|
2017-12-01 11:41:40 -08:00
|
|
|
* examples: "port", "1234", "socket_name", "/tmp/s1". This vector should
|
|
|
|
* have an even length.
|
2016-11-18 19:57:51 -08:00
|
|
|
* @return This returns a handle to the database, which must be freed with
|
|
|
|
* db_disconnect after use.
|
|
|
|
*/
|
2017-05-18 17:40:41 -07:00
|
|
|
DBHandle *db_connect(const std::string &db_primary_address,
|
|
|
|
int db_primary_port,
|
2017-02-26 00:32:43 -08:00
|
|
|
const char *client_type,
|
|
|
|
const char *node_ip_address,
|
2017-12-01 11:41:40 -08:00
|
|
|
const std::vector<std::string> &args);
|
2016-12-20 20:21:35 -08:00
|
|
|
|
2016-11-18 19:57:51 -08:00
|
|
|
/**
|
|
|
|
* Attach global system store connection to an event loop. Callbacks from
|
|
|
|
* queries to the global system store will trigger events in the event loop.
|
|
|
|
*
|
2016-12-05 00:26:53 -08:00
|
|
|
* @param db The handle to the database that is connected.
|
|
|
|
* @param loop The event loop the database gets connected to.
|
|
|
|
* @param reattach Can only be true in unit tests. If true, the database is
|
|
|
|
* reattached to the loop.
|
2016-11-18 19:57:51 -08:00
|
|
|
* @return Void.
|
|
|
|
*/
|
2017-02-26 00:32:43 -08:00
|
|
|
void db_attach(DBHandle *db, event_loop *loop, bool reattach);
|
2016-09-13 18:54:26 -07:00
|
|
|
|
2016-11-18 19:57:51 -08:00
|
|
|
/**
|
|
|
|
* Disconnect from the global system store.
|
|
|
|
*
|
|
|
|
* @param db The database connection to close and clean up.
|
|
|
|
* @return Void.
|
|
|
|
*/
|
2017-02-26 00:32:43 -08:00
|
|
|
void db_disconnect(DBHandle *db);
|
2016-09-13 18:54:26 -07:00
|
|
|
|
2017-08-30 22:20:50 -07:00
|
|
|
/**
|
|
|
|
* Free the database handle.
|
|
|
|
*
|
|
|
|
* @param db The database connection to clean up.
|
|
|
|
* @return Void.
|
|
|
|
*/
|
|
|
|
void DBHandle_free(DBHandle *db);
|
|
|
|
|
2016-10-18 15:12:41 -07:00
|
|
|
/**
|
2016-11-18 19:57:51 -08:00
|
|
|
* Returns the db client ID.
|
2016-10-18 15:12:41 -07:00
|
|
|
*
|
|
|
|
* @param db The handle to the database.
|
2016-11-18 19:57:51 -08:00
|
|
|
* @returns int The db client ID for this connection to the database.
|
2016-10-18 15:12:41 -07:00
|
|
|
*/
|
2017-02-26 00:32:43 -08:00
|
|
|
DBClientID get_db_client_id(DBHandle *db);
|
2016-10-18 15:12:41 -07:00
|
|
|
|
2016-09-13 18:54:26 -07:00
|
|
|
#endif
|