Reputation: 461
I'm trying to interact with a MapR-DB table from a simple Java application that is running within a node of an M3 MapR cluster. It seems that I am able to connect to the cluster but apparently I am not able to connect to the table properly. This is a snippet from the code:
Configuration configuration = new Configuration();
configuration.set("hbase.zookeeper.quorum", "192.168.2.1,192.168.2.2,192.168.2.3");
configuration.set("hbase.zookeeper.property.clientPort", "5181");
configuration.set("mapr.htable.impl", "com.mapr.fs.MapRHTable");
configuration.set("hbase.table.namespace.mappings", "*:/user/mapr/");
configuration = HBaseConfiguration.create(configuration);
HConnection connection = HConnectionManager.createConnection(configuration);
System.out.println("Is Master running? " + connection.isMasterRunning());
String tableName = args[0];
HTable table = (HTable) connection.getTable(tableName.getBytes());
for (HColumnDescriptor columnFamily : table.getTableDescriptor().getColumnFamilies()) {
System.out.println("Column family: " + columnFamily.getNameAsString());
}
I have a table that is called "/user/mapr/test_table" (I see it in the MapR Web Console and I can access it through hbase shell
). Running the code with any reasonable parameter for the table name just returns this exception:
org.apache.hadoop.hbase.TableNotFoundException: /user/mapr/test_table
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getHTableDescriptor(HConnectionManager.java:2750)
at org.apache.hadoop.hbase.client.HTable.getTableDescriptor(HTable.java:701)
at it.noovle.bigdata.hadoop.MaprDBLocalTest.main(MaprDBLocalTest.java:49)
hbase shell
I simply use '/user/mapr/test_table'.Upvotes: 0
Views: 2898
Reputation: 3510
MapR allows you, depending of your installation to use:
The "name" of the table defines if this is a "MapR-DB" or "Hbase" table:
/apps/my_tables/users
users
Then depending of the name of the table the way the client is reaching the cluster varies:
The client code does not change between MapR-DB or Hbase, only the table names and "configuration" change, what I mean for the configuration is:
I have a small project available here
Upvotes: 0
Reputation: 48
To connect to MapR-DB, you don't require to connect to Zookeeper. To open the table you have to provide absolute path. For e.g /user/mapr/test_table. Attaching a simple example below:
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
public class HBaseExample {
public static void main(String[] args) throws IOException {
Configuration config = HBaseConfiguration.create();
HTable table = new HTable(config, "/user/mapr/test_table");
Put p = new Put(Bytes.toBytes("row1"));
p.add(Bytes.toBytes("cf1"), Bytes.toBytes("col2"),
Bytes.toBytes("ABC"));
table.put(p);
Get g = new Get(Bytes.toBytes("row1"));
Result r = table.get(g);
byte[] value = r.getValue(Bytes.toBytes("cf1"),
Bytes.toBytes("col2"));
String valueStr = Bytes.toString(value);
System.out.println("GET: " + valueStr);
Scan s = new Scan();
s.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col2"));
ResultScanner scanner = table.getScanner(s);
try {
for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
System.out.println("Found row: " + rr);
}
} finally {
scanner.close();
}
}
}
Here is the hbase-site.xml, it is taken from MapR sandbox.
-bash-4.1$ cat ./hbase/hbase-0.98.7/conf/hbase-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hbase.rootdir</name>
<value>maprfs:///hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>maprdemo</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>5181</value>
</property>
<property>
<name>dfs.support.append</name>
<value>true</value>
</property>
<property>
<name>hbase.fsutil.maprfs.impl</name>
<value>org.apache.hadoop.hbase.util.FSMapRUtils</value>
</property>
<property>
<name>hbase.regionserver.handler.count</name>
<value>30</value>
<!-- default is 25 -->
</property>
<!-- uncomment this to enable fileclient logging
<property>
<name>fs.mapr.trace</name>
<value>debug</value>
</property>
-->
<!-- Allows file/db client to use 64 threads -->
<property>
<name>fs.mapr.threads</name>
<value>64</value>
</property>
</configuration>
-bash-4.1$
Upvotes: 1