/// <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); }
public virtual void TestEmptyInputStream() { ZooKeeper zk = BKJMUtil.ConnectZooKeeper(); BookKeeper bkc = new BookKeeper(new ClientConfiguration(), zk); try { LedgerHandle lh = bkc.CreateLedger(BookKeeper.DigestType.Crc32, Sharpen.Runtime.GetBytesForString ("foobar")); lh.Close(); EditLogLedgerMetadata metadata = new EditLogLedgerMetadata("/foobar", HdfsConstants .NamenodeLayoutVersion, lh.GetId(), unchecked ((int)(0x1234))); try { new BookKeeperEditLogInputStream(lh, metadata, -1); NUnit.Framework.Assert.Fail("Shouldn't get this far, should have thrown"); } catch (IOException ioe) { NUnit.Framework.Assert.IsTrue(ioe.Message.Contains("Invalid first bk entry to read" )); } metadata = new EditLogLedgerMetadata("/foobar", HdfsConstants.NamenodeLayoutVersion , lh.GetId(), unchecked ((int)(0x1234))); try { new BookKeeperEditLogInputStream(lh, metadata, 0); NUnit.Framework.Assert.Fail("Shouldn't get this far, should have thrown"); } catch (IOException ioe) { NUnit.Framework.Assert.IsTrue(ioe.Message.Contains("Invalid first bk entry to read" )); } } finally { bkc.Close(); zk.Close(); } }
public void AddResourceOperationList(string op) { if (!_bookkeeping) { return; } int startIdx = 0; int idx = op.IndexOf(";", startIdx); if (idx < 0) { idx = op.Length; } while (idx > startIdx) { string[] sop = op.Substring(startIdx, idx - startIdx).Trim().Split('.'); if (sop.Length == 2) { short ord; ResourceType rtype = BookKeeper.getResourceType(sop[0], out ord); switch (rtype) { case ResourceType.Message: case ResourceType.Target: case ResourceType.Selector: case ResourceType.ArgumentList: // ignore these, operations not tracked #if DEBUG Console.Error.WriteLine("<JoinPointContext> Not tracking operation: {0}.{1}", sop[0], sop[1]); #endif break; case ResourceType.Return: if (_returnValue != null) { ReturnValueBK.AddOperation(sop[1]); } break; case ResourceType.ArgumentEntry: if (ord == -1) { foreach (ArgumentInfo ai in _arguments.Values) { ai.ArgumentBK.AddOperation(sop[1]); } } else { _arguments[ord].ArgumentBK.AddOperation(sop[1]); } break; case ResourceType.Custom: AddResourceOp(sop[0], sop[1]); break; } } startIdx = idx + 1; if (startIdx >= op.Length) { break; } idx = op.IndexOf(";", startIdx); if (idx < 0) { idx = op.Length; } } }