Skip to content

Instantly share code, notes, and snippets.

@johann8384
Last active October 30, 2017 03:23
Show Gist options
  • Save johann8384/5544290 to your computer and use it in GitHub Desktop.
Save johann8384/5544290 to your computer and use it in GitHub Desktop.
Creating Tables for OpenTSDB
# usage: ./create_table.rb tsdb 255
include Java
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.HTableDescriptor
import org.apache.hadoop.hbase.client.HBaseAdmin
import org.apache.hadoop.hbase.HColumnDescriptor
conf = HBaseConfiguration.create
conf.set("zookeeper.znode.parent", "/hbase-unsecure");
tablename = ARGV[0]
regions = ARGV[1].to_i
hcd = HColumnDescriptor.new('t')
#hcd.COMPRESSION="COMPRESSION"
#hcd.BLOOMFILTER="BLOOMFILTER"
htd = HTableDescriptor.new(tablename)
htd.addFamily(hcd)
HBaseAdmin.new(conf).createTable(
htd,
"\x00\x00\x00\x01".to_java_bytes,
"\x00\x00\x1F\x40".to_java_bytes,
regions)
#!/bin/sh
# Small script to setup the HBase tables used by OpenTSDB.
# Taken from git://github.com/stumbleupon/opentsdb.git
# Version: 1.1.0
test -n "$HBASE_HOME" || {
echo >&2 'The environment variable HBASE_HOME must be set'
exit 1
}
test -d "$HBASE_HOME" || {
echo >&2 "No such directory: HBASE_HOME=$HBASE_HOME"
exit 1
}
TSDB_TABLE=${TSDB_TABLE-'tsdb'}
UID_TABLE=${UID_TABLE-'tsdb-uid'}
BLOOMFILTER=${BLOOMFILTER-'ROW'}
MAXFILESIZE=25769803776
COMPRESSION=${COMPRESSION-'SNAPPY'}
# HBase scripts also use a variable named `HBASE_HOME', and having this
# variable in the environment with a value somewhat different from what
# they expect can confuse them in some cases. So rename the variable.
hbh=$HBASE_HOME
unset HBASE_HOME
exec "$hbh/bin/hbase" shell <<EOF
create '$UID_TABLE',
{NAME => 'id', COMPRESSION => '$COMPRESSION', MAX_FILESIZE => '$MAXFILESIZE'},
{NAME => 'name', COMPRESSION => '$COMPRESSION', MAX_FILESIZE => '$MAXFILESIZE'}
disable '$UID_TABLE'
alter '$UID_TABLE', {METHOD => 'table_att', MAX_FILESIZE=>'$MAXFILESIZE'}
enable '$UID_TABLE'
create '$TSDB_TABLE',
{NAME => 't', VERSIONS => 1, COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER', MAX_FILESIZE => '$MAXFILESIZE'}
disable '$TSDB_TABLE'
alter '$TSDB_TABLE', {NAME => 't', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'SNAPPY', TTL => '2147483647', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
alter '$TSDB_TABLE', {METHOD => 'table_att', MAX_FILESIZE => '$MAXFILESIZE'}
enable '$TSDB_TABLE'
EOF
@johann8384
Copy link
Author

Sure, I haven't used 2.1 yet, but I will be soon and I'll let you know

Copy link

ghost commented Jul 22, 2015

Could you please update this script to make it work with OpenTSDB 2.1?

@kramerli
Copy link

Hi

I`m using your script. But I hit a problem. Can you help to look and give some advice? Thanks very much

https://groups.google.com/forum/#!topic/opentsdb/B3Yodf-cxV0

Here is the link to my question

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