BangDB Server- Network Cluster (Master Slaves Model)

Getting Started - BangDB Server

Please download the BangDB Server for linux native file and un-compress it. Run the install.sh file to install the BangDB client, that's it! (note the server is exe and is self contained and no extra lib is required for this) Please go through the README file for more info.

The download files are (once un-compressed):

  • include folder - This contains all the headers and soruce files needed to build app (using the bangdb-client.lib)
  • bangdb_bench folder - the simple test/bench file
  • bangdb-server (the server exe)
  • libbangdb-client.so.0.5 - The BangDB Client library
  • install.sh - The BangDB client install file
  • uninstall.sh - The BangDB client uninstall file
  • bangdb.config - The config file for BangDB Server and Client
  • README.txt - General info for the db and the release

To test the server and client. Simply go to the download dir and run the server (./bangdb-server) You will see the screen like this



Now using other terminal, go to the bangdb_bench folder contained in the same download folder then build it (bash build.sh) and run the client (./bench)

bash build.sh

Then run the exe with command line arg as suggested by the exe. For example to put and get 100,000 items with 4 threads run

./bench 4 100000 all

You can play with the server using the bench file.

The config file provided in the download dir has all the default values for the server and client and that should be good enough for the test and development purposes. However, for the production environment, please look at the configuration section or the document here

For more sophisticated usage, you will need to change the bangdb.config with right parameters. Please see below details for few necessary parameters

  • SERVER_DIR - This is basically the location where the db will keep its files (default is current folder)
  • IDX_SIZE - This is to denote the maximum length of key that you will be using to store values. The min value is 8 bytes, and maximum is dependent upon the PAGE_SIZE defined. however keep it small for better performance
  • BUFF_POOL_SIZE_HINT - The size of the buffer pool
  • BANGDB_LOG - to enable or disable write ahead log
  • SERVER_TYPE - 0 for master and 1 for slaves
  • SERVER_ID - ip address or name of the server (the running server, for slaves or master it's the address of this server)
  • SERV_PORT - port num of this server (master or slave)
  • MASTER_SERVER_ID - ip address or name of the master server
  • MASTER_SERV_PORT - port of the master server (note that for master SERVER_ID and MASTER_SERVER_ID would be same, same for the port)
  • MAX_SLAVES - maximum number of slaves. This can't be changed at run time. You must stop the server change it and then restart. Default is four
  • Please look at the bangdb.config for complete set of config params

Note that the clients for bangdb embedded or server are same in terms of API. Hence if you have code for bangdb embedded, you can potentially reuse the same code for bangdb server as well with some bangdb.config changes.

To build an application for BangDB Server, you can either download the test files (from listed above or included in the server download) and simply build and run it for test and then extend as required or can create from scratch as it's very simple and straight forward to create application for BangDB Server. Below are the steps to create an application on linux.

Below is sample code to do some simple operations using BangDB Server. The bangdb.config file defines many configurable parameters, but most importantly edit the following values based on your liking;

The sample client code is as follows (note exactly similar to that of bangdb embedded version)

	/* Create db, table and connection */
	database *db = new database((char*)"mydb");
	table *tbl = db->gettable((char*)"mytbl", 0);
	if(tbl == NULL)
	{
		printf("Table is NULL, quitting");
		return -1;
	}				
	connection *conn = tbl->getconnection();
	if(conn == NULL)
	{
		printf("Connection is NULL, quitting");
		return -1;
	}		
			
	/* do some operations */
	char *key = "key_1";
	char *val = "This is the test value for key_1";
				
	/* put */
	if(conn->put(key, val, INSERT_UNIQUE) < 0)
		printf("Put error");
					
	/* get */
	char *out = conn->get(key);
	if(out == NULL)
		printf("Get error");
				
	/* update */
	val = "Update value for the test key";
	if(conn->put(key, val, UPDATE_EXISTING) < 0)
		printf("Update error");
					
	/* del */
	if(conn->del(key) < 0)
		printf("Del error");
					
	/* try to get the del key */
	if(conn->get(key) != NULL)
		printf("Got the deleted value, error");