In order to repeat this experiment, I met a lot of pits
Https://www.iteblog.com/archives/1889.html
/** * Created by Administrator on 2017/8/18.*/ Public classIteblogbulkloaddriver { Public Static classIteblogbulkloadmapper extends Mapper<longwritable, Text, StringWriter, put> { protected voidmap (longwritable key, Text value, Context context) throws Interruptedexception, IOException {if(value==NULL) { return; } String Line=value.tostring (); string[] Items= Line.split ("\\^"); if(items.length<3) {Items= Line.split ("\\^"); } if(items.length<3) {System. out. println ("================less 3"); return; } System. out. println (line); String RowKey= items[0]+items[1]; Put put=NewPut (Bytes.tobytes (items[0]));//ROWKEYPut.addcolumn ("CF". GetBytes (),"URL". GetBytes (), items[1].getbytes ()); Put.addcolumn ("CF". GetBytes (),"name". GetBytes (), items[2].getbytes ()); Context.write (NewStringWriter (). Append (RowKey), put); } } Public Static classHbasehfilereducer extends Reducer<stringwriter, Put, immutablebyteswritable, put> { protected voidReduce (StringWriter key, iterable<put>values, Context context) throws IOException, interruptedexception {String va Lue=""; Immutablebyteswritable k=Newimmutablebyteswritable (Key.tostring (). GetBytes ()); Put Val=Values.iterator (). Next (); Context.write (K, Val); } } Public Static voidMain (string[] args) throws IOException, ClassNotFoundException, interruptedexception {//String src_path= "hdfs:/slave1:8020/maats5/pay/logdate=20170906";//String desc_path= "hdfs:/slave1:8020/maats5_test/pay/logdate=20170906";String src_path= args[0]; String Desc_path=args[1]; Configuration conf=Hbaseconnectionfactory.config; Conf.Set("Fs.hdfs.impl","Org.apache.hadoop.hdfs.DistributedFileSystem"); Job Job=job.getinstance (conf); Job.setjarbyclass (iteblogbulkloaddriver.class); Job.setmapperclass (iteblogbulkloadmapper.class); Job.setmapoutputkeyclass (StringWriter.class); Job.setmapoutputvalueclass (Put.class); Job.setreducerclass (hbasehfilereducer.class); Job.setoutputformatclass (HFILEOUTPUTFORMAT2.class); htable Table=NewHtable (Conf,"maatstest"); Hfileoutputformat2.configureincrementalload (Job,table,table.getregionlocator ()); Fileinputformat.addinputpath (Job,NewPath (Src_path)); Fileoutputformat.setoutputpath (Job,NewPath (Desc_path)); System.exit (Job.waitforcompletion (true)?0:1); } }
When using the Bulkloader (Loadincrementalhfiles, dobulkload) You can have only add items which are "lexically ordered", ie. You need to make sure and the items you add is sorted by the Row-id.
Https://stackoverflow.com/questions/25860114/hfile-creation-added-a-key-not-lexically-larger-than-previous-key
http://ganliang13.iteye.com/blog/1884921
caused by:java.io.IOException:Added a key not lexically larger than previous.