/// <summary>Construct a Bookkeeper journal manager.</summary> /// <exception cref="System.IO.IOException"/> public BookKeeperJournalManager(Configuration conf, URI uri, NamespaceInfo nsInfo ) { this.conf = conf; this.nsInfo = nsInfo; string zkConnect = uri.GetAuthority().Replace(";", ","); basePath = uri.GetPath(); ensembleSize = conf.GetInt(BkjmBookkeeperEnsembleSize, BkjmBookkeeperEnsembleSizeDefault ); quorumSize = conf.GetInt(BkjmBookkeeperQuorumSize, BkjmBookkeeperQuorumSizeDefault ); ackQuorumSize = conf.GetInt(BkjmBookkeeperAckQuorumSize, quorumSize); addEntryTimeout = conf.GetInt(BkjmBookkeeperAddEntryTimeoutSec, BkjmBookkeeperAddEntryTimeoutDefault ); speculativeReadTimeout = conf.GetInt(BkjmBookkeeperSpeculativeReadTimeoutMs, BkjmBookkeeperSpeculativeReadTimeoutDefault ); readEntryTimeout = conf.GetInt(BkjmBookkeeperReadEntryTimeoutSec, BkjmBookkeeperReadEntryTimeoutDefault ); ledgerPath = basePath + "/ledgers"; string maxTxIdPath = basePath + "/maxtxid"; string currentInprogressNodePath = basePath + "/CurrentInprogress"; versionPath = basePath + "/version"; digestpw = conf.Get(BkjmBookkeeperDigestPw, BkjmBookkeeperDigestPwDefault); try { zkConnectLatch = new CountDownLatch(1); int bkjmZKSessionTimeout = conf.GetInt(BkjmZkSessionTimeout, BkjmZkSessionTimeoutDefault ); zkc = new ZooKeeper(zkConnect, bkjmZKSessionTimeout, new BookKeeperJournalManager.ZkConnectionWatcher (this)); // Configured zk session timeout + some extra grace period (here // BKJM_ZK_SESSION_TIMEOUT_DEFAULT used as grace period) int zkConnectionLatchTimeout = bkjmZKSessionTimeout + BkjmZkSessionTimeoutDefault; if (!zkConnectLatch.Await(zkConnectionLatchTimeout, TimeUnit.Milliseconds)) { throw new IOException("Error connecting to zookeeper"); } PrepareBookKeeperEnv(); ClientConfiguration clientConf = new ClientConfiguration(); clientConf.SetSpeculativeReadTimeout(speculativeReadTimeout); clientConf.SetReadEntryTimeout(readEntryTimeout); clientConf.SetAddEntryTimeout(addEntryTimeout); bkc = new BookKeeper(clientConf, zkc); } catch (KeeperException e) { throw new IOException("Error initializing zk", e); } catch (Exception ie) { Sharpen.Thread.CurrentThread().Interrupt(); throw new IOException("Interrupted while initializing bk journal manager", ie); } ci = new CurrentInprogress(zkc, currentInprogressNodePath); maxTxId = new MaxTxId(zkc, maxTxIdPath); }
/// <summary> /// Tests that update should throw IOE, if version number modifies between read /// and update /// </summary> /// <exception cref="System.Exception"/> public virtual void TestUpdateShouldFailWithIOEIfVersionNumberChangedAfterRead() { CurrentInprogress ci = new CurrentInprogress(zkc, CurrentNodePath); ci.Init(); ci.Update("myInprogressZnode"); NUnit.Framework.Assert.AreEqual("Not returning myInprogressZnode", "myInprogressZnode" , ci.Read()); // Updating data in-between to change the data to change the version number ci.Update("YourInprogressZnode"); ci.Update("myInprogressZnode"); }
public virtual void TestReadShouldReturnTheZnodePathAfterUpdate() { string data = "inprogressNode"; CurrentInprogress ci = new CurrentInprogress(zkc, CurrentNodePath); ci.Init(); ci.Update(data); string inprogressNodePath = ci.Read(); NUnit.Framework.Assert.AreEqual("Not returning inprogressZnode", "inprogressNode" , inprogressNodePath); }
public virtual void TestReadShouldReturnNullAfterClear() { CurrentInprogress ci = new CurrentInprogress(zkc, CurrentNodePath); ci.Init(); ci.Update("myInprogressZnode"); ci.Read(); ci.Clear(); string inprogressNodePath = ci.Read(); NUnit.Framework.Assert.AreEqual("Expecting null to be return", null, inprogressNodePath ); }