From 97331fb7d44416f25bb43e49bdb0963fdf1483ca Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Sat, 19 Mar 2011 20:13:08 +0000 Subject: [PATCH] HBASE-3655 Revision to HBase book, more examples in data model, more metrics, more performance -- part one git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1083274 13f79535-47bb-0310-9956-ffa450edef68 --- src/docbkx/book.xml | 47 +++++++++++++++++++++++++++++++++++- src/docbkx/configuration.xml | 44 +++++++++++++++++++++++++++------ 2 files changed, 82 insertions(+), 9 deletions(-) diff --git a/src/docbkx/book.xml b/src/docbkx/book.xml index cf18f1f8c59..f10bbb0d8c9 100644 --- a/src/docbkx/book.xml +++ b/src/docbkx/book.xml @@ -319,7 +319,8 @@ Tables in HBase are initially created with one region by default. For bulk impo Get/Scan Gets are implemented on top of Scans. The below discussion of - Get applies equally to Scans. + Get applies equally to Scans. By default, i.e. if you specify no explicit version, when doing a get, the cell whose version has the @@ -343,6 +344,29 @@ Tables in HBase are initially created with one region by default. For bulk impo desired version and set the max versions to 1. + + +
+ Default Get Example + The following Get will only retrieve the current version of the row + + Get get = new Get( Bytes.toBytes("row1") ); + Result r = htable.get(get); + byte[] b = r.getValue( Bytes.toBytes("cf"), Bytes.toBytes("attr") ); // returns current version of value + + +
+
+ Versioned Get Example + The following Get will return the last 3 versions of the row. + + Get get = new Get( Bytes.toBytes("row1") ); + get.setMaxVersions(3); // will return last 3 versions of row + Result r = htable.get(get); + byte[] b = r.getValue( Bytes.toBytes("cf"), Bytes.toBytes("attr") ); // returns current version of value + List<KeyValue> kv = r.getColumn( Bytes.toBytes("cf"), Bytes.toBytes("attr") ); // returns all versions of this column + +
@@ -358,6 +382,27 @@ Tables in HBase are initially created with one region by default. For bulk impo To overwrite an existing value, do a put at exactly the same row, column, and version as that of the cell you would overshadow. +
+ Implicit Version Example + The following Put will be implicitly versioned by HBase with the current time. + + Put put = new Put(Bytes.toBytes(row)); + put.add(Bytes.toBytes("cf"), Bytes.toBytes("attr1"), Bytes.toBytes( data)); + htable.put(put); + + +
+
+ Explicit Version Example + The following Put has the version timestamp explicitly set. + + Put put = new Put( Bytes.toBytes( row ) ); + long explicitTimeInMs = 555; // just an example + put.add(Bytes.toBytes("cf"), Bytes.toBytes("attr1"), explicitTimeInMs, Bytes.toBytes( data)); + htable.put(put); + + +
diff --git a/src/docbkx/configuration.xml b/src/docbkx/configuration.xml index f032712b76f..d28e8d30aa3 100644 --- a/src/docbkx/configuration.xml +++ b/src/docbkx/configuration.xml @@ -259,15 +259,21 @@ of all regions.
Client configuration and dependencies connecting to an HBase cluster - Since the HBase Master may move around, clients bootstrap by looking ZooKeeper. Thus clients - require the ZooKeeper quorum information in a hbase-site.xml that - is on their CLASSPATH. + Since the HBase Master may move around, clients bootstrap by looking to ZooKeeper for + current critical locations. ZooKeeper is where all these values are kept. Thus clients + require the location of the ZooKeeper ensemble information before they can do anything else. + Usually this the ensemble location is kept out in the hbase-site.xml and + is picked up by the client from the CLASSPATH. + If you are configuring an IDE to run a HBase client, you should - include the conf/ directory on your classpath. + include the conf/ directory on your classpath so + hbase-site.xml settings can be found (or + add src/test/resources to pick up the hbase-site.xml + used by tests). - Minimally, a client of HBase needs the hbase, hadoop, log4j, commons-logging, and zookeeper jars - in its CLASSPATH connecting to a cluster. + Minimally, a client of HBase needs the hbase, hadoop, log4j, commons-logging, commons-lang, + and zookeeper jars in its CLASSPATH connecting to a cluster. An example basic hbase-site.xml for client only @@ -283,9 +289,31 @@ of all regions. -]]> - +]]> +
+ Java client configuration connecting to an HBase cluster + How Java reads hbase-site.xml content + The configuration used by a client is kept + in an HBaseConfiguration instance. + Through the factory method on HBaseConfiguration... + Configuration config = HBaseConfiguration.create(); + .. a client will pick up a configuration sourced from the first hbase-site.xml found on + the client's CLASSPATH, if one is present + (We'll also factor in any hbase-default.xml found; an hbase-default.xml ships inside + the hbase.X.X.X.jar). + It is also possible to specify configuration directly without having to read from a + hbase-site.xml. For examplt to set the + zookeeper ensemble for the cluster programmatically do as follows... + Configuration config = HBaseConfiguration.create(); + config.set("hbase.zookeeper.quorum", "localhost"); // we are running zookeeper locally + + If multiple zookeeper instances make up your zookeeper ensemble, + they may be specified in a comma-list (just as in the hbase-site.xml file). + This populated Configuration instance can then be passed to an + HTable instance via the overloaded constructor. + +