本文整理汇总了Java中org.apache.zookeeper.server.persistence.FileTxnSnapLog类的典型用法代码示例。如果您正苦于以下问题:Java FileTxnSnapLog类的具体用法?Java FileTxnSnapLog怎么用?Java FileTxnSnapLog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileTxnSnapLog类属于org.apache.zookeeper.server.persistence包,在下文中一共展示了FileTxnSnapLog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startFakeCluster
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的package包/类
/**
* 启动伪集群模式
* @param config
* @throws IOException
* @throws InterruptedException
* @throws ConfigException
*/
public void startFakeCluster(QuorumPeerConfig config) throws IOException{
ServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns());
QuorumPeer quorumPeer = new QuorumPeer(config.getServers(), config.getDataDir(), config.getDataLogDir(), config.getElectionAlg(), config.getServerId(), config.getTickTime(), config.getInitLimit(), config.getSyncLimit(), config.getQuorumListenOnAllIPs(), cnxnFactory, config.getQuorumVerifier());
quorumPeer.setClientAddress(config.getClientPortAddress());
quorumPeer.setTxnFactory(new FileTxnSnapLog(config.getDataLogDir(), config.getDataDir()));
quorumPeer.setElectionType(config.getElectionAlg());
quorumPeer.setMyid(config.getServerId());
quorumPeer.setTickTime(config.getTickTime());
quorumPeer.setMinSessionTimeout(config.getMinSessionTimeout());
quorumPeer.setMaxSessionTimeout(config.getMaxSessionTimeout());
quorumPeer.setInitLimit(config.getInitLimit());
quorumPeer.setSyncLimit(config.getSyncLimit());
quorumPeer.setQuorumVerifier(config.getQuorumVerifier(), true);
quorumPeer.setCnxnFactory(cnxnFactory);
quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory()));
quorumPeer.setLearnerType(config.getPeerType());
quorumPeer.setSyncEnabled(config.getSyncEnabled());
quorumPeer.setQuorumListenOnAllIPs(config.getQuorumListenOnAllIPs());
quorumPeer.start();
LOGGER.info("ZkServerCluster Started! ClientPortAddress={}", config.getClientPortAddress());
}
示例2: QuorumPeer
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的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: testSnapFilesLessThanToRetain
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的package包/类
/**
* Tests purge where the data directory contains old snapshots and data
* logs, newest snapshots and data logs
*/
@Test
public void testSnapFilesLessThanToRetain() throws Exception {
int nRecentCount = 4;
int fileToPurgeCount = 2;
AtomicInteger offset = new AtomicInteger(0);
tmpDir = ClientBase.createTmpDir();
File version2 = new File(tmpDir.toString(), "version-2");
Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
version2.mkdir());
List<File> snapsToPurge = new ArrayList<File>();
List<File> logsToPurge = new ArrayList<File>();
List<File> snaps = new ArrayList<File>();
List<File> logs = new ArrayList<File>();
createDataDirFiles(offset, fileToPurgeCount, version2, snapsToPurge,
logsToPurge);
createDataDirFiles(offset, nRecentCount, version2, snaps, logs);
FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
PurgeTxnLog.retainNRecentSnapshots(txnLog, snaps);
txnLog.close();
verifyFilesAfterPurge(snapsToPurge, false);
verifyFilesAfterPurge(logsToPurge, false);
verifyFilesAfterPurge(snaps, true);
verifyFilesAfterPurge(logs, true);
}
示例4: makeLeader
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的package包/类
@Override
protected Leader makeLeader(FileTxnSnapLog logFactory) throws IOException {
LeaderZooKeeperServer zk = new LeaderZooKeeperServer(logFactory, this, this.getZkDb()) {
@Override
protected void setupRequestProcessors() {
/**
* This method is overridden to make a place to inject
* MockSyncRequestProcessor
*/
RequestProcessor finalProcessor = new FinalRequestProcessor(this);
RequestProcessor toBeAppliedProcessor = new Leader.ToBeAppliedRequestProcessor(finalProcessor,
getLeader());
commitProcessor = new CommitProcessor(toBeAppliedProcessor, Long.toString(getServerId()), false,
getZooKeeperServerListener());
commitProcessor.start();
ProposalRequestProcessor proposalProcessor = new MockProposalRequestProcessor(this,
commitProcessor);
proposalProcessor.initialize();
prepRequestProcessor = new PrepRequestProcessor(this, proposalProcessor);
prepRequestProcessor.start();
firstProcessor = new LeaderRequestProcessor(this, prepRequestProcessor);
}
};
return new Leader(this, zk);
}
示例5: makeFollower
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的package包/类
@Override
protected Follower makeFollower(FileTxnSnapLog logFactory) throws IOException {
return new Follower(this, new FollowerZooKeeperServer(logFactory, this, this.getZkDb())) {
@Override
void writePacket(QuorumPacket pp, boolean flush) throws IOException {
if (pp != null && pp.getType() == Leader.ACK) {
newLeaderMessage = true;
try {
/**
* Delaying the ACK message, a follower sends as
* response to a NEWLEADER message, so that the
* leader has a chance to send the reconfig and only
* then the UPTODATE message.
*/
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
super.writePacket(pp, flush);
}
};
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:26,代码来源:ReconfigDuringLeaderSyncTest.java
示例6: makeFollower
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的package包/类
@Override
protected Follower makeFollower(FileTxnSnapLog logFactory)
throws IOException {
return new Follower(this, new FollowerZooKeeperServer(logFactory,
this, this.getZkDb())) {
@Override
void readPacket(QuorumPacket pp) throws IOException {
/**
* In real scenario got SocketTimeoutException while reading
* the packet from leader because of network problem, but
* here throwing SocketTimeoutException based on whether
* error is injected or not
*/
super.readPacket(pp);
if (injectError && pp.getType() == Leader.PROPOSAL) {
String type = LearnerHandler.packetToString(pp);
throw new SocketTimeoutException(
"Socket timeout while reading the packet for operation "
+ type);
}
}
};
}
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:26,代码来源:EphemeralNodeDeletionTest.java
示例7: internalTestSnapFilesEqualsToRetain
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的package包/类
public void internalTestSnapFilesEqualsToRetain(boolean testWithPrecedingLogFile) throws Exception {
int nRecentCount = 3;
AtomicInteger offset = new AtomicInteger(0);
tmpDir = ClientBase.createTmpDir();
File version2 = new File(tmpDir.toString(), "version-2");
Assert.assertTrue("Failed to create version_2 dir:" + version2.toString(),
version2.mkdir());
List<File> snaps = new ArrayList<File>();
List<File> logs = new ArrayList<File>();
createDataDirFiles(offset, nRecentCount, testWithPrecedingLogFile, version2, snaps, logs);
FileTxnSnapLog txnLog = new FileTxnSnapLog(tmpDir, tmpDir);
PurgeTxnLog.purgeOlderSnapshots(txnLog, snaps.get(snaps.size() - 1));
txnLog.close();
verifyFilesAfterPurge(snaps, true);
verifyFilesAfterPurge(logs, true);
}
示例8: ZooKeeperServer
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的package包/类
/**
* Creates a ZooKeeperServer instance. It sets everything up, but doesn't
* actually start listening for clients until run() is invoked.
*
* @param dataDir the directory to put the data
*/
public ZooKeeperServer(FileTxnSnapLog txnLogFactory, int tickTime,
int minSessionTimeout, int maxSessionTimeout,
DataTreeBuilder treeBuilder, ZKDatabase zkDb) {
serverStats = new ServerStats(this);
this.txnLogFactory = txnLogFactory;
this.zkDb = zkDb;
this.tickTime = tickTime;
this.minSessionTimeout = minSessionTimeout;
this.maxSessionTimeout = maxSessionTimeout;
listener = new ZooKeeperServerListenerImpl(this);
LOG.info("Created server with tickTime " + tickTime
+ " minSessionTimeout " + getMinSessionTimeout()
+ " maxSessionTimeout " + getMaxSessionTimeout()
+ " datadir " + txnLogFactory.getDataDir()
+ " snapdir " + txnLogFactory.getSnapDir());
}
示例9: testNoAuthLearnerConnectsToServerWithAuthNotRequired
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的package包/类
/**
* Test verifies that the No Auth enabled Learner is connecting to a No Auth
* Leader server. Learner should be able to establish a connection with
* Leader as auth is not required.
*/
@Test(timeout = 30000)
public void testNoAuthLearnerConnectsToServerWithAuthNotRequired()
throws Exception {
File testDataLearner = ClientBase.createTmpDir();
File tmpDir = File.createTempFile("test", ".dir", testDataLearner);
tmpDir.delete();
FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpDir, tmpDir);
QuorumPeer learnerPeer = createQuorumPeer(tmpDir, true, false, false,
"QuorumLearner", "QuorumServer", "");
SimpleLearner sl = new SimpleLearner(ftsl, learnerPeer);
File testDataLeader = ClientBase.createTmpDir();
tmpDir = File.createTempFile("test", ".dir", testDataLeader);
tmpDir.delete();
tmpDir.mkdir();
Leader leader = null;
QuorumPeer peer = createQuorumPeer(tmpDir, true, false, false, "QuorumLearner",
"QuorumServer",
QuorumAuth.QUORUM_KERBEROS_SERVICE_PRINCIPAL_DEFAULT_VALUE);
CountDownLatch learnerLatch = new CountDownLatch(1);
leader = createSimpleLeader(tmpDir, peer, learnerLatch);
peer.leader = leader;
startLearnerCnxAcceptorThread(leader);
LOG.info("Start establishing a connection with the Leader");
String hostname = getLeaderHostname(peer);
sl.connectToLeader(peer.getQuorumAddress(), hostname);
Assert.assertTrue("Leader should accept no auth learner connection",
learnerLatch.await(leader.self.tickTime * leader.self.initLimit + 1000,
TimeUnit.MILLISECONDS));
ClientBase.recursiveDelete(testDataLearner);
ClientBase.recursiveDelete(testDataLeader);
}
示例10: FollowerZooKeeperServer
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的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.persistence.FileTxnSnapLog; //导入依赖的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: createObserver
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的package包/类
private ConversableObserver createObserver(File tmpDir, QuorumPeer peer)
throws IOException {
FileTxnSnapLog logFactory = new FileTxnSnapLog(tmpDir, tmpDir);
peer.setTxnFactory(logFactory);
DataTreeBuilder treeBuilder = new ZooKeeperServer.BasicDataTreeBuilder();
ZKDatabase zkDb = new ZKDatabase(logFactory);
ObserverZooKeeperServer zk = new ObserverZooKeeperServer(logFactory, peer, treeBuilder, zkDb);
peer.setZKDatabase(zkDb);
return new ConversableObserver(peer, zk);
}
示例13: QuorumZooKeeperServer
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的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;
}
示例14: ZooKeeperServer
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的package包/类
/**
* Default constructor, relies on the config for its agrument values
*
* @throws IOException
*/
public ZooKeeperServer(FileTxnSnapLog txnLogFactory,
DataTreeBuilder treeBuilder)
throws IOException
{
this(txnLogFactory, DEFAULT_TICK_TIME, -1, -1, treeBuilder,
new ZKDatabase(txnLogFactory));
}
示例15: testAuthLearnerConnectsToServerWithAuthNotRequired
import org.apache.zookeeper.server.persistence.FileTxnSnapLog; //导入依赖的package包/类
/**
* Test verifies that the Leader should authenticate the connecting learner
* quorumpeer. After the successful authentication it should add this
* learner to the learnerHandler list.
*/
@Test(timeout = 30000)
public void testAuthLearnerConnectsToServerWithAuthNotRequired()
throws Exception {
File testDataLearner = ClientBase.createTmpDir();
File tmpDir = File.createTempFile("test", ".dir", testDataLearner);
tmpDir.delete();
FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpDir, tmpDir);
QuorumPeer learnerPeer = createQuorumPeer(tmpDir, true, true, true,
"QuorumLearner", "QuorumServer",
QuorumAuth.QUORUM_KERBEROS_SERVICE_PRINCIPAL_DEFAULT_VALUE);
SimpleLearner sl = new SimpleLearner(ftsl, learnerPeer);
File testDataLeader = ClientBase.createTmpDir();
tmpDir = File.createTempFile("test", ".dir", testDataLeader);
tmpDir.delete();
tmpDir.mkdir();
Leader leader = null;
QuorumPeer peer = createQuorumPeer(tmpDir, true, true, false, "QuorumLearner",
"QuorumServer",
QuorumAuth.QUORUM_KERBEROS_SERVICE_PRINCIPAL_DEFAULT_VALUE);
CountDownLatch learnerLatch = new CountDownLatch(1);
leader = createSimpleLeader(tmpDir, peer, learnerLatch);
peer.leader = leader;
startLearnerCnxAcceptorThread(leader);
LOG.info("Start establishing a connection with the Leader");
String hostname = getLeaderHostname(peer);
sl.connectToLeader(peer.getQuorumAddress(), hostname);
// wait till leader socket soTimeout period
Assert.assertTrue("Leader should accept the auth learner connection",
learnerLatch.await(leader.self.tickTime * leader.self.initLimit + 1000,
TimeUnit.MILLISECONDS));
Assert.assertEquals("Failed to added the learner", 1,
leader.getLearners().size());
ClientBase.recursiveDelete(testDataLearner);
ClientBase.recursiveDelete(testDataLeader);
}