HBase & thrift & C++緙栫▼_PHP教程

來源:互聯網
上載者:User

HBase & thrift & C++緙栫▼


HBase & thrift & C++緙栫▼.pdf

鐩綍

鐩綍1

1.鍓嶈█1

2.鍚姩鍜屽仠姝?span>thrift2 1

2.1.鍚姩thrift2 1

2.2.鍋滄thrift2 1

2.3.鍚姩鍙傛暟2

3.hbase.thrift2

3.1.緙栬瘧hbase.thrift 2

4.thrift_helper.h3

5.紺轟緥浠g爜4

1.鍓嶈█

鏈枃鐩殑鏄粙緇嶄嬌鐢?span>C++濡備綍鎿嶄綔HBase銆備粠HBase0.94寮€濮嬶紝HBase鏂板thrift2錛屾湰鏂囧彧浠嬬粛鍜岃璁?/span>thrift2鐩稿叧鐨勩€?/span>hbase-1.1.2浣跨敤鐨?/span>thrift浼拌鏄?/span>thrift-0.9.0鐗堟湰銆?

2.鍚姩鍜屽仠姝?span>thrift2

2.1.鍚姩thrift2

鐧誨綍HBasemaster鏈哄櫒錛屾墽琛屼互涓嬪懡浠ゅ惎鍔?/span>thrift2錛?/span>hbase-daemon.shstartthrift2銆?

thrift榛樿鐨勭洃鍚鍙f槸9090錛屽彲浠ラ€氳繃鍙傛暟鈥?span>-p鈥濇寚瀹氬叾瀹冪鍙c€傞粯璁や嬌鐢ㄧ殑Server鏄?/span>TThreadPoolServer銆傞粯璁や嬌鐢ㄧ殑Protocol鏄?/span>TBinaryProtocol銆?/span>

娉ㄦ剰瀹㈡埛絝嬌鐢ㄧ殑Protocol鍜?/span>Transport鍜屾湇鍔$鐨勮淇濇寔涓€鑷達紝鍚﹀墶瀹㈡埛絝湪璋冪敤鏃訛紝鍙兘閬囧埌鈥淓AGAIN(timedout)鈥濈瓑閿欒銆?

2.2.鍋滄thrift2

hbase-daemon.shstopthrift2

2.3.鍚姩鍙傛暟

浣跨敤鈥渉base-daemon.shstartthrift2鈥濇椂錛岃繕鍙互甯︿互涓嬪弬鏁幫細

鍙傛暟鍚?/span>

鏄惁榛樿

鍙傛暟璿存槑

-h,--help

鏄劇ず甯姪淇℃伅

-b,--bind

緇戝畾鎸囧畾鍦板潃錛屼絾涓嶆敮鎸?span>TNonblockingServer鍜?/span>THsHaServer錛屼袱鑰呮€繪槸浣跨敤鈥?/span>0.0.0.0鈥?/span>

-p,--port

9090

緇戝鎸囧畾絝彛錛岄粯璁や負9090

-f,--framed

浣跨敤TFramedTransport

-c,--compact

浣跨敤TCompactProtocol錛岄粯璁ゆ槸TBinaryProtocol

-threadpool

鏄?/span>

浣跨敤TThreadPoolServer錛屼負榛樿Server

-nonblocking

浣跨敤瀹炵幇浜?span>FramedTransport鐨?/span>TNonblockingServer

-hsha

浣跨敤瀹炵幇浜?span>FramedTransport鐨?/span>THsHaServer

瀹㈡埛絝拰hbasethrift2鐨?/span>Transport鍜?/span>Protocol闇€淇濇寔涓€鑷達紝姣斿瀹㈡埛絝負FramedTransport錛屽墶涔熼渶浠モ€?/span>-f鈥濆惎鍔?/span>hbasethrift2銆?/span>

鍚﹀墶瀹㈡埛絝湪璋冪敤鏃訛紝鍙兘浼氶亣鍒扳€淓AGAIN(timedout)鈥濈瓑閿欒銆?

鍚姩鍙傛暟淇℃伅鏉ユ簮浜庡畼緗戠殑欏甸潰錛?

https://hbase.apache.org/devapidocs/org/apache/hadoop/hbase/thrift2/package-summary.html銆?

