KeeperErrorCode = ConnectionLoss 问题解决

日志内容如下:

ERROR 19282 — [tor-Framework-0] o.a.c.f.imps.CuratorFrameworkImpl : Background retry gave up
org.apache.curator.CuratorConnectionLossException: KeeperErrorCode = ConnectionLoss

原因:

一般是由于连接还未完成就执行zookeeper的get/create/exsit操作引起的.

解决方法:

利用"CountDownLatch 类 + zookeeper的watcher + zookeeper的getStat" 实现连接完成后再调用.

可防止此错误发生.

示例类如下(为一配置获取类):

import java.util.concurrent.CountDownLatch;
 
 
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.ZooKeeper.States;
import org.apache.zookeeper.data.Stat;
public class Conf{
	public static void waitUntilConnected(ZooKeeper zooKeeper, CountDownLatch connectedLatch) {
        if (States.CONNECTING == zooKeeper.getState()) {
            try {
                connectedLatch.await();
            } catch (InterruptedException e) {
                throw new IllegalStateException(e);
            }
        }
    }
 
    static class ConnectedWatcher implements Watcher {
 
        private CountDownLatch connectedLatch;
 
        ConnectedWatcher(CountDownLatch connectedLatch) {
            this.connectedLatch = connectedLatch;
        }
 
		@Override
		public void process(WatchedEvent event) {
	       if (event.getState() == KeeperState.SyncConnected) {
	           connectedLatch.countDown();
	       }
		}
    }
	static public Conf Instance(){
		if(static_ == null){
			static_ = new Conf();
		}
		return static_;
	}
	public boolean Init(String hostports, int times){
		try{
	        CountDownLatch connectedLatch = new CountDownLatch(1);
	        Watcher watcher = new ConnectedWatcher(connectedLatch);
	        zk_ = new ZooKeeper(hostports, times, watcher);
			waitUntilConnected(zk_, connectedLatch);
		}
		catch(Exception e){
			System.out.println(e);
			return false;
		}
		return true;
	}
	public String Get(String keys){
		String re = "";
		String ppath = "/zookeeper";
		int oldpos = -1;
		int pos = 0;
		while(true){
			pos = keys.indexOf(".", oldpos + 1);
			if(pos < 0){
				ppath += "/";
				String str = keys.substring(oldpos + 1);
				ppath += str;
				break;
			}
			ppath += "/";
			String str = keys.substring(oldpos + 1,  pos);
			ppath += str;
			oldpos = pos;
		}
		Stat stat = new Stat();
	    try{
	    	byte[] b = zk_.getData(ppath, false, stat);    //获取节点的信息及存储的数据
	    	re = new String(b);
	    }
	    catch(Exception e){
	    	System.out.println(e);
	    }
		return re;
	}
	private Conf(){
		
	}
	private ZooKeeper zk_;
	static private Conf static_;
	public static void main(String args[]){
		String hostports = "192.168.1.88:2181,192.168.1.88:2182,192.168.1.88:2183";
		
		Conf.Instance().Init(hostports, 1000);
		
		String str = Conf.Instance().Get("conf.logicpoint.subscriberserverip");
		str = Conf.Instance().Get("conf.logicpoint.subscriberserverport");
		System.out.println(str);
		while(true){
			try{Thread.sleep(100);}
			catch(Exception e){
				
			}
		}
		
	}
}

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
keepererrorcode = connectionloss for /hbase/hbaseid是指在HBase中出现了连接丢失的错误。HBase是一个构建在Hadoop之上的开源分布式数据库,它使用ZooKeeper来管理集群的协调和一致性。在HBase中,/hbase/hbaseid是ZooKeeper的一个znode节点,它存储有关HBase集群唯一标识符的信息。 当出现"keepererrorcode = connectionloss for /hbase/hbaseid"的错误时,意味着在尝试连接到ZooKeeper获取/hbase/hbaseid节点时,连接丢失了。这可能是由于网络问题ZooKeeper节点故障或其他相关问题导致的。 这个错误可能会导致HBase集群处于不稳定状态,因为/hbase/hbaseid节点的信息被视为集群的重要标识符。如果无法获得正确的/hbase/hbaseid信息,一些HBase功能可能无法正常工作,例如表的读写操作、区域分配等。 为了解决这个问题,我们需要首先确认网络连接是否正常,检查ZooKeeper节点是否正常运行,并查看ZooKeeper日志以获得更多详细信息。如果网络和节点都没有问题,则可能需要重新启动HBase集群来恢复连接。 此外,还可以尝试通过增加ZooKeeper的超时设置来避免连接丢失的问题。这样做可以提高连接的容错性,确保在一定时间内可以重新连接到ZooKeeper节点。 总而言之,"keepererrorcode = connectionloss for /hbase/hbaseid"的错误表示HBase无法连接到ZooKeeper获取重要的集群信息,这可能会导致HBase功能异常。通过检查网络连接、ZooKeeper节点状态和调整超时设置等措施,可以解决这个问题并恢复HBase集群的正常运行。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值