Home > other >  Java access Hbase thrown exception? For some reason
Java access Hbase thrown exception? For some reason

Time:10-04

Package com. Aspire;
Import the Java. IO. BufferedReader;
Import the Java. IO. The File;
Import the Java. IO. FileNotFoundException;
Import the Java. IO. FileReader;
Import the Java. IO. IOException;
Import the Java. Util. ArrayList;
import java.util.List;

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. Client. HTableInterface;
Import org, apache hadoop. Hbase. Client. HTablePool;

Import org, apache hadoop. Hbase. Client. Put;
Import org, apache hadoop. Hbase. Ipc. HBaseClient;

@ SuppressWarnings ({" unused ", "deprecation"})
Public class Test {
Public static Configuration conf=HBaseConfiguration. The create ();
The static {
The Configuration HBASE_CONFIG=new Configuration ();

//HBASE_CONFIG. Set (" hbase. Zookeeper. Quorum ", "ugcserver3, ugcserver4, ugcserver5");
HBASE_CONFIG. Set (" hbase. Zookeeper. Property. ClientPort ", "2181");
The conf=HBaseConfiguration. Create (HBASE_CONFIG);

}
Public static void creatTable (String tableName, String [] familys)
Throws the Exception {
HBaseAdmin admin=new HBaseAdmin (conf);
If (admin. TableExists (tableName)) {
System. Out.println (" table already exists!" );
} else {
System. Out.println (" table not exists!" );
HTableDescriptor tableDesc=new HTableDescriptor (tableName);
For (int I=0; I & lt; Familys. Length; I++) {
TableDesc. AddFamily (new HColumnDescriptor (familys [I]));
}
Admin. CreateTable (tableDesc);
System. The out. Println (" create table "+ tableName +" ok ");
}
}

@ SuppressWarnings (" deprecation ")
Public static void main (String [] args) throws IOException {
If (args==null | | args. The length & lt; 2) {
System. Out.println (" error: the usage & lt; File_name & gt; System. The exit (1);
}

The String filename=args [0].
String splitflag=args [1].
System. The out. Println (filename + "-- -- -- -- --" + splitflag);
String tableName="dmuser";
String [] fa={" basic ", "the features"};
String [] cols={" name ", "BRAND", "PROVINCE", "CITY", "ADDR", "SEX", "AGE", "GROUP_NAME", "the CHILD", "CAR", "WAP_FEATURE_STR
"};
int a=0;

List List=new ArrayList (a);
Try {
Test. CreatTable (tableName, fa);
} the catch (Exception e) {
e.printStackTrace();
}
System. The out. Println (" began to insert the data ");
Long start=System. CurrentTimeMillis ();



HTablePool pool=new HTablePool (conf, 1000);
HTableInterface table=pool. GetTable (tableName);
Table. SetWriteBufferSize (5 * 1024 * 1024);
Table. SetAutoFlush (false);


The File File=new File (filename);
BufferedReader reader=null;
String lineString=null;
Try {
Reader=new BufferedReader (new FileReader (file));
While ((lineString=reader. ReadLine ())!=null) {
+;
String [] lines=lineString. Split (splitflag);
Put the Put=new Put (lines [0]. GetBytes ());
For (int I=1; I & lt; Cols. Length; I++) {
If (cols [I] equals (" WAP_FEATURE_STR ") | | cols [I] equals (" CXP_FEATURE_STR ") | | cols [I] equals (" KEYWORD_STR ")) {
//the continue;
Put the add (fa [1]. GetBytes (), cols [I] getBytes (), lines [I] getBytes ());
} else {
Put the add (fa [0]. GetBytes (), cols [I] getBytes (), lines [I] getBytes ());
}
List. Add (put);
}

If (a % 10000==0) {
Table. The put (list);
List. The clear ();
Table. FlushCommits ();
System. The out. Println (" insert a number: "+ a);
}

}
The pool. The close ();
Reader. The close ();
Table. The close ();
} the catch (FileNotFoundException e) {
e.printStackTrace();
} the catch (IOException e) {
e.printStackTrace();
} the finally {
If (reader!=null) {
Try {
Reader. The close ();
} the catch (IOException e) {
e.printStackTrace();
}
}
}
Long stop=System. CurrentTimeMillis ();
System. The out. Println (" insert data time elapsed: "+ (stop - start) * 1.0/1000 +" s ");
}



}

The above code throw exceptions for:
14/03/18 10:17:23 WARN client. HConnectionManager $HConnectionImplementation: Failed all the from region=dmuser,, 1395108680648. Fb4da06ffd652f7435d927bdbfc6b32c., hostname=BJ - YZ - 103 - r - 63-32, port=60020
Java. Util. Concurrent. ExecutionException: Java. IO. IOException: Call to BJ - YZ - 103 - r - 63-32/192.168.63.32:60020 failed on local exception: Java. IO. EOFException
The at Java. Util. Concurrent. FutureTask $Sync. InnerGet (FutureTask. Java: 252)
At Java. Util. Concurrent. FutureTask. Get (111) FutureTask. Java:
At org, apache hadoop. Hbase. Client. HConnectionManager $HConnectionImplementation. ProcessBatchCallback (HConnectionManager. Java: 1708)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related