浠ヤ笂鍙傛暟涓嶆槸緇?span>hbase-daemon.sh浣跨敤錛岃€屾槸琚?/span>hbasethrift2浣跨敤錛屽彲浠ユ祻瑙堢溮鍏蟲簮浠g爜浜嗚В緇嗚妭錛?/span>

hbase-thrift\src\main\java\org\apache\hadoop\hbase\thrift2\ThriftServer.java

hbase-thrift\src\main\java\org\apache\hadoop\hbase\thrift2\ThriftHBaseServiceHandler.java

?鍚姩紺轟緥錛?

hbase-daemon.shstartthrift2--framed-nonblocking

3.hbase.thrift

hbaser.thrift鏂囦歡鍦?/span>hbase婧愪唬鐮佸寘錛堜互hbase-1.1.2涓轟緥錛変腑鐨勪綅緗細

hbase-thrift\src\main\resources\org\apache\hadoop\hbase\thrift2\hbase.thrift

3.1.緙栬瘧hbase.thrift

淇濇寔鏈哄櫒涓婂凡瀹夎濂?span>thrift錛堢粡嫻嬭瘯hbase-1.1.2鍜?/span>thrift-0.9.0鍏煎錛夛紝鐒跺悗浣跨敤涓嬪垪鍛戒護緙栬瘧錛?/span>thrift--gencpp-out.hbase.thrift錛岀紪璿戞垚鍔熷悗錛屼細鍦ㄢ€?span>-out鈥濇寚瀹氱殑鐩綍涓嬬敓鎴愪互涓嬩簲涓枃浠訛細

THBaseService.h

THBaseService.cpp

hbase_types.h

hbase_types.cpp

hbase_constants.h

hbase_constants.cpp

鍏朵腑渚涘鎴風浣跨敤鐨勬槸浣嶄簬鏂囦歡THBaseService.h涓殑綾?/span>THBaseServiceClient銆?

4.thrift_helper.h

涓轟簡綆€鍖?span>C++瀹㈡埛絝殑緙栫▼錛屽彲浠ヤ嬌鐢?/span>thrift_helper.h錛?/span>

https://github.com/eyjian/mooon/blob/master/common_library/include/mooon/net/thrift_helper.h錛屽畠鍙互甯姪綆€鍖栧HBasethrift2鐨勮皟鐢細

//thrift瀹㈡埛絝緟鍔╃被

//

//浣跨敤紺轟緥錛?/span>

//mooon::net::CThriftClientHelperclient(rpc_server_ip,rpc_server_port);

//try

//{

//client.connect();

//client->foo();

//}

//catch(apache::thrift::transport::TTransportException&ex)

//{

//MYLOG_ERROR("thriftexception:(%d)%s\n",ex.getType(),ex.what());

//}

//catch(apache::thrift::transport::TApplicationException&ex)

//{

//MYLOG_ERROR("thriftexception:%s\n",ex.what());

//}

//catch(apache::thrift::TException&ex)

//{

//MYLOG_ERROR("thriftexception:%s\n",ex.what());

//}

//Transport闄ら粯璁ょ殑TFramedTransport(TBufferTransports.h)錛岃繕鍙€夋嫨錛?/span>

//TBufferedTransport(TBufferTransports.h)

//THttpTransport

//TZlibTransport

//TFDTransport(TSimpleFileTransport)

//

//Protocol闄ら粯璁ょ殑apache::thrift::protocol::TBinaryProtocol錛岃繕鍙€夋嫨錛?/span>

//TCompactProtocol

//TJSONProtocol

//TDebugProtocol

template

classProtocol=apache::thrift::protocol::TBinaryProtocol,

classTransport=apache::thrift::transport::TFramedTransport>

classCThriftClientHelper

5.紺轟緥浠g爜

//HBasethrift2C++緙栫▼紺轟緥

#include"THBaseService.h"

#include//PRIu64

#include

#include

#include

//璿鋒敞鎰忓鎴風浣跨敤鐨則hrift鐨凾ransport鍜孭rotocol瑕佸拰hbasethrift2鏈嶅姟絝繚鎸佷竴鑷達紝

//鍚﹀墶璋冪敤鏃訛紝鍙兘鎬繪槸鎶ヨ秴鏃訛紝鎴栧叾瀹冮敊璿紒錛侊紒

//

