/** * Mark any slots associated with this blockId as unanchorable. * * @param blockId The block ID. * @return True if we should allow the munlock request. */ public synchronized boolean processBlockMunlockRequest( ExtendedBlockId blockId) { if (!enabled) return true; boolean allowMunlock = true; Set<Slot> affectedSlots = slots.get(blockId); for (Slot slot : affectedSlots) { slot.makeUnanchorable(); if (slot.isAnchored()) { allowMunlock = false; } } return allowMunlock; }
/** * Process a block mlock event from the FsDatasetCache. * * @param blockId The block that was mlocked. */ public synchronized void processBlockMlockEvent(ExtendedBlockId blockId) { if (!enabled) return; Set<Slot> affectedSlots = slots.get(blockId); for (Slot slot : affectedSlots) { slot.makeAnchorable(); } }
public synchronized void removeShm(ShortCircuitShm shm) { if (LOG.isTraceEnabled()) { LOG.trace("removing shm " + shm); } // Stop tracking the shmId. RegisteredShm removedShm = segments.remove(shm.getShmId()); Preconditions.checkState(removedShm == shm, "failed to remove " + shm.getShmId()); // Stop tracking the slots. for (Iterator<Slot> iter = shm.slotIterator(); iter.hasNext(); ) { Slot slot = iter.next(); boolean removed = slots.remove(slot.getBlockId(), slot); Preconditions.checkState(removed); slot.makeInvalid(); } // De-allocate the memory map and close the shared file. shm.free(); }
public synchronized void registerSlot(ExtendedBlockId blockId, SlotId slotId, boolean isCached) throws InvalidRequestException { if (!enabled) { if (LOG.isTraceEnabled()) { LOG.trace(this + " can't register a slot because the " + "ShortCircuitRegistry is not enabled."); } throw new UnsupportedOperationException(); } ShmId shmId = slotId.getShmId(); RegisteredShm shm = segments.get(shmId); if (shm == null) { throw new InvalidRequestException("there is no shared memory segment " + "registered with shmId " + shmId); } Slot slot = shm.registerSlot(slotId.getSlotIdx(), blockId); if (isCached) { slot.makeAnchorable(); } else { slot.makeUnanchorable(); } boolean added = slots.put(blockId, slot); Preconditions.checkState(added); if (LOG.isTraceEnabled()) { LOG.trace(this + ": registered " + blockId + " with slot " + slotId + " (isCached=" + isCached + ")"); } }
public synchronized void unregisterSlot(SlotId slotId) throws InvalidRequestException { if (!enabled) { if (LOG.isTraceEnabled()) { LOG.trace("unregisterSlot: ShortCircuitRegistry is " + "not enabled."); } throw new UnsupportedOperationException(); } ShmId shmId = slotId.getShmId(); RegisteredShm shm = segments.get(shmId); if (shm == null) { throw new InvalidRequestException("there is no shared memory segment " + "registered with shmId " + shmId); } Slot slot = shm.getSlot(slotId.getSlotIdx()); slot.makeInvalid(); shm.unregisterSlot(slotId.getSlotIdx()); slots.remove(slot.getBlockId(), slot); }
/** * Get the SlotId of this slot, containing both shmId and slotIdx. * * @return The SlotId of this slot. */ public SlotId getSlotId() { return new SlotId(getShmId(), getSlotIdx()); }
"src: 127.0.0.1, dest: 127.0.0.1, op: RELEASE_SHORT_CIRCUIT_FDS," + " shmId: %016x%016x, slotIdx: %d, srvID: %s, success: %b", slotId.getShmId().getHi(), slotId.getShmId().getLo(), slotId.getSlotIdx(), datanode.getDatanodeUuid(), success));
public void freeSlot(Slot slot) { lock.lock(); try { DfsClientShm shm = (DfsClientShm)slot.getShm(); shm.getEndpointShmManager().freeSlot(slot); } finally { lock.unlock(); } }
/** * Invalidate any slot associated with a blockId that we are invalidating * (deleting) from this DataNode. When a slot is invalid, the DFSClient will * not use the corresponding replica for new read or mmap operations (although * existing, ongoing read or mmap operations will complete.) * * @param blockId The block ID. */ public synchronized void processBlockInvalidation(ExtendedBlockId blockId) { if (!enabled) return; final Set<Slot> affectedSlots = slots.get(blockId); if (!affectedSlots.isEmpty()) { final StringBuilder bld = new StringBuilder(); String prefix = ""; bld.append("Block ").append(blockId).append(" has been invalidated. "). append("Marking short-circuit slots as invalid: "); for (Slot slot : affectedSlots) { slot.makeInvalid(); bld.append(prefix).append(slot.toString()); prefix = ", "; } LOG.info(bld.toString()); } }
@Override public String toString() { return "Slot(slotIdx=" + getSlotIdx() + ", shm=" + getShm() + ")"; } }
/** * Remove a no-checksum anchor for our shared memory slot. * * This method does not require any synchronization. */ public void removeNoChecksumAnchor() { if (slot != null) { slot.removeAnchor(); } }
try { do { shmId = ShmId.createRandom(); } while (segments.containsKey(shmId)); fis = shmFactory.createDescriptor(clientName, SHM_LENGTH);
public synchronized String getClientNames(ExtendedBlockId blockId) { if (!enabled) return ""; final HashSet<String> clientNames = new HashSet<String>(); final Set<Slot> affectedSlots = slots.get(blockId); for (Slot slot : affectedSlots) { clientNames.add(((RegisteredShm)slot.getShm()).getClientName()); } return Joiner.on(",").join(clientNames); }
/** * Iterate over all allocated slots. * * Note that this method isn't safe if * * @return The slot iterator. */ public SlotIterator slotIterator() { return new SlotIterator(); }
/** * Decrement the reference count. */ public void unref() { cache.unref(this); }
/** * Get the SlotId of this slot, containing both shmId and slotIdx. * * @return The SlotId of this slot. */ public SlotId getSlotId() { return new SlotId(getShmId(), getSlotIdx()); }
public void freeSlot(Slot slot) { lock.lock(); try { DfsClientShm shm = (DfsClientShm)slot.getShm(); shm.getEndpointShmManager().freeSlot(slot); } finally { lock.unlock(); } }
/** * Iterate over all allocated slots. * * Note that this method isn't safe if * * @return The slot iterator. */ public SlotIterator slotIterator() { return new SlotIterator(); }
/** * Get the SlotId of this slot, containing both shmId and slotIdx. * * @return The SlotId of this slot. */ public SlotId getSlotId() { return new SlotId(getShmId(), getSlotIdx()); }