OpenTSDB源码分析之TSDB-UID表操作(修改)

为了方便研究将tsdb-uid表的修改操作抽取出来,代码如下:

package net.opentsdb.tools;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;

import net.opentsdb.core.TSDB;
import net.opentsdb.uid.NoSuchUniqueName;
import net.opentsdb.utils.Config;

import org.hbase.async.DeleteRequest;
import org.hbase.async.GetRequest;
import org.hbase.async.HBaseClient;
import org.hbase.async.HBaseException;
import org.hbase.async.KeyValue;
import org.hbase.async.PutRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.stumbleupon.async.Callback;
import com.stumbleupon.async.Deferred;

public class TestTsdbuidModify {

	private static final Logger LOG = LoggerFactory.getLogger(TestTsdbuidModify.class);

	private static final Charset CHARSET = Charset.forName("ISO-8859-1");
	private static final byte[] ID_FAMILY = toBytes("id");
	private static final byte[] NAME_FAMILY = toBytes("name");
	private static final short MAX_ATTEMPTS_PUT = 6;
	private static final short INITIAL_EXP_BACKOFF_DELAY = 800;

	private final HBaseClient client;
	private final byte[] table;
	private final byte[] kind;
	private final short id_width;

	private final ConcurrentHashMap<String, byte[]> name_cache = new ConcurrentHashMap<String, byte[]>();
	private final ConcurrentHashMap<String, String> id_cache = new ConcurrentHashMap<String, String>();

	private volatile int cache_hits;
	private volatile int cache_misses;

	public TestTsdbuidModify(final HBaseClient client, final byte[] table, final String kind, final int width) {
		this.client = client;
		this.table = table;
		if (kind.isEmpty()) {
			throw new IllegalArgumentException("Empty string as 'kind' argument!");
		}
		this.kind = toBytes(kind);
		if (width < 1 || width > 8) {
			throw new IllegalArgumentException("Invalid width: " + width);
		}
		this.id_width = (short) width;
	}

	public static void main(String[] args) throws Exception {
		args = new String[] { "rename", "metrics", "a1", "m1" };

		ArgP argp = new ArgP();
		CliOptions.addCommon(argp);
		CliOptions.addVerbose(argp);
		argp.addOption("--idwidth", "N", "Number of bytes on which the UniqueId is encoded.");
		argp.addOption("--ignore-case", "Ignore case distinctions when matching a regexp.");
		argp.addOption("-i
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值