NoSQL Zone is brought to you in partnership with:

Istvan Szegedi is an IT Technical Architect at Vodafone UK. He has been working at Hewlett-Packard, Nokia Networks, Google, Morgan Stanley and Vodafone. He holds certificates such as Sun Certified System Administrator, Sun Certified Java Programmer, Sun Certified Web Component Developer, Salesforce.com Certified Force.com Developer, TOGAF Certified Enterprise Architect. As a big fan of mobile and cloud computing, he likes to believe that these technologies will eventually push aside the desktop/client-server architecture Istvan is a DZone MVB and is not an employee of DZone and has posted 38 posts at DZone. You can read more from them at their website. View Full User Profile

Introducing NuoDB - An Elastically Scalable Cloud Database

04.10.2013
| 7985 views |
  • submit to reddit

Curator's Note: This is the first in a series of three articles that explore NuoDB.  You can learn more about NuoDB, as well as access a free trial, by heading over to the NuoDB website.


Introduction

Traditional relational databases are built upon a synchronous, client-server architecture that is often limited in terms of scalability requirements that are posed by distributed computing systems. As a result, various sharding, caching, and replication techniques emerged to cope with these demands. On the other hand, NoSQL solutions have emerged on the ground of the CAP theorem.  Data management systems like BigTable, HBase, MongoDB, Cassandra, and Dynamo offer different capabilities depending on how they balance consistency, availability, and partition tolerance. However, they gave up supporting SQL and ACID properties, which are critical in the relational database world.

NuoDB is a complete re-think of relational databases that is built on a new foundation: partial, on-demand replication. Under the hood, NuoDB is an asynchronous, decentralized, peer-to-peer database. It uses the concept of Atoms, which are objects that are being replicated. In NuoDB, everything is an Atom; database, schema, sequence, table, index, records, blobs, data. NuoDB holds a patent on this peer-to-peer object replication.


NuoDB Architecture

NuoDB architecture has three layers: management, SQL, and data. Themanagement layer is comprised of an agent that manages the NuoDB processes running on a particular computer. It starts and stops them, and it also collects statistics from the transaction and storage engines. Certain agents are configured to be a broker. Brokers communicate with the client initially and then introduce the client to the transaction engine. From then on, the client can communicate directly with the transaction engines. NuoDB’s management layer also offers a command line and a web-based management tool to manage the databases, as well as a command line loader for exporting and importing data.

At the SQL layer,transaction engines provide access to a single database.The transaction engine parses, compiles, optimizes, and executes the SQL statements on behalf of the clients.

At the data layer, storage managers provide persistence of the data. A storage manager uses key/value pairs to store information, but it can also use more sophisticated stores e.g. HDFS.

In the case of a minimal configuration, we can run every component (broker, transaction engine, and storage manager) on the same machine. NuoDB can be easily scaled out and can be made redundant by adding multiple brokers, transaction engines, and storage managers. In more complex scenarios, we can run NuoDB in the AWS cloud or across multiple corporate datacenters in order to provide geo-redundancy. Below is an example of a redundant architecture with two brokers, two transaction engines, and two storage managers.

 NuoDBRedundantArchitecture


Getting Started

NuoDB is available on multiple platforms, including Windows 32 and 64-bit, Linux 64-bit (Ubuntu, RHEL, Suse), Mac OSX 10.7, and Solaris 11 (Inter 64-bit).  For this tutorial, we used an Ubuntu 12.04 LTS virtual machine.

First, we need to start up the components as discussed above, beginning with the broker/agent.  Then, from the command line management tool, we can start up the transaction engine and the storage manager. We also need to configure the properties file to contain the settings for the domain.

$ vi ./etc/stock.properties
# A flag specifying whether this agent should be run as a connection broker
broker = true
# The name used to identify the domain that this agent is a part of 
domain = stock
# The default administrative password, and the secret used by agents to
# setup and maintain the domain securely
domainPassword = stock
=================================================================
# Start agent
$ java -DpropertiesUrl=file:///home/notroot/nuodb/etc/stock.properties -jar jar/nuoagent.jar --verbose &>/tmp/stock.log &
# Start command line manager
$ java -jar jar/nuodbmanager.jar --broker localhost --password stock
nuodb [stock] > show domain summary
Hosts:
[broker] localhost/127.0.0.1:48004
## Create a new domain administrator user
nuodb [stock] > create domain administrator user istvan password istvan
## Start Storage Manager
nuodb [stock] > start process sm
Database: stock
Host: localhost
Process command-line options: --dba-user stock --dba-password stock
Archive directory: /home/notroot/nuodb/data
Initialize archive: true
Started: [SM] ubuntu/127.0.1.1:59914 [ pid = 3467 ] ACTIVE
## ps -ef | grep nuodb
## notroot   3467  3396  0 12:01 pts/0    00:00:00 /home/notroot/nuodb-1.0.1.128.linux.x86_64/bin/nuodb --connect-key 7124934669079864995
## Start Transaction Engine
nuodb [stock/stock] > start process te
Host: localhost
Process command-line options: --dba-user stock --dba-password stock
Started: [TE] ubuntu/127.0.1.1:60545 [ pid = 3494 ] ACTIVE

