<pre name="code" class="html">如果在连接时候zk服务器宕机
To create a client session the application code must provide a connection string containing a comma separated list of host:port pairs, each corresponding to a ZooKeeper server (e.g. "127.0.0.1:4545" or "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"). The ZooKeeper client library will pick an arbitrary server and try to connect to it. If this connection fails, or if the client becomes disconnected from the server for any reason, the client will automatically try the next server in the list, until a connection is (re-)established. 创建一个client session 应用代码必须提供一个连接字符串包含一个逗号分隔的主机:端口 列表, 每个对应到一个ZooKeeper server (e.g. "127.0.0.1:4545" or "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"). ZooKeeper 客户端库 会选择一个任意的server 和尝试连接到它。 如果这个连接失败,或者 如果客户端变的不能连接,客户端会自动 尝试下一个server 在列表里,知道一个连接重新创建。 如果已经连接之后服务器宕机
SessionMovedException. There is an internal exception that is generally not seen by clients called the SessionMovedException. This exception occurs because a request was received on a connection for a session which has been reestablished on a different server. The normal cause of this error is a client that sends a request to a server, but the network packet gets delayed, so the client times out and connects to a new server. When the delayed packet arrives at the first server, the old server detects that the session has moved, and closes the client connection. Clients normally do not see this error since they do not read from those old connections. (Old connections are usually closed.) One situation in which this condition can be seen is when two clients try to reestablish the same connection using a saved session id and password. One of the clients will reestablish the connection and the second client will be disconnected (causing the pair to attempt to re-establish its connection/session indefinitely). SessionMovedException. 有一个内部的异常,那是通常不被客户端请求SessionMovedException 看到。 这个exception 因为 一个请求被接收在一个连接对于一个会话 精被重新建立到一个不同的zk server. 这个错误的通常情况是一个客户端发送一个请求到一个服务器, 但是网络包延时了,因此客户端超时 ,连接到一个新的服务器.当延迟的packet 到达第一个server, old server 检测倒 session 已经移动了,关闭客户端连接。 客户端通常不会看到这个错误 因为它们不会从老的连接读取(老的连接通常是被关闭的) 一种情况是这个状况可以被看到当 2个客户端尝试重建建立相同的连接使用一个保存的会话id和密码。 demo: zjtest7-redis:/root/zk# cat test_zk.pl
use ZooKeeper;
use AnyEvent;
use AE;
use Data::Dumper;
use IO::Socket;
sub check_port {
( $server, $port ) = ('127.0.0.1','3306');
$sock = IO::Socket::INET->new(PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp');
if ($sock)
{return 1}
else
{return 0 };
}; my @ip_list=();
my $zk = ZooKeeper->new(hosts => '1.1.1.1:2181,1.1.1.1:2182,1.1.1.1:2183') ;
#my $zk = ZooKeeper->new(hosts => '1.1.1.1:2182,1.1.1.1:2183') ;
print Dumper($zk);
eval { my $stat = $zk->exists('/mysql/0001');
if ($stat){
$mysql_ip = $zk->get('/mysql/0001');
print $mysql_ip."\n";
}
else{
$mysql_ip = $zk->get('/mysql/0002');
print $mysql_ip."\n";
}; use DBI;
my $database='zjzc';
my $user="zjzc_app";
my $passwd="1234567";
my @arr2=();
my $dbh = DBI->connect("dbi:mysql:database=$database;host=$mysql_ip;port=3306",$user,$passwd,{
RaiseError => 1,
AutoCommit => 0
} ) or die "can't connect to database ". DBI-errstr;
my $hostSql = qq{select id,name from scan; };
my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);
my $selStmt = $dbh->prepare($hostSql);
$selStmt->execute();
$selStmt->bind_columns(undef, \$a1, \$a2);
$selStmt->execute();
while( $selStmt->fetch() )
{ push (@arr2, "$a1 $a2 $a3\n" );
};
print "\@arr2 is @arr2\n";
$dbh->disconnect;
}; 默认连接3个zk server '1.1.1.1:2181,1.1.1.1:2182,1.1.1.1:2183 测试1 关闭 2181 服务器: zjtest7-redis:/root/zk# perl test_zk.pl
$VAR1 = bless( {
'buffer_length' => 2048,
'default_acl' => [
{
'scheme' => 'world',
'id' => 'anyone',
'perms' => 31
}
],
'dispatcher' => bless( {
'ignore_session_events' => 1,
'dispatch_cb' => sub { "DUMMY" },
'channel' => bless( {}, 'ZooKeeper::Channel' ),
'ae_watcher' => bless( do{\(my $o = '¸`ÿp‹ᅡþ欁ᄋ')}, 'EV::IO' ),
'watchers' => {}
}, 'ZooKeeper::Dispatcher::AnyEvent' ),
'timeout' => 10000,
'hosts' => '1.1.1.1:2181,1.1.1.1:2182,1.1.1.1:2183'
}, 'ZooKeeper' );
192.168.32.6
@arr2 is 1 aaabbb
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe
2 cccddeqe zjtest7-redis:/root/zk# perl test_zk.pl
$VAR1 = bless( {
'hosts' => '1.1.1.1:2181,1.1.1.1:2182,1.1.1.1:2183',
'default_acl' => [
{
'perms' => 31,
'id' => 'anyone',
'scheme' => 'world'
}
],
'timeout' => 10000,
'buffer_length' => 2048,
'dispatcher' => bless( {
'watchers' => {},
'dispatch_cb' => sub { "DUMMY" },
'ae_watcher' => bless( do{\(my $o = ' ʂˎྋ샀ž')}, 'EV::IO' ),
'channel' => bless( {}, 'ZooKeeper::Channel' ),
'ignore_session_events' => 1
}, 'ZooKeeper::Dispatcher::AnyEvent' )
}, 'ZooKeeper' ); 此时有可能连接不上,原因为连接到了1.1.1.1:2181 测试2: #my $zk = ZooKeeper->new(hosts => '1.1.1.1:2181,1.1.1.1:2182,1.1.1.1:2183') ;
my $zk = ZooKeeper->new(hosts => '1.1.1.1:2182,1.1.1.1:2183') ; 此时一切正常
												

