本文整理汇总了Java中org.apache.zookeeper.server.ZKDatabase类的典型用法代码示例。如果您正苦于以下问题:Java ZKDatabase类的具体用法?Java ZKDatabase怎么用?Java ZKDatabase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ZKDatabase类属于org.apache.zookeeper.server包,在下文中一共展示了ZKDatabase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shutdownServerInstance
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
static void shutdownServerInstance(ServerCnxnFactory factory,
String hostPort)
{
if (factory != null) {
ZKDatabase zkDb;
{
ZooKeeperServer zs = getServer(factory);
zkDb = zs.getZKDatabase();
}
factory.shutdown();
try {
zkDb.close();
} catch (IOException ie) {
LOG.warn("Error closing logs ", ie);
}
final int PORT = getPort(hostPort);
Assert.assertTrue("waiting for server down",
ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT,
CONNECTION_TIMEOUT));
}
}
示例2: QuorumPeer
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
public QuorumPeer(Map<Long, QuorumServer> quorumPeers, File dataDir,
File dataLogDir, int electionType,
long myid, int tickTime, int initLimit, int syncLimit,
boolean quorumListenOnAllIPs,
ServerCnxnFactory cnxnFactory,
QuorumVerifier quorumConfig) throws IOException {
this();
this.cnxnFactory = cnxnFactory;
this.quorumPeers = quorumPeers;
this.electionType = electionType;
this.myid = myid;
this.tickTime = tickTime;
this.initLimit = initLimit;
this.syncLimit = syncLimit;
this.quorumListenOnAllIPs = quorumListenOnAllIPs;
this.logFactory = new FileTxnSnapLog(dataLogDir, dataDir);
this.zkDb = new ZKDatabase(this.logFactory);
if(quorumConfig == null)
this.quorumConfig = new QuorumMaj(countParticipants(quorumPeers));
else this.quorumConfig = quorumConfig;
}
示例3: shutdownServerInstance
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
static void shutdownServerInstance(ServerCnxnFactory factory,
String hostPort)
{
if (factory != null) {
ZKDatabase zkDb = null;
{
ZooKeeperServer zs = getServer(factory);
if (zs != null) {
zkDb = zs.getZKDatabase();
}
}
factory.shutdown();
try {
if (zkDb != null) {
zkDb.close();
}
} catch (IOException ie) {
LOG.warn("Error closing logs ", ie);
}
final int PORT = getPort(hostPort);
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown("127.0.0.1:" + PORT,
CONNECTION_TIMEOUT));
}
}
示例4: validateRequestLog
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
/**
* Walk through the target peer commmittedLog.
* @param sessionId
* @param peerId
*/
private void validateRequestLog(long sessionId, int peerId) {
String session = Long.toHexString(sessionId);
LOG.info("Searching for txn of session 0x " + session +
" on peer " + peerId);
String peerType = peerId == qb.getLeaderIndex() ? "leader" : "follower";
QuorumPeer peer = qb.getPeerList().get(peerId);
ZKDatabase db = peer.getActiveServer().getZKDatabase();
for (Proposal p : db.getCommittedLog()) {
Assert.assertFalse("Should not see " +
TraceFormatter.op2String(p.request.type) +
" request from local session 0x" + session +
" on the " + peerType,
p.request.sessionId == sessionId);
}
}
示例5: waitForSync
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
/**
* Wait for all server to have the same lastProccessedZxid. Timeout in seconds
*/
private boolean waitForSync(QuorumUtil qu, int index, int timeout) throws InterruptedException{
LOG.info("Wait for server to sync");
int leaderIndex = (index == 1) ? 2 : 1;
ZKDatabase restartedDb = qu.getPeer(index).peer.getActiveServer().getZKDatabase();
ZKDatabase cleanDb = qu.getPeer(3).peer.getActiveServer().getZKDatabase();
ZKDatabase leadDb = qu.getPeer(leaderIndex).peer.getActiveServer().getZKDatabase();
long leadZxid = 0;
long cleanZxid = 0;
long restartedZxid = 0;
for (int i = 0; i < timeout; ++i) {
leadZxid = leadDb.getDataTreeLastProcessedZxid();
cleanZxid = cleanDb.getDataTreeLastProcessedZxid();
restartedZxid = restartedDb.getDataTreeLastProcessedZxid();
if (leadZxid == cleanZxid && leadZxid == restartedZxid) {
return true;
}
Thread.sleep(1000);
}
LOG.info("Timeout waiting for zxid to sync: leader 0x{}" +
"clean 0x{}" +
"restarted 0x{}", Long.toHexString(leadZxid), Long.toHexString(cleanZxid),
Long.toHexString(restartedZxid));
return false;
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:28,代码来源:FollowerResyncConcurrencyTest.java
示例6: tearDown
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
@After
public void tearDown() throws IOException, InterruptedException {
if (zks != null) {
ZKDatabase zkDb = zks.getZKDatabase();
factory.shutdown();
try {
zkDb.close();
} catch (IOException ie) {
}
final int PORT = Integer.parseInt(hostPort.split(":")[1]);
Assert.assertTrue("waiting for server down",
waitForServerDown("127.0.0.1:" + PORT,
CONNECTION_TIMEOUT));
}
}
示例7: QuorumPeer
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
public QuorumPeer(Map<Long, QuorumServer> quorumPeers, File dataDir,
File dataLogDir, int electionType,
long myid, int tickTime, int initLimit, int syncLimit,
ServerCnxnFactory cnxnFactory,
QuorumVerifier quorumConfig) throws IOException {
this();
this.cnxnFactory = cnxnFactory;
this.quorumPeers = quorumPeers;
this.electionType = electionType;
this.myid = myid;
this.tickTime = tickTime;
this.initLimit = initLimit;
this.syncLimit = syncLimit;
this.logFactory = new FileTxnSnapLog(dataLogDir, dataDir);
this.zkDb = new ZKDatabase(this.logFactory);
if(quorumConfig == null)
this.quorumConfig = new QuorumMaj(countParticipants(quorumPeers));
else this.quorumConfig = quorumConfig;
}
示例8: shutdownServerInstance
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
static void shutdownServerInstance(ServerCnxnFactory factory,
String hostPort)
{
if (factory != null) {
ZKDatabase zkDb;
{
ZooKeeperServer zs = getServer(factory);
zkDb = zs.getZKDatabase();
}
factory.shutdown();
try {
zkDb.close();
} catch (IOException ie) {
LOG.warn("Error closing logs ", ie);
}
final int PORT = getPort(hostPort);
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown("127.0.0.1:" + PORT,
CONNECTION_TIMEOUT));
}
}
示例9: waitForSync
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
/**
* Wait for all server to have the same lastProccessedZxid. Timeout in seconds
*/
private boolean waitForSync(QuorumUtil qu, int index, int timeout) throws InterruptedException{
LOG.info("Wait for server to sync");
int leaderIndex = (index == 1) ? 2 : 1;
ZKDatabase restartedDb = qu.getPeer(index).peer.getActiveServer().getZKDatabase();
ZKDatabase cleanDb = qu.getPeer(3).peer.getActiveServer().getZKDatabase();
ZKDatabase leadDb = qu.getPeer(leaderIndex).peer.getActiveServer().getZKDatabase();
long leadZxid = 0;
long cleanZxid = 0;
long restartedZxid = 0;
for (int i = 0; i < timeout; ++i) {
leadZxid = leadDb.getDataTreeLastProcessedZxid();
cleanZxid = cleanDb.getDataTreeLastProcessedZxid();
restartedZxid = restartedDb.getDataTreeLastProcessedZxid();
if (leadZxid == cleanZxid && leadZxid == restartedZxid) {
return true;
}
Thread.sleep(1000);
}
LOG.info("Timeout waiting for zxid to sync: leader 0x" + Long.toHexString(leadZxid)+
"clean 0x" + Long.toHexString(cleanZxid) +
"restarted 0x" + Long.toHexString(restartedZxid));
return false;
}
示例10: FollowerZooKeeperServer
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
/**
* @param port
* @param dataDir
* @throws IOException
*/
FollowerZooKeeperServer(FileTxnSnapLog logFactory,QuorumPeer self,
DataTreeBuilder treeBuilder, ZKDatabase zkDb) throws IOException {
super(logFactory, self.tickTime, self.minSessionTimeout,
self.maxSessionTimeout, treeBuilder, zkDb, self);
this.pendingSyncs = new ConcurrentLinkedQueue<Request>();
}
示例11: LearnerZooKeeperServer
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
public LearnerZooKeeperServer(FileTxnSnapLog logFactory, int tickTime,
int minSessionTimeout, int maxSessionTimeout,
DataTreeBuilder treeBuilder, ZKDatabase zkDb, QuorumPeer self)
throws IOException
{
super(logFactory, tickTime, minSessionTimeout, maxSessionTimeout,
treeBuilder, zkDb, self);
}
示例12: QuorumZooKeeperServer
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
protected QuorumZooKeeperServer(FileTxnSnapLog logFactory, int tickTime,
int minSessionTimeout, int maxSessionTimeout,
DataTreeBuilder treeBuilder, ZKDatabase zkDb, QuorumPeer self)
{
super(logFactory, tickTime, minSessionTimeout, maxSessionTimeout,
treeBuilder, zkDb);
this.self = self;
}
示例13: deserializeSnapshot
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
private void deserializeSnapshot(InputArchive ia)
throws IOException {
ZKDatabase zkdb = new ZKDatabase(null);
zkdb.deserializeSnapshot(ia);
String signature = ia.readString("signature");
assertEquals("BenWasHere", signature);
}
示例14: prepareLeader
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
private LeaderZooKeeperServer prepareLeader(File tmpDir, QuorumPeer peer)
throws IOException, NoSuchFieldException, IllegalAccessException {
FileTxnSnapLog logFactory = new FileTxnSnapLog(tmpDir, tmpDir);
peer.setTxnFactory(logFactory);
Field addrField = peer.getClass().getDeclaredField("myQuorumAddr");
addrField.setAccessible(true);
addrField.set(peer, new InetSocketAddress(PortAssignment.unique()));
ZKDatabase zkDb = new ZKDatabase(logFactory);
LeaderZooKeeperServer zk = new LeaderZooKeeperServer(logFactory, peer, new ZooKeeperServer.BasicDataTreeBuilder(), zkDb);
return zk;
}
示例15: createFollower
import org.apache.zookeeper.server.ZKDatabase; //导入依赖的package包/类
private ConversableFollower createFollower(File tmpDir, QuorumPeer peer)
throws IOException {
FileTxnSnapLog logFactory = new FileTxnSnapLog(tmpDir, tmpDir);
peer.setTxnFactory(logFactory);
ZKDatabase zkDb = new ZKDatabase(logFactory);
FollowerZooKeeperServer zk = new FollowerZooKeeperServer(logFactory, peer, new ZooKeeperServer.BasicDataTreeBuilder(), zkDb);
peer.setZKDatabase(zkDb);
return new ConversableFollower(peer, zk);
}