//榪愯涔嬪墠錛岃閫氳繃HBaseshell鍒涘緩濂借〃錛歝reate'test','cf1','cf2'

//鎴栨寚瀹氱増鏈暟錛歝reate'test',{NAME=>'cf1',VERSIONS=>2},{NAME=>'cf2',VERSIONS=>3}

//鍒犻櫎琛紝鎸夐『搴忔墽琛屼互涓嬩袱鏉Baseshell鍛戒護錛?/span>

//disable'test'

//drop'test'

STRING_ARG_DEFINE(hbase_ip,"192.168.0.1","hbasethriftip");

INTEGER_ARG_DEFINE(uint16_t,hbase_port,9090,1000,50000,"hbasethriftport");

intmain(intargc,char*argv[])

{

std::stringerrmsg;

if(!mooon::utils::parse_arguments(argc,argv,&errmsg))

{

fprintf(stderr,"parametererror:%s\n",errmsg.c_str());

exit(1);

}

usingnamespaceapache;

usingnamespaceapache::hadoop;

std::stringhbase_ip=mooon::argument::hbase_ip->value();

uint16_thbase_port=mooon::argument::hbase_port->value();

mooon::net::CThriftClientHelperhbase_client(hbase_ip,hbase_port);

try

{

hbase_client.connect();//榪炴帴hbasethrift2server

fprintf(stdout,"connect%s:%dok\n",hbase_ip.c_str(),hbase_port);

std::stringtablename="test";//琛ㄥ悕錛岀‘淇濊繍琛屼箣鍓嶅凡鍒涘緩濂?/span>

std::stringrowkey="row1";//琛孠ey

std::stringfamily="cf1";//渚嬫棌鍚?/span>

std::stringcolumnname="f1";//渚嬪悕

std::stringcolumnvalue="value1";//渚嬪€?/span>

//鎻掑靉鍙傛暟璁劇疆

std::vectorcolumns_value(1);

columns_value[0].__set_family(family);

columns_value[0].__set_qualifier(columnname);

columns_value[0].__set_value(columnvalue);

hbase::thrift2::TPutput;

put.__set_row(rowkey);

put.__set_columnValues(columns_value);

hbase_client->put(tablename,put);//鎻掑靉錛屽嚭閿欐姏寮傚父hbase::thrift2::TIOError

//鏌ヨ鍙傛暟璁劇疆

hbase::thrift2::TGetinput;

input.__set_row(rowkey);

hbase::thrift2::TResultresult;//鏌ヨ緇撴灉瀛樻斁鍦ㄨ繖閲?/span>

hbase_client->get(result,tablename,input);//鏌ヨ錛屽嚭閿欐姏寮傚父hbase::thrift2::TIOError

//鏄劇ず鏌ヨ緇撴灉

for(inti=0;i(result.columnValues.size());++i)

{

consthbase::thrift2::TColumnValue&column_value_ref=result.columnValues[i];

fprintf(stdout,"family[%s]/qualifier[%s]/timestamp[%"PRIu64"]:%s\n",column_value_ref.family.c_str(),

column_value_ref.qualifier.c_str(),

column_value_ref.timestamp,

column_value_ref.value.c_str());

}

}

catch(hbase::thrift2::TIOError&ex)

{

fprintf(stderr,"IOError:%s\n",ex.what());

}

catch(apache::thrift::transport::TTransportException&ex)

{

//濡傛灉鍜屾湇鍔$鐨凾ransport鍜孭rotocol涓嶅悓錛岃繖閲岀殑閿欒鏄€淓AGAIN(timedout)鈥?/span>

fprintf(stderr,"(%d)%s\n",ex.getType(),ex.what());

}

catch(apache::thrift::TApplicationException&ex)

{

fprintf(stderr,"%s\n",ex.what());

}

catch(thrift::TException&ex)

{

fprintf(stderr,"%s\n",ex.what());

}

return0;

}

http://www.bkjia.com/PHPjc/1096388.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1096388.htmlTechArticleHBase C++緙栫▼ HBase thrift C++緙栫▼.pdf 鐩綍 鐩綍1 1.鍓嶈█1 2.鍚姩鍜屽仠姝?span>thrift2 1 2.1.鍚姩thrift2 1 2.2.鍋滄thrift2 1 2.3.鍚姩鍙...

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.