Adding Support for a New Database

Chris Donati edited this page May 25, 2015 · 3 revisions

AppScale is designed to make it easy to run over different databases. It does so by abstracting away the database itself through two interfaces: one that defines how the database should be started, and one that defines how to save and retrieve data. This document details how these interfaces are defined and how to extend AppScale to support a new database via an example (which we will call "mydb").

ProTip: In addition to these directions, check out how we implement support for Cassandra (appscale/AppDB/cassandra) for best practices when adding support for your database.

Step 1: Change the Build Script to Install Your Database

When we build an AppScale virtual machine from source, we need to automatically build your new database as well. Open up appscale/debian/ and add a function named "installmydb", which should define how to install your database. Next, open appscale/debian/ and change this line:

supported_dbs=(hbase hypertable mysql cassandra)

to be:

supported_dbs=(hbase hypertable mysql cassandra mydb)

to tell the build script that your database is officially supported. Continue by opening appscale/debian/ and after the "core)" section, add in your database:

   ... lots of stuff ...
  ... lots of stuff ...
  ... lots of stuff ...
    installcassandra # and the other DBs

Of course, be sure to actually test that this works! Build a clean Ubuntu Lucid VM, run "bash" and make sure your database is installed.

Step 2: Tell AppScale How to Configure, Start, and Stop Your Database

Begin by creating a directory in AppDB named after your database:

$ mkdir appscale/AppDB/mydb

Next, create a file in that directory named "mydb_helper.rb". This Ruby file needs to define the following functions:




setup_db_config_files(master_ip, slave_ips, creds)





Step 3: Tell AppScale How to Read and Write to Your Database

Begin by creating an empty "" file in your app's interface directory:

$ touch appscale/AppDB/mydb/

Next, create a file named "" and create a class called "MyDBInterface" that subclasses "AppDBInterface". Be sure to import that interface from dbinterface_batch and not the older, slower dbinterface. Next, implement the following methods for your database:

batch_get_entity(self, table_name, row_key, column_names)

batch_put_entity(self, table_name, row_key, column_names, cell_values)

batch_delete(self, table_name, row_keys, column_names=[])

delete_table(self, table_name)

range_query(self, table_name, column_names, start_key, end_key, limit, offset=0, start_inclusive=True, end_inclusive=True, keys_only=False)

create_table(self,table_name, column_names)

Step 4: Tell the AppScale Tools About Your Database

To prevent users from running with a misspelled database name, the AppScale Tools only let users run databases that match a whitelist. Open up appscale-tools/lib/ and change this line:

ALLOWED_DATASTORES = ["hbase", "hypertable", "cassandra"]

to include your database:

ALLOWED_DATASTORES = ["hbase", "hypertable", "cassandra", "mydb"]

You then will be good to go when you execute "appscale-run-instances" or "appscale up" with your new database name specified! Make sure that you can run AppScale with your database on one node and four nodes, in a cluster deployment and in a cloud deployment. Try the guestbook app for an easy app that does puts and queries.

Step 5: Send Us a Pull Request!

Once you have your new database automatically started and installed on AppScale virtual machines, send us a pull request in a branch that details what database you've added support for and why it's awesome, and we'll review it and (assuming it works for us) accept it!