In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the ways in which HBase coprocessors load". In daily operation, I believe many people have doubts about the way HBase coprocessors load. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the way HBase coprocessors load?" Next, please follow the editor to study!
Three ways of loading HBase coprocessor
Shell loading
1. Upload HDFS
Upload the packaged HelloCoprocessor-0.0.1.jar to the server and put it on HDFS.
# switch hadoop users and create a demo directory
$hdfs dfs-mkdir / usr/hbase/coprocessor
$hdfs dfs-put HelloCoprocessor-0.0.1.jar / usr/hbase/coprocessor
2. Shell loading coprocessor
Let's assume that the package name of its coprocessor class is:
Org.myname.hbase.Coprocessor.RegionObserverExample
The Shell operation is as follows:
Hbase > disable 'mytable' # disable table, optional
Hbase > alter 'mytable', METHOD = >' table_att', 'coprocessor' = >' / usr/hbase/coprocessor/HelloCoprocessor-0.0.1.jar' | org.myname.hbase.Coprocessor.RegionObserverExample | 1001 | arg1=1,arg2=2'
Hbase > enable 'mytable' # enable tables after disabling tables. Optional
The structure is as follows:
Hbase > alter 'mytable', METHOD = >' table_att', 'coprocessor' = > ① | ② | ③ | ④'
Explain the above parameters:
①: coprocessor Jar packet path, to ensure that all RegionServer can be read. It can also be a local path, but it is recommended to put it on HDFS.
②: the full class name of the coprocessor.
③: coprocessor priority, expressed as an integer. Can be empty.
④: the parameter passed to the coprocessor, which can be empty.
Note: there are no spaces between the parameters.
3. Verify that the coprocessor is loaded
Hbase > desc 'mytable'
Table mytable is ENABLE
Mytable, {TABLE_ATTRIBUTES = > {coprocessor$1 = >'/ usr/hbase/coprocessor/HelloCoprocessor-0.0.1.jar' | org.myname.hbase.Coprocessor.RegionObserverExample | 1001 | arg1=1,arg2=2'}}
This verification does not guarantee that the coprocessor will work properly: the shell command does not guarantee that the jar file exists at a specific location, nor does it verify that the given class is actually contained in the jar file.
4. Uninstall coprocessor
Hbase > disable 'mytable' # disable table, optional
Hbase > alter 'mytable', METHOD = >' table_att_unset', NAME = > 'coprocessor$1'
Hbase > enable 'mytable' # enable tables after disabling tables. Optional
Pit: if you modify the coprocessor code and reload the coprocessor without restarting HBase, please rename the coprocessor Jar package, otherwise it will not take effect. Since the current JVM references an existing coprocessor, you must restart JVM by restarting RegionServer in order to replace it. )
Api loading
The specific method is to call the addCoprocessor method of HtableDescriptor. This method has two overloaded methods:
AddCoprocessor (String className)
AddCoprocessor (className,jarPath,priority,kvs)
The second overloaded method provides each parameter ①②③④ needed in the above Shell. Method one requires the user to manually distribute the jar package to the lib directory of each RegionServer.
The sample code is as follows:
TableName tableName = TableName.valueOf ("mytable")
Path path = new Path ("hdfs://:/usr/hbase/coprocessor/HelloCoprocessor-0.0.1.jar")
Configuration conf = HBaseConfiguration.create ()
Connection connection = ConnectionFactory.createConnection (conf)
Admin admin = connection.getAdmin ()
Admin.disableTable (tableName)
HTableDescriptor hTableDescriptor = new HTableDescriptor (tableName)
HColumnDescriptor columnFamily1 = new HColumnDescriptor ("F1")
ColumnFamily1.setMaxVersions (1)
HTableDescriptor.addFamily (columnFamily1)
HColumnDescriptor columnFamily2 = new HColumnDescriptor ("f2")
ColumnFamily2.setMaxVersions (3)
HTableDescriptor.addFamily (columnFamily2)
HTableDescriptor.addCoprocessor ('org.myname.hbase.Coprocessor.RegionObserverExample', path
Coprocessor.PRIORITY_USER, null)
Admin.modifyTable (tableName, hTableDescriptor)
Admin.enableTable (tableName)
Reload the table definition without using the addCoprocessor () method to set the value of the coprocessor. This removes any coprocessors attached to the table.
Configuration file loading
1. Modify the configuration file: hbase-site.xml. The configuration items are as follows:
1.1 RegionObservers/Endpoints
Hbase.coprocessor.region.classes
Org.myname.hbase.Coprocessor.RegionObserverExample
1.2 WALObservers
Hbase.coprocessor.wal.classes
Org.myname.hbase.Coprocessor.RegionObserverExample
1.3 MasterObservers
Hbase.coprocessor.master.classes
Org.myname.hbase.Coprocessor.RegionObserverExample
If you want to configure multiple coprocessors at the same time, you can separate the class names of multiple coprocessors with commas.
two。 Add Jar package
Put your code on the classpath of HBase. A simple way is to put jar (which contains the code and all dependencies) in the HBase installation directory lib/.
3. Restarting HBase takes effect.
4. Static unloading
Remove the coprocessor elements, including child elements, from the hbase-site.xml.
Restart HBase.
Delete the coprocessor's JAR file from the classpath or HBase's lib/ directory. (optional)
At this point, the study of "how HBase coprocessors are loaded" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.