user7639713
user7639713

Reputation: 46

HBase Connection Timeout Issue with Java API on CentOS 8

I have installed the following on CentOS 8 with IP 192.168.142.131:

Zookeeper: 3.4.6 Hadoop: 3.1.3 HBase: 2.4.5 The firewall has been disabled, and I’m using OpenJDK version 1.8.0_312.

Configuration Files Zookeeper (zoo.cfg):

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/tmp/zookeeper
clientPort=2181

Hadoop (hdfs-site.xml):

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
   <property>
       <name>dfs.replication</name>
       <value>1</value>
   </property>
</configuration>

HBase (hbase-site.xml):

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>hbase.zookeeper.quorum</name>
        <value>192.168.142.131:2181</value>
    </property>
    <property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
    </property>
    <property>
        <name>hbase.tmp.dir</name>
        <value>./tmp</value>
    </property>
    <property>
        <name>hbase.unsafe.stream.capability.enforce</name>
        <value>false</value>
    </property>
    <property>
        <name>hbase.rootdir</name>
        <value>file:///usr/local/hbase/rootdir</value>
    </property>
    <property>
        <name>hbase.zookeeper.property.dataDir</name>
        <value>/home/zookeeper/hbaseDir</value>
    </property>
</configuration>

Status Check When I start the services, they run without issues:

[root@bogon bin]# jps
3297 SecondaryNameNode
5570 Jps
3061 DataNode
3574 ResourceManager
2601 QuorumPeerMain
3757 NodeManager
4381 HMaster
4558 HRegionServer
2879 NameNode

Issue However, when I attempt to connect to HBase using a Java API, I encounter the following error:

Caused by: java.net.SocketTimeoutException: callTimeout=60000, callDuration=60496: row 'my_table,,' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=bogon,16020,1730188790503, seqNum=0

Java API Code

Here’s the Java code I am using to connect to HBase:

package com.example.demo;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import java.io.IOException;

public class HBaseRemoteAPI {
    public static void main(String[] args) {
        Configuration config = HBaseConfiguration.create();
        config.set("hbase.zookeeper.quorum", "192.168.142.131");
        config.set("hbase.zookeeper.property.clientPort", "2181");
        
        try (Connection connection = ConnectionFactory.createConnection(config)) {
            Admin admin = connection.getAdmin();
            TableName tableName = TableName.valueOf("my_table");
            String columnFamily = "deviceInfo";
            if (!admin.tableExists(tableName)) {
                HTableDescriptor tableDescriptor = new HTableDescriptor(tableName);
                tableDescriptor.addFamily(new HColumnDescriptor(columnFamily));
                admin.createTable(tableDescriptor);
                System.out.println("Table created successfully.");
            } else {
                System.out.println("Table already exists.");
            }
        } catch (IOException e) {
            System.err.println("IOException: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

Questions

1.What could be causing the SocketTimeoutException when connecting to HBase? 2.Are there any configuration settings I should check or adjust? Thank you for your help!

Upvotes: 0

Views: 22

Answers (0)

Related Questions