Skip to content

Instantly share code, notes, and snippets.

@prasanthkothuri
Last active September 3, 2021 11:31
Show Gist options
  • Save prasanthkothuri/ad600fc30efd037bc14e1e9994bf8b78 to your computer and use it in GitHub Desktop.
Save prasanthkothuri/ad600fc30efd037bc14e1e9994bf8b78 to your computer and use it in GitHub Desktop.

Number of tables in each namespace

# table count per namespace (environment)
echo "NAMESPACE,TABLE_COUNT"
for namespace in $(echo "list_namespace" | hbase shell -n | grep nxcals)
do
table_count=$(echo "list_namespace_tables '$namespace'" | hbase shell -n | wc -l)
echo "$namespace,$table_count"
done

Number of tables in each namespace

echo "list" | hbase shell -n > /tmp/tables.txt
awk -F: 'NR>1{arr[$1]++}END{for (a in arr) print a, arr[a]}' /tmp/tables.txt | sort

Download hbase-operator-tools, scp to the target server and untar

curl -o hbase-operator-tools-1.1.0-bin.tar.gz https://dlcdn.apache.org/hbase/hbase-operator-tools-1.1.0/hbase-operator-tools-1.1.0-bin.tar.gz

Assign a region

Assign a region that is not assigned to any region server (refer hbase web UI -> HBCK Report), the ENCODED_REGIONNAME below is the last bit of the region server, e.g if region server is AFFILIATE_DIM_CACHE:AFFILIATE_DIM_KEYS,,1557740446150.6594d1a17e382bcbf2736707fb712ead then ENCODED_REGIONNAME is 6594d1a17e382bcbf2736707fb712ead

cd `ls -1rtd /var/run/cloudera-scm-agent/process/*hbase* | tail -1`
kinit -kt hbase.keytab hbase/`hostname`@FWTR-IPA.KAZOOTEK.COM
 
/opt/cloudera/parcels/CDH/bin/hbase --config /etc/hbase/conf hbck -j /tmp/hbase/hbase-operator-tools-1.1.0/hbase-hbck2/hbase-hbck2-1.1.0.jar assigns -o 677cee2e421942fb5f1c0c9cb2db377b

Regions stuck in forever Region-In-Transition state

cd `ls -1rtd /var/run/cloudera-scm-agent/process/*hbase* | tail -1`
kinit -kt hbase.keytab hbase/`hostname`@FWTR-IPA.KAZOOTEK.COM
 
# kill all the exclusive locks with the below command (refer hbase web UI -> Procedures & Locks)
/opt/cloudera/parcels/CDH/bin/hbase --config /etc/hbase/conf hbck -j /tmp/hbase/hbase-operator-tools-1.1.0/hbase-hbck2/hbase-hbck2-1.1.0.jar bypass -o -r 145612
 
# set the state to CLOSED if in CLOSING
/opt/cloudera/parcels/CDH/bin/hbase --config /etc/hbase/conf hbck -j /tmp/hbase/hbase-operator-tools-1.1.0/hbase-hbck2/hbase-hbck2-1.1.0.jar setRegionState 677cee2e421942fb5f1c0c9cb2db377b CLOSED
 
# assign the region
/opt/cloudera/parcels/CDH/bin/hbase --config /etc/hbase/conf hbck -j /tmp/hbase/hbase-operator-tools-1.1.0/hbase-hbck2/hbase-hbck2-1.1.0.jar assigns -o 677cee2e421942fb5f1c0c9cb2db377b

Unassign a region

cd `ls -1rtd /var/run/cloudera-scm-agent/process/*hbase* | tail -1`
kinit -kt hbase.keytab hbase/`hostname`@FWTR-IPA.KAZOOTEK.COM
 
/opt/cloudera/parcels/CDH/bin/hbase --config /etc/hbase/conf hbck -j /tmp/hbase/hbase-operator-tools-1.1.0/hbase-hbck2/hbase-hbck2-1.1.0.jar unassigns 677cee2e421942fb5f1c0c9cb2db377b

Hbase:meta region

hbase:meta always have the same encoded region number which is 1588230740, simple operations like assign and unassign can be done as below but for more complex like setregionstate it is better to raise a support ticket

cd `ls -1rtd /var/run/cloudera-scm-agent/process/*hbase* | tail -1`
kinit -kt hbase.keytab hbase/`hostname`@FWTR-IPA.KAZOOTEK.COM
 
/opt/cloudera/parcels/CDH/bin/hbase --config /etc/hbase/conf hbck -j /tmp/hbase/hbase-operator-tools-1.1.0/hbase-hbck2/hbase-hbck2-1.1.0.jar assigns 1588230740
/opt/cloudera/parcels/CDH/bin/hbase --config /etc/hbase/conf hbck -j /tmp/hbase/hbase-operator-tools-1.1.0/hbase-hbck2/hbase-hbck2-1.1.0.jar unassigns 1588230740

Official Documentation

https://github.com/apache/hbase-operator-tools/tree/master/hbase-hbck2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment