/// <exception cref="System.Exception"/> public virtual void TestAllocateSlots() { FilePath path = new FilePath(TestBase, "testAllocateSlots"); path.Mkdirs(); SharedFileDescriptorFactory factory = SharedFileDescriptorFactory.Create("shm_", new string[] { path.GetAbsolutePath() }); FileInputStream stream = factory.CreateDescriptor("testAllocateSlots", 4096); ShortCircuitShm shm = new ShortCircuitShm(ShortCircuitShm.ShmId.CreateRandom(), stream ); int numSlots = 0; AList <ShortCircuitShm.Slot> slots = new AList <ShortCircuitShm.Slot>(); while (!shm.IsFull()) { ShortCircuitShm.Slot slot = shm.AllocAndRegisterSlot(new ExtendedBlockId(123L, "test_bp1" )); slots.AddItem(slot); numSlots++; } Log.Info("allocated " + numSlots + " slots before running out."); int slotIdx = 0; for (IEnumerator <ShortCircuitShm.Slot> iter = shm.SlotIterator(); iter.HasNext();) { NUnit.Framework.Assert.IsTrue(slots.Contains(iter.Next())); } foreach (ShortCircuitShm.Slot slot_1 in slots) { NUnit.Framework.Assert.IsFalse(slot_1.AddAnchor()); NUnit.Framework.Assert.AreEqual(slotIdx++, slot_1.GetSlotIdx()); } foreach (ShortCircuitShm.Slot slot_2 in slots) { slot_2.MakeAnchorable(); } foreach (ShortCircuitShm.Slot slot_3 in slots) { NUnit.Framework.Assert.IsTrue(slot_3.AddAnchor()); } foreach (ShortCircuitShm.Slot slot_4 in slots) { slot_4.RemoveAnchor(); } foreach (ShortCircuitShm.Slot slot_5 in slots) { shm.UnregisterSlot(slot_5.GetSlotIdx()); slot_5.MakeInvalid(); } shm.Free(); stream.Close(); FileUtil.FullyDelete(path); }
/// <exception cref="System.IO.IOException"/> public ShortCircuitRegistry(Configuration conf) { bool enabled = false; SharedFileDescriptorFactory shmFactory = null; DomainSocketWatcher watcher = null; try { int interruptCheck = conf.GetInt(DFSConfigKeys.DfsShortCircuitSharedMemoryWatcherInterruptCheckMs , DFSConfigKeys.DfsShortCircuitSharedMemoryWatcherInterruptCheckMsDefault); if (interruptCheck <= 0) { throw new IOException(DFSConfigKeys.DfsShortCircuitSharedMemoryWatcherInterruptCheckMs + " was set to " + interruptCheck); } string[] shmPaths = conf.GetTrimmedStrings(DFSConfigKeys.DfsDatanodeSharedFileDescriptorPaths ); if (shmPaths.Length == 0) { shmPaths = DFSConfigKeys.DfsDatanodeSharedFileDescriptorPathsDefault.Split(","); } shmFactory = SharedFileDescriptorFactory.Create("HadoopShortCircuitShm_", shmPaths ); string dswLoadingFailure = DomainSocketWatcher.GetLoadingFailureReason(); if (dswLoadingFailure != null) { throw new IOException(dswLoadingFailure); } watcher = new DomainSocketWatcher(interruptCheck, "datanode"); enabled = true; if (Log.IsDebugEnabled()) { Log.Debug("created new ShortCircuitRegistry with interruptCheck=" + interruptCheck + ", shmPath=" + shmFactory.GetPath()); } } catch (IOException e) { if (Log.IsDebugEnabled()) { Log.Debug("Disabling ShortCircuitRegistry", e); } } finally { this.enabled = enabled; this.shmFactory = shmFactory; this.watcher = watcher; } }
/// <exception cref="System.Exception"/> public virtual void TestStartupShutdown() { FilePath path = new FilePath(TestBase, "testStartupShutdown"); path.Mkdirs(); SharedFileDescriptorFactory factory = SharedFileDescriptorFactory.Create("shm_", new string[] { path.GetAbsolutePath() }); FileInputStream stream = factory.CreateDescriptor("testStartupShutdown", 4096); ShortCircuitShm shm = new ShortCircuitShm(ShortCircuitShm.ShmId.CreateRandom(), stream ); shm.Free(); stream.Close(); FileUtil.FullyDelete(path); }