## ps -ef| grep nuodb
## notroot   3494  3396  0 12:06 pts/0    00:00:00 /home/notroot/nuodb-1.0.1.128.linux.x86_64/bin/nuodb --connect-key 8587006928753483386

Note that we started the storage manager with the initialize yes option. This is only for the first time; any subsequent startup shall use the initialize no option, otherwise the data will be overwritten.

Next, we can connect to the database using the nuosql client – the first argument is the name of the database (stock), and we need to specify the database admin username/password. After login, we can set the schema with the use command to stock:
$ bin/nuosql stock --user stock --password stock
SQL> use stock
SQL> show
	autocommit state is on
	semicolon completion is required
	current schema is STOCK
SQL> show tables
	No tables found in schema STOCK
SQL> create table Stock
   > (
   >    Id             Integer not NULL generated always as identity primary key,
   >    StockDate      Date,
   >    StockOpen      Decimal(8,2),
   >    StockHigh      Decimal(8,2),
   >    StockLow       Decimal(8,2),
   >    StockClose     Decimal(8,2),
   >    StockVolume    Integer,
   >    StockAdjClose  Decimal(8,2)
   > );
SQL> show tables
	Tables in schema STOCK
		STOCK
We can then load the data stored in .csv file format into the database table. The CSV file – google.csv for stock information – was downloaded from http://finance.yahoo.com

$ bin/nuoloader --schema stock --user stock --password stock --import "/home/notroot/nuodb/samples/stock/google.csv",skip --to "insert into Stock values(default,?,?,?,?,?,?,?)" stock &> /tmp/nuoloader.log

Imported 2163 rows, failed 0 rows, size 101897 bytes from /home/notroot/nuodb/samples/stock/google.csv
Next, we can login again using nuosql and run a regular SQL query to retrieve the top 10 stock values and the corresponding date (ordered by adj close value):

notroot@ubuntu:~/nuodb$ bin/nuosql stock --user stock --password stockSQL> use stock
SQL> select count(*) from stock;
 COUNT  
 ------ 
  2163  

SQL> select StockDate, StockOpen,StockClose, StockVolume, StockAdjClose from stock order by StockAdjClose desc limit 10;
 STOCKDATE  STOCKOPEN  STOCKCLOSE  STOCKVOLUME  STOCKADJCLOSE  
 ---------- ---------- ----------- ------------ -------------- 
 2013-03-05   828.93     838.60      4044100        838.60     
 2013-03-11   831.69     834.82      1594700        834.82     
 2013-03-07   834.06     832.60      2052700        832.60     
 2013-03-08   834.50     831.52      2911900        831.52     
 2013-03-06   841.03     831.38      2873000        831.38     
 2013-03-12   830.71     827.61      2008300        827.61     
 2013-03-13   827.90     825.31      1641300        825.31     
 2013-03-14   826.99     821.54      1651200        821.54     
 2013-03-04   805.30     821.50      2775600        821.50     
 2013-03-20   816.83     814.71      1463800        814.71

Java Client - JDBC for NuoDB

NuoDB supports various programming languages for client applications such as Java, .NET, PHP, Ruby and Node.js. In this section we demonstrate that NuoDB supports JDBC in the same way that it is available for traditional relational databases. The Java program needs to add nuodbjdbc.jar to its classpath.

Below is an example Java code (StockDB.java) to retrieve the highest stock value ever (ordered by adj close) and the related date:

