Skip to content

Instantly share code, notes, and snippets.

@camathieu
Created September 16, 2014 10:22
Show Gist options
  • Save camathieu/5ea219faaa1170f11a8f to your computer and use it in GitHub Desktop.
Save camathieu/5ea219faaa1170f11a8f to your computer and use it in GitHub Desktop.
my opentsdb create-table.sh
#!/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
}
PREFIX=$1
TSDB_TABLE="$PREFIX_tsdb"
UID_TABLE="$PREFIX_tsdb-uid"
META_TABLE="$PREFIX_tsdb-meta"
TREE_TABLE="$PREFIX_tsdb-tree"
BLOOMFILTER=${BLOOMFILTER-'ROW'}
MAXFILESIZE=10073741824
COMPRESSION=${COMPRESSION-'LZO'}
# 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
###
# UID TABLE
###
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'
###
# DATA 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'
###
# META TABLE
###
create '$META_TABLE',
{NAME => 'name', COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER'}
diable '$META_TABLE'
alter '$META_TABLE', {METHOD => 'table_att', MAX_FILESIZE => '$MAXFILESIZE'}
enable '$META_TABLE'
###
# TREE TABLE
###
create '$TREE_TABLE',
{NAME => 't', VERSIONS => 1, COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER'}
disable '$TREE_TABLE'
alter '$TSDB_TABLE', {METHOD => 'table_att', MAX_FILESIZE => '$MAXFILESIZE'}
enable '$TREE_TABLE'
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment