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(); }
FileInputStream stream = factory.createDescriptor("testAllocateSlots", 4096); ShortCircuitShm shm = new ShortCircuitShm(ShmId.createRandom(), stream); int numSlots = 0; ArrayList<Slot> slots = new ArrayList<Slot>(); while (!shm.isFull()) { Slot slot = shm.allocAndRegisterSlot(new ExtendedBlockId(123L, "test_bp1")); slots.add(slot); numSlots++; for (Iterator<Slot> iter = shm.slotIterator(); iter.hasNext(); ) { Assert.assertTrue(slots.contains(iter.next())); shm.unregisterSlot(slot.getSlotIdx()); slot.makeInvalid(); shm.free(); stream.close(); FileUtil.fullyDelete(path);
raf.setLength(8192); FileInputStream shmStream = new FileInputStream(raf.getFD()); shm = new ShortCircuitShm(ShmId.createRandom(), shmStream); ShortCircuitReplica replica = new ShortCircuitReplica(key, dataIn, metaIn, shortCircuitCache, Time.now(), shm.allocAndRegisterSlot( ExtendedBlockId.fromExtendedBlock(block))); blockReaderLocal = new BlockReaderLocal.Builder( if (metaIn != null) metaIn.close(); if (blockReaderLocal != null) blockReaderLocal.close(); if (shm != null) shm.free(); if (raf != null) raf.close();
@Test(timeout=60000) public void testStartupShutdown() throws Exception { File path = new File(TEST_BASE, "testStartupShutdown"); path.mkdirs(); SharedFileDescriptorFactory factory = SharedFileDescriptorFactory.create("shm_", new String[] { path.getAbsolutePath() } ); FileInputStream stream = factory.createDescriptor("testStartupShutdown", 4096); ShortCircuitShm shm = new ShortCircuitShm(ShmId.createRandom(), stream); shm.free(); stream.close(); FileUtil.fullyDelete(path); }
/** * Allocate a new slot and register it. * * This function chooses an empty slot, initializes it, and then returns * the relevant Slot object. * * @return The new slot. */ synchronized public final Slot allocAndRegisterSlot( ExtendedBlockId blockId) { int idx = allocatedSlots.nextClearBit(0); if (idx >= slots.length) { throw new RuntimeException(this + ": no more slots are available."); } allocatedSlots.set(idx, true); Slot slot = new Slot(calculateSlotAddress(idx), blockId); slot.clear(); slot.makeValid(); slots[idx] = slot; if (LOG.isTraceEnabled()) { LOG.trace(this + ": allocAndRegisterSlot " + idx + ": allocatedSlots=" + allocatedSlots + StringUtils.getStackTrace(Thread.currentThread())); } return 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()); }
this.mmappedLength = getUsableLength(stream); this.baseAddress = POSIX.mmap(stream.getFD(), POSIX.MMAP_PROT_READ | POSIX.MMAP_PROT_WRITE, true, mmappedLength);
FileInputStream stream = factory.createDescriptor("testAllocateSlots", 4096); ShortCircuitShm shm = new ShortCircuitShm(ShmId.createRandom(), stream); int numSlots = 0; ArrayList<Slot> slots = new ArrayList<Slot>(); while (!shm.isFull()) { Slot slot = shm.allocAndRegisterSlot(new ExtendedBlockId(123L, "test_bp1")); slots.add(slot); numSlots++; for (Iterator<Slot> iter = shm.slotIterator(); iter.hasNext(); ) { Assert.assertTrue(slots.contains(iter.next())); shm.unregisterSlot(slot.getSlotIdx()); slot.makeInvalid(); shm.free(); stream.close(); FileUtil.fullyDelete(path);
@Test(timeout=60000) public void testStartupShutdown() throws Exception { File path = new File(TEST_BASE, "testStartupShutdown"); path.mkdirs(); SharedFileDescriptorFactory factory = SharedFileDescriptorFactory.create("shm_", new String[] { path.getAbsolutePath() } ); FileInputStream stream = factory.createDescriptor("testStartupShutdown", 4096); ShortCircuitShm shm = new ShortCircuitShm(ShmId.createRandom(), stream); shm.free(); stream.close(); FileUtil.fullyDelete(path); }
/** * Allocate a new slot and register it. * * This function chooses an empty slot, initializes it, and then returns * the relevant Slot object. * * @return The new slot. */ synchronized public final Slot allocAndRegisterSlot( ExtendedBlockId blockId) { int idx = allocatedSlots.nextClearBit(0); if (idx >= slots.length) { throw new RuntimeException(this + ": no more slots are available."); } allocatedSlots.set(idx, true); Slot slot = new Slot(calculateSlotAddress(idx), blockId); slot.clear(); slot.makeValid(); slots[idx] = slot; if (LOG.isTraceEnabled()) { LOG.trace(this + ": allocAndRegisterSlot " + idx + ": allocatedSlots=" + allocatedSlots + StringUtils.getStackTrace(Thread.currentThread())); } return 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()); }
this.mmappedLength = getUsableLength(stream); this.baseAddress = POSIX.mmap(stream.getFD(), POSIX.MMAP_PROT_READ | POSIX.MMAP_PROT_WRITE, true, mmappedLength);
public synchronized void removeShm(ShortCircuitShm shm) { if (LOG.isTraceEnabled()) { LOG.debug("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(); }
/** * Allocate a new slot and register it. * * This function chooses an empty slot, initializes it, and then returns * the relevant Slot object. * * @return The new slot. */ synchronized public final Slot allocAndRegisterSlot( ExtendedBlockId blockId) { int idx = allocatedSlots.nextClearBit(0); if (idx >= slots.length) { throw new RuntimeException(this + ": no more slots are available."); } allocatedSlots.set(idx, true); Slot slot = new Slot(calculateSlotAddress(idx), blockId); slot.clear(); slot.makeValid(); slots[idx] = slot; if (LOG.isTraceEnabled()) { LOG.trace(this + ": allocAndRegisterSlot " + idx + ": allocatedSlots=" + allocatedSlots + StringUtils.getStackTrace(Thread.currentThread())); } return 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()); }
this.mmappedLength = getUsableLength(stream); this.baseAddress = POSIX.mmap(stream.getFD(), POSIX.MMAP_PROT_READ | POSIX.MMAP_PROT_WRITE, true, mmappedLength);
public synchronized void removeShm(ShortCircuitShm shm) { if (LOG.isTraceEnabled()) { LOG.debug("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(); }
" is already in use."); Slot slot = new Slot(calculateSlotAddress(slotIdx), blockId); if (!slot.isValid()) { throw new InvalidRequestException(this + ": slot " + slotIdx +
" is already in use."); Slot slot = new Slot(calculateSlotAddress(slotIdx), blockId); if (!slot.isValid()) { throw new InvalidRequestException(this + ": slot " + slotIdx +
" is already in use."); Slot slot = new Slot(calculateSlotAddress(slotIdx), blockId); if (!slot.isValid()) { throw new InvalidRequestException(this + ": slot " + slotIdx +