$ cat StockDB.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class StockDB {

    /** The driver class provided by NimbusDB. */
    public static final String DRIVER_CLASS =
	"com.nuodb.jdbc.Driver";

    /** The base URL for connecting to a local database server. */
    public static final String DATABASE_URL =
	"jdbc:com.nuodb://localhost/";

    // the established connection to a local server
    private final Connection dbConnection;

    /**
     * Creates an instance of DB and connects to a local server,
     * as the given user, to work with the given named database
     *
     * @param user the user name for the connection
     * @param password the password for the given user
     * @param dbName the name of the database at the server to use
     */
    public StockDB(String user, String password, String dbName)
	throws SQLException
    {
	Properties properties = new Properties();
	properties.put("user", user);
	properties.put("password", password);
	properties.put("schema", "stock");

	dbConnection =
	    DriverManager.getConnection(DATABASE_URL + dbName, properties);
    }

    /** Closes the connection to the server. */
    public void close() throws SQLException {
	dbConnection.close();
    }

    /**
     * Gets the name for the given id, or null if no name exists.
     *
     * @param an identifier
     * @return the name associate with the identifier, or null
     */
    public String getDateAndAdjClose() throws SQLException {
	Statement stmt = dbConnection.createStatement();
	ResultSet rs = stmt.
	    executeQuery("select stockdate, stockadjclose from stock order by stockadjclose desc limit 1");
	try {
	    if (rs.next())
		return rs.getString(1) + ", " + rs.getString(2);
	    return null;
	} finally {
	    rs.close();
	    stmt.close();
	}
    }

    /** Main-line for this example. */
    public static void main(String [] args) throws Exception {
	Class.forName(DRIVER_CLASS);

	StockDB stockDB = new StockDB("stock", "stock", "stock");
	System.out.println("Date and AdjClose: "  + stockDB.getDateAndAdjClose());

	stockDB.close();
    }

}

Then we can run the Java program as follows:

notroot@ubuntu:~/nuodb/samples/java$ javac StockDB.java 
notroot@ubuntu:~/nuodb/samples/java$ java -classpath .:../../jar/nuodbjdbc.jar StockDB
Date and AdjClose: 2013-03-05, 838.60


Conclusion

NuoDB takes a new approach to address the challenges of data growth and scalability issues. Traditional relational databases have limitations due to their architecture and require fairly complex techniques such as sharding and master/slave replication to cope with scale out demands. NoSQL databases take another route to support scalability at the cost of dropping SQL and transaction management that requires new programming methods.  NouDB promises the ability to combine the good things from the relational database world (SQL support and ACID properties) and from NoSQL methodologies  (easy to scale out, asynchronous nature with on-demand replication)  and offers a great choice to deal with the modern, 21st century database requirements.
Published at DZone with permission of Istvan Szegedi, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Sarfraz Khan replied on Wed, 2013/04/10 - 11:25am

 Very impressive. I was expecting to see some comparative analysis in terms of some stats/performance measures between RDBMS vs NuoDB.

Also, it appears that you have to stick with the Console window for everything you would ever do for administration/development purpose. does it come with any UI tool for this purpose?

Wiqar Chaudry replied on Wed, 2013/04/10 - 8:46pm in response to: Sarfraz Khan

@Sarfraz Khan, thanks for your kind words and comment - NuoDB compares favorably against many popular relational and NoSQL databases. We are currently running TPC-C/DBT2 benchmarks which will be made public in the coming weeks. You can also download out YCSB benchmark report from our website: http://www.nuodb.com/resources/documents/

The current release of NuoDB 1.0.2 includes a beta version of our visual editor as part of our install. We will be releasing the GA version in the next few weeks. You can download NuoDB at www.nuodb.com and try it for yourself. 

Please let us know if you have any other questions we can help answer. 

Best regards, 

Wiqar Chaudry

Technology Evangelist, NuoDB

Istvan Szegedi replied on Thu, 2013/04/11 - 8:30am in response to: Sarfraz Khan

@Sarfraz,

Wiqar was very kind to explain in his reply how NuoDB compares to other database solutions and provided the reference link to the benchmarks.

As for you other question, NuoDB comes with a  web console as well, it is based on Jetty and provides you capabilities to manage databases - start a database, add an engine, check alerts, and the like - from web UI, you do not have to use command line for database management.

Istvan.

Sarfraz Khan replied on Thu, 2013/04/11 - 8:56am in response to: Istvan Szegedi

 Thanks Istvan.

With the growth in NoSQL databases we have seen many home cooked databases flooding in. But NuoDB is very impressive in all good notes. Exploring NuoDB is in  my ToDO list now :)



Jim Fitzgerald replied on Tue, 2013/05/14 - 1:04pm

 I have one statement: Greg Fegan where have you been the last 6 years, this guy is a natural leader and one of the best sales guys this industry has ever seen

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.