zk 节点故障 重连机制的更多相关文章

  1. zookeeper 故障重连机制

    一.连接多个服务器,用逗号隔开 如果在连接时候zk服务器宕机 To create a client session the application code must provide a connec ...

  2. zookeeper节点失效重连机制

    http://www.blogjava.net/xylz/archive/2011/12/05/365578.html http://blog.csdn.net/tswisdom/article/de ...

  3. 正确理解IM长连接的心跳及重连机制,并动手实现(有完整IM源码)

    1.引言 说道“心跳”这个词大家都不陌生,当然不是指男女之间的心跳,而是和长连接相关的.顾名思义就是证明是否还活着的依据. 什么场景下需要心跳呢?目前我们接触到的大多是一些基于长连接的应用需要心跳来“ ...

  4. 详细解析kafka之 kafka消费者组与重平衡机制

    消费组组(Consumer group)可以说是kafka很有亮点的一个设计.传统的消息引擎处理模型主要有两种,队列模型,和发布-订阅模型. 队列模型:早期消息处理引擎就是按照队列模型设计的,所谓队列 ...

  5. ActiveMQ的断线重连机制

    断线重连机制是ActiveMQ的高可用性具体体现之一.ActiveMQ提供failover机制去实现断线重连的高可用性,可以使得连接断开之后,不断的重试连接到一个或多个brokerURL. 默认情况下 ...

  6. Zookeeper 重连机制

    Zookeeper 重连机制 public class ZKConnectSessionWatcher implements Watcher { public final static String ...

  7. zk 节点宕机如何处理?

    Zookeeper 本身也是集群,推荐配置不少于 3 个服务器.Zookeeper 自身也要保 证当一个节点宕机时,其他节点会继续提供服务. 如果是一个 Follower 宕机,还有 2 台服务器提供 ...

  8. Dubbo超时和重连机制

    dubbo启动时默认有重试机制和超时机制.超时机制的规则是如果在一定的时间内,provider没有返回,则认为本次调用失败,重试机制在出现调用失败时,会再次调用.如果在配置的调用次数内都失败,则认为此 ...

  9. testng增加失败重跑机制

    注: 以下内容引自 http://www.yeetrack.com/?p=1015 testng增加失败重跑机制 Posted on 2014 年 10 月 31 日 使用Testng框架搭建自动测试 ...

随机推荐

  1. 英特尔发布全新英特尔® INDE 2015工具套件

    2014年10月15日,英特尔发布了全新的英特尔® Integrated Native Developer Experience 2015工具套件(简称英特尔® INDE).该产品提供了一系列最佳工具 ...

  2. Leetcode算法刷题:第112题 Path Sum

    Path Sum 题目 给予一个二叉树,和一个值su,寻找是否有一个从根节点到叶节点的和为su,有则返回True,没有为False.比如: 5 / \ 4 8 / / \ 11 13 4 / \ \ ...

  3. IIS搭建的http文件服务器

    使用C#WebClient类访问(上传/下载/删除/列出文件目录)由IIS搭建的http文件服务器 前言 为什么要写这边博文呢?其实,就是使用C#WebClient类访问由IIS搭建的http文件服务 ...

  4. SQL Server 内存使用量下降问题

    SQL server这个程序是非喜欢内存这东西的.所以它的内存使用量下降,一定是被别人给抢去了.这件事的后果就是SQL Server 变的 非常慢.怎么样才可以让这件事不太容易发生呢? ------- ...

  5. 【转】浏览器中的data类型的Url格式,data:image/png,data:image/jpeg!

    所谓"data"类型的Url格式,是在RFC2397中 提出的,目的对于一些"小"的数据,可以在网页中直接嵌入,而不是从外部文件载入.例如对于img这个Tag, ...

  6. 从setTimeout到浏览器线程机制

    看高性能javascipt 这本书时,看到这么一句话: Putting scripts at the top of the page in this way typically leads to a ...

  7. USACO2016 January Gold Angry Cows

    Angry Cows 题目描述:给出数轴上的\(n\)个整点\((a[i])\),现在要在数轴上选一个位置\(x\)(可以是实数),以及一个半径\(R\),在以\(x\)为中心,半径为\(R\)的范围 ...

  8. 伪造 UDP 包源 IP 地址

    Raw sockets 方式 raw socket 可通过参数  IPV6_HDRINCL 或 IP_HDRINCL 自定义IP头——伪造UDP报文源IP就全靠它了. 限制:从xp sp2之后的所有非 ...

  9. linux分区,文件系统,目录结构概述

    1.Linux中如何表示硬盘,分区 Linux内核读取光驱,硬盘等资源时均通过“设备文件”的形式进行,因此在linux系统中,将硬 盘和分区表示为不同的文件.具体表述形式如下: 硬盘:对于IDE接口的 ...

  10. hdu 4619 Warm up 2_最大独立集

    三个人整个下午都想不出这题 后来看题解,竟然用匈牙利算法的最大独立集,我顿时晕了. 题意:给竖着和横着的方块,除去重叠的,最多能留下几个方块 #include <cstdlib> #inc ...