/// <summary>Register a slot.</summary> /// <remarks> /// Register a slot. /// This function looks at a slot which has already been initialized (by /// another process), and registers it with us. Then, it returns the /// relevant Slot object. /// </remarks> /// <returns>The slot.</returns> /// <exception cref="Org.Apache.Hadoop.FS.InvalidRequestException"> /// If the slot index we're trying to allocate has not been /// initialized, or is already in use. /// </exception> public ShortCircuitShm.Slot RegisterSlot(int slotIdx, ExtendedBlockId blockId) { lock (this) { if (slotIdx < 0) { throw new InvalidRequestException(this + ": invalid negative slot " + "index " + slotIdx); } if (slotIdx >= slots.Length) { throw new InvalidRequestException(this + ": invalid slot " + "index " + slotIdx); } if (allocatedSlots.Get(slotIdx)) { throw new InvalidRequestException(this + ": slot " + slotIdx + " is already in use." ); } ShortCircuitShm.Slot slot = new ShortCircuitShm.Slot(this, CalculateSlotAddress(slotIdx ), blockId); if (!slot.IsValid()) { throw new InvalidRequestException(this + ": slot " + slotIdx + " is not marked as valid." ); } slots[slotIdx] = slot; allocatedSlots.Set(slotIdx, true); if (Log.IsTraceEnabled()) { Log.Trace(this + ": registerSlot " + slotIdx + ": allocatedSlots=" + allocatedSlots + StringUtils.GetStackTrace(Sharpen.Thread.CurrentThread())); } return(slot); } }
/// <exception cref="System.IO.IOException"/> public void Visit(Dictionary <DatanodeInfo, DfsClientShmManager.PerDatanodeVisitorInfo > info) { NUnit.Framework.Assert.IsTrue(info[datanode].full.IsEmpty()); NUnit.Framework.Assert.IsFalse(info[datanode].disabled); NUnit.Framework.Assert.AreEqual(1, info[datanode].notFull.Values.Count); DfsClientShm shm = info[datanode].notFull.Values.GetEnumerator().Next(); for (IEnumerator <ShortCircuitShm.Slot> iter = shm.SlotIterator(); iter.HasNext();) { ShortCircuitShm.Slot slot = iter.Next(); if (slot.IsValid()) { this._enclosing.done.SetValue(false); } } }
/// <summary>Check if the replica is stale.</summary> /// <remarks> /// Check if the replica is stale. /// Must be called with the cache lock held. /// </remarks> internal virtual bool IsStale() { if (slot != null) { // Check staleness by looking at the shared memory area we use to // communicate with the DataNode. bool stale = !slot.IsValid(); if (Log.IsTraceEnabled()) { Log.Trace(this + ": checked shared memory segment. isStale=" + stale); } return(stale); } else { // Fall back to old, time-based staleness method. long deltaMs = Time.MonotonicNow() - creationTimeMs; long staleThresholdMs = cache.GetStaleThresholdMs(); if (deltaMs > staleThresholdMs) { if (Log.IsTraceEnabled()) { Log.Trace(this + " is stale because it's " + deltaMs + " ms old, and staleThresholdMs = " + staleThresholdMs); } return(true); } else { if (Log.IsTraceEnabled()) { Log.Trace(this + " is not stale because it's only " + deltaMs + " ms old, and staleThresholdMs = " + staleThresholdMs); } return(false); } } }