Permalink
Browse files

Reorganizes the chapters.

  • Loading branch information...
1 parent 94bdbff commit 4ef467e325b17d3ccabfb23f27cafb1eda1e6ddc @larsgeorge committed May 10, 2011
Showing with 18 additions and 1,705 deletions.
  1. +0 −8 ch04/pom.xml
  2. +0 −78 ch04/src/main/java/admin/ClusterStatusExample.java
  3. +0 −39 ch04/src/main/java/admin/CreateTableExample.java
  4. +0 −69 ch04/src/main/java/admin/CreateTableWithRegionsExample.java
  5. +0 −52 ch04/src/main/java/admin/ListTablesExample.java
  6. +0 −46 ch04/src/main/java/admin/ModifyTableExample.java
  7. +0 −70 ch04/src/main/java/admin/TableOperationsExample.java
  8. +0 −79 ch04/src/main/java/client/BatchExample.java
  9. +0 −63 ch04/src/main/java/client/CheckAndDeleteExample.java
  10. +0 −56 ch04/src/main/java/client/CheckAndPutExample.java
  11. +0 −50 ch04/src/main/java/client/DeleteExample.java
  12. +0 −80 ch04/src/main/java/client/DeleteListErrorExample.java
  13. +0 −67 ch04/src/main/java/client/DeleteListExample.java
  14. +0 −40 ch04/src/main/java/client/GetExample.java
  15. +0 −56 ch04/src/main/java/client/GetListErrorExample.java
  16. +0 −74 ch04/src/main/java/client/GetListExample.java
  17. +0 −44 ch04/src/main/java/client/GetRowOrBeforeExample.java
  18. +0 −121 ch04/src/main/java/client/MissingRegionExample.java
  19. +0 −38 ch04/src/main/java/client/PutExample.java
  20. +0 −39 ch04/src/main/java/client/PutIdenticalExample.java
  21. +0 −43 ch04/src/main/java/client/PutListErrorExample1.java
  22. +0 −50 ch04/src/main/java/client/PutListErrorExample2.java
  23. +0 −45 ch04/src/main/java/client/PutListExample.java
  24. +0 −54 ch04/src/main/java/client/PutWriteBufferExample.java
  25. +0 −91 ch04/src/main/java/client/RowLockExample.java
  26. +0 −82 ch04/src/main/java/client/ScanCacheBatchExample.java
  27. +0 −63 ch04/src/main/java/client/ScanExample.java
  28. +0 −59 ch04/src/main/java/client/ScanTimeoutExample.java
  29. +0 −49 ch04/src/main/java/pool/HTablePoolExample.java
  30. +10 −0 hush/pom.xml
  31. +8 −0 pom.xml
View
@@ -16,12 +16,4 @@
<name>HBase Book Chapter 4</name>
- <dependencies>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.5</version>
- </dependency>
- </dependencies>
-
</project>
@@ -1,78 +0,0 @@
-package admin;
-
-// cc ClusterStatusExample Example reporting the status of a cluster
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.ClusterStatus;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.HServerInfo;
-import org.apache.hadoop.hbase.HServerLoad;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.util.Bytes;
-
-import java.io.IOException;
-import java.util.Map;
-
-public class ClusterStatusExample {
-
- public static void main(String[] args) throws IOException, InterruptedException {
- Configuration conf = HBaseConfiguration.create();
-
- // vv ClusterStatusExample
- HBaseAdmin admin = new HBaseAdmin(conf);
-
- ClusterStatus status = admin.getClusterStatus(); // co ClusterStatusExample-1-GetStatus Get the cluster status.
-
- System.out.println("Cluster Status:\n--------------");
- System.out.println("Avg Load: " + status.getAverageLoad());
- System.out.println("HBase Version: " + status.getHBaseVersion());
- System.out.println("Version: " + status.getVersion());
- System.out.println("No. Servers: " + status.getServers());
- System.out.println("No. Dead Servers: " + status.getDeadServers());
- System.out.println("Dead Servers: " + status.getDeadServerNames());
- System.out.println("No. Regions: " + status.getRegionsCount());
- System.out.println("No. Requests: " + status.getRequestsCount());
-
- System.out.println("\nServer Info:\n--------------");
- for (HServerInfo info : status.getServerInfo()) { // co ClusterStatusExample-2-ServerInfo Iterate over the included server info instances.
- System.out.println("Hostname: " + info.getHostname());
- System.out.println("RPC Port: " + info.getHostnamePort());
- System.out.println("Servername: " + info.getServerName());
- System.out.println("Info Port: " + info.getInfoPort());
- System.out.println("Address: " + info.getServerAddress());
- System.out.println("Start Code: " + info.getStartCode());
-
- HServerLoad load = info.getLoad(); // co ClusterStatusExample-3-ServerLoad Retrieve the load details for the current server.
-
- System.out.println("\nServer Load:\n--------------");
- System.out.println("Load: " + load.getLoad());
- System.out.println("Max Heap (MB): " + load.getMaxHeapMB());
- System.out.println("Memstore Size (MB): " + load.getMemStoreSizeInMB());
- System.out.println("No. Regions: " + load.getNumberOfRegions());
- System.out.println("No. Requests: " + load.getNumberOfRequests());
- System.out.println("Storefile Index Size (MB): " + load.getStorefileIndexSizeInMB());
- System.out.println("No. Storefiles: " + load.getStorefiles());
- System.out.println("Storefile Size (MB): " + load.getStorefileSizeInMB());
- System.out.println("Used Heap (MB): " + load.getUsedHeapMB());
-
- System.out.println("\nRegion Load:\n--------------");
- for (Map.Entry<byte[], HServerLoad.RegionLoad> entry : // co ClusterStatusExample-4-Regions Iterate over the region details of the current server.
- load.getRegionsLoad().entrySet()) {
- System.out.println("Region: " + Bytes.toStringBinary(entry.getKey()));
-
- HServerLoad.RegionLoad regionLoad = entry.getValue(); // co ClusterStatusExample-5-RegionLoad Get the load details for the current region.
-
- System.out.println("Name: " + Bytes.toStringBinary(regionLoad.getName()));
- System.out.println("No. Stores: " + regionLoad.getStores());
- System.out.println("No. Storefiles: " + regionLoad.getStorefiles());
- System.out.println("Storefile Size (MB): " + regionLoad.getStorefileSizeMB());
- System.out.println("Storefile Index Size (MB): " + regionLoad.getStorefileIndexSizeMB());
- System.out.println("Memstore Size (MB): " + regionLoad.getMemStoreSizeMB());
- System.out.println("No. Requests: " + regionLoad.getRequestsCount());
- System.out.println("No. Read Requests: " + regionLoad.getReadRequestsCount());
- System.out.println("No. Write Requests: " + regionLoad.getWriteRequestsCount());
- System.out.println();
- }
- }
- // ^^ ClusterStatusExample
- }
-}
@@ -1,39 +0,0 @@
-package admin;
-
-// cc CreateTableExample Example using the administrative API to create a table
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.HColumnDescriptor;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.util.Bytes;
-import util.HBaseHelper;
-
-import java.io.IOException;
-
-public class CreateTableExample {
-
- public static void main(String[] args) throws IOException, InterruptedException {
- // vv CreateTableExample
- Configuration conf = HBaseConfiguration.create();
- // ^^ CreateTableExample
- HBaseHelper helper = HBaseHelper.getHelper(conf);
- helper.dropTable("testtable");
- // vv CreateTableExample
-
- HBaseAdmin admin = new HBaseAdmin(conf); // co CreateTableExample-1-CreateAdmin Create a administrative API instance.
-
- HTableDescriptor desc = new HTableDescriptor( // co CreateTableExample-2-CreateHTD Create the table descriptor instance.
- Bytes.toBytes("testtable"));
-
- HColumnDescriptor coldef = new HColumnDescriptor( // co CreateTableExample-3-CreateHCD Create a column family descriptor and add it to the table descriptor.
- Bytes.toBytes("colfam1"));
- desc.addFamily(coldef);
-
- admin.createTable(desc); // co CreateTableExample-4-CreateTable Call the createTable() method to do the actual work.
-
- boolean avail = admin.isTableAvailable(Bytes.toBytes("testtable")); // co CreateTableExample-5-Check Check if the table is available.
- System.out.println("Table available: " + avail);
- // ^^ CreateTableExample
- }
-}
@@ -1,69 +0,0 @@
-package admin;
-
-// cc CreateTableWithRegionsExample Example using the administrative API to create a table with predefined regions
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.HColumnDescriptor;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.client.HTable;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.Pair;
-import util.HBaseHelper;
-
-import java.io.IOException;
-
-public class CreateTableWithRegionsExample {
-
- // vv CreateTableWithRegionsExample
- private static void printTableRegions(String tableName) throws IOException { // co CreateTableWithRegionsExample-1-PrintTable Helper method to print the regions of a table.
- System.out.println("Printing regions of table: " + tableName);
- HTable table = new HTable(Bytes.toBytes(tableName));
- Pair<byte[][], byte[][]> pair = table.getStartEndKeys(); // co CreateTableWithRegionsExample-2-GetKeys Retrieve the start and end keys from the newly created table.
- for (int n = 0; n < pair.getFirst().length; n++) {
- byte[] sk = pair.getFirst()[n];
- byte[] ek = pair.getSecond()[n];
- System.out.println("[" + (n + 1) + "]" +
- " start key: " +
- (sk.length == 8 ? Bytes.toLong(sk) : Bytes.toStringBinary(sk)) + // co CreateTableWithRegionsExample-3-Print Print the key, but guarding against the empty start (and end) key.
- ", end key: " +
- (ek.length == 8 ? Bytes.toLong(ek) : Bytes.toStringBinary(ek)));
- }
- }
- // ^^ CreateTableWithRegionsExample
-
- // vv CreateTableWithRegionsExample
- public static void main(String[] args) throws IOException, InterruptedException {
- Configuration conf = HBaseConfiguration.create();
- // ^^ CreateTableWithRegionsExample
-
- HBaseHelper helper = HBaseHelper.getHelper(conf);
- helper.dropTable("testtable1");
- helper.dropTable("testtable2");
-
- // vv CreateTableWithRegionsExample
- HBaseAdmin admin = new HBaseAdmin(conf);
-
- HTableDescriptor desc = new HTableDescriptor(
- Bytes.toBytes("testtable1"));
- HColumnDescriptor coldef = new HColumnDescriptor(
- Bytes.toBytes("colfam1"));
- desc.addFamily(coldef);
-
- admin.createTable(desc/*[*/, Bytes.toBytes(1L), Bytes.toBytes(100L), 10/*]*/); // co CreateTableWithRegionsExample-4-CreateTable1 Call the createTable() method while also specifying the region boundaries.
- printTableRegions("testtable1");
-
- byte[][] regions = new byte[][] { // co CreateTableWithRegionsExample-5-Regions Manually create region split keys.
- Bytes.toBytes("A"),
- Bytes.toBytes("D"),
- Bytes.toBytes("G"),
- Bytes.toBytes("K"),
- Bytes.toBytes("O"),
- Bytes.toBytes("T")
- };
- desc.setName(Bytes.toBytes("testtable2"));
- admin.createTable(desc, regions); // co CreateTableWithRegionsExample-6-CreateTable2 Call the crateTable() method again, with a new table name and the list of region split keys.
- printTableRegions("testtable2");
- }
- // ^^ CreateTableWithRegionsExample
-}
@@ -1,52 +0,0 @@
-package admin;
-
-// cc ListTablesExample Example listing the existing tables and their descriptors
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.util.Bytes;
-import util.HBaseHelper;
-
-import java.io.IOException;
-
-public class ListTablesExample {
-
- public static void main(String[] args) throws IOException, InterruptedException {
- Configuration conf = HBaseConfiguration.create();
-
- HBaseHelper helper = HBaseHelper.getHelper(conf);
- helper.dropTable("testtable1");
- helper.dropTable("testtable2");
- helper.dropTable("testtable3");
- helper.createTable("testtable1", "colfam1", "colfam2", "colfam3");
- helper.createTable("testtable2", "colfam1", "colfam2", "colfam3");
- helper.createTable("testtable3", "colfam1", "colfam2", "colfam3");
-
- // vv ListTablesExample
- HBaseAdmin admin = new HBaseAdmin(conf);
-
- HTableDescriptor[] htds = admin.listTables();
- // ^^ ListTablesExample
- System.out.println("Printing all tables...");
- // vv ListTablesExample
- for (HTableDescriptor htd : htds) {
- System.out.println(htd);
- }
-
- HTableDescriptor htd1 = admin.getTableDescriptor(
- Bytes.toBytes("testtable1"));
- // ^^ ListTablesExample
- System.out.println("Printing testtable1...");
- // vv ListTablesExample
- System.out.println(htd1);
-
- HTableDescriptor htd2 = admin.getTableDescriptor(
- Bytes.toBytes("testtable10"));
- // ^^ ListTablesExample
- System.out.println("Printing testtable10...");
- // vv ListTablesExample
- System.out.println(htd2);
- // ^^ ListTablesExample
- }
-}
@@ -1,46 +0,0 @@
-package admin;
-
-// cc ModifyTableExample Example modifying the structure of an existing table
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.HColumnDescriptor;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.util.Bytes;
-import util.HBaseHelper;
-
-import java.io.IOException;
-
-public class ModifyTableExample {
-
- public static void main(String[] args) throws IOException, InterruptedException {
- Configuration conf = HBaseConfiguration.create();
-
- HBaseHelper helper = HBaseHelper.getHelper(conf);
- helper.dropTable("testtable");
- // vv ModifyTableExample
- byte[] name = Bytes.toBytes("testtable");
- HBaseAdmin admin = new HBaseAdmin(conf);
- HTableDescriptor desc = new HTableDescriptor(name);
- HColumnDescriptor coldef1 = new HColumnDescriptor(
- Bytes.toBytes("colfam1"));
- desc.addFamily(coldef1);
-
- admin.createTable(desc); // co ModifyTableExample-1-CreateTable Create the table with the original structure.
-
- HTableDescriptor htd1 = admin.getTableDescriptor(name); // co ModifyTableExample-2-SchemaUpdate Get schema, update by adding a new family and changing the maximum file size property.
- HColumnDescriptor coldef2 = new HColumnDescriptor(
- Bytes.toBytes("colfam2"));
- htd1.addFamily(coldef2);
- htd1.setMaxFileSize(1024 * 1024 * 1024L);
-
- admin.disableTable(name);
- admin.modifyTable(name, htd1); // co ModifyTableExample-3-ChangeTable Disable, modify, and enable the table.
- admin.enableTable(name);
-
- HTableDescriptor htd2 = admin.getTableDescriptor(name);
- System.out.println("Equals: " + htd1.equals(htd2)); // co ModifyTableExample-4-Verify Check if the table schema matches the new one created locally.
- System.out.println("New schema: " + htd2);
- // ^^ ModifyTableExample
- }
-}
@@ -1,70 +0,0 @@
-package admin;
-
-// cc TableOperationsExample Example using the various calls to disable, enable, and check that status of a table
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.HColumnDescriptor;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.util.Bytes;
-import util.HBaseHelper;
-
-import java.io.IOException;
-
-public class TableOperationsExample {
-
- public static void main(String[] args) throws IOException, InterruptedException {
- Configuration conf = HBaseConfiguration.create();
-
- HBaseHelper helper = HBaseHelper.getHelper(conf);
- helper.dropTable("testtable");
-
- // vv TableOperationsExample
- HBaseAdmin admin = new HBaseAdmin(conf);
-
- HTableDescriptor desc = new HTableDescriptor(
- Bytes.toBytes("testtable"));
- HColumnDescriptor coldef = new HColumnDescriptor(
- Bytes.toBytes("colfam1"));
- desc.addFamily(coldef);
- // ^^ TableOperationsExample
- System.out.println("Creating table...");
- // vv TableOperationsExample
- admin.createTable(desc);
-
- // ^^ TableOperationsExample
- System.out.println("Deleting enabled table...");
- // vv TableOperationsExample
- try {
- admin.deleteTable(Bytes.toBytes("testtable"));
- } catch (IOException e) {
- System.err.println("Error deleting table: " + e.getMessage());
- }
-
- // ^^ TableOperationsExample
- System.out.println("Disabling table...");
- // vv TableOperationsExample
- admin.disableTable(Bytes.toBytes("testtable"));
- boolean isDisabled = admin.isTableDisabled(Bytes.toBytes("testtable"));
- System.out.println("Table is disabled: " + isDisabled);
-
- boolean avail1 = admin.isTableAvailable(Bytes.toBytes("testtable"));
- System.out.println("Table available: " + avail1);
-
- // ^^ TableOperationsExample
- System.out.println("Deleting disabled table...");
- // vv TableOperationsExample
- admin.deleteTable(Bytes.toBytes("testtable"));
-
- boolean avail2 = admin.isTableAvailable(Bytes.toBytes("testtable"));
- System.out.println("Table available: " + avail2);
-
- // ^^ TableOperationsExample
- System.out.println("Creating table again...");
- // vv TableOperationsExample
- admin.createTable(desc);
- boolean isEnabled = admin.isTableEnabled(Bytes.toBytes("testtable"));
- System.out.println("Table is enabled: " + isEnabled);
- // ^^ TableOperationsExample
- }
-}
Oops, something went wrong.

0 comments on commit 4ef467e

Please sign in to comment.