/** * Used to shut down the cache -or- turn it off in the case of something broken. */ private void disableCache() { if (!cacheEnabled) return; cacheEnabled = false; ioEngine.shutdown(); this.scheduleThreadPool.shutdown(); for (int i = 0; i < writerThreads.length; ++i) writerThreads[i].interrupt(); this.ramCache.clear(); if (!ioEngine.isPersistent() || persistencePath == null) { // If persistent ioengine and a path, we will serialize out the backingMap. this.backingMap.clear(); } }
ioEngine.sync(); } catch (IOException ioex) { LOG.error("Failed syncing IO engine", ioex);
BucketEntry bucketEntry = ioEngine.usesSharedMemory() ? UnsafeAvailChecker.isAvailable() ? new UnsafeSharedMemoryBucketEntry(offset, len, accessCounter, inMemory) LOG.trace("Write offset=" + offset + ", len=" + len); ioEngine.write(sliceBuf, offset); ioEngine.write(metadata, offset + len - metadata.limit()); } else { ByteBuffer bb = ByteBuffer.allocate(len); data.serialize(bb, true); ioEngine.write(bb, offset);
@Override public void shutdown() { disableCache(); LOG.info("Shutdown bucket cache: IO persistent=" + ioEngine.isPersistent() + "; path to write=" + persistencePath); if (ioEngine.isPersistent() && persistencePath != null) { try { join(); persistToFile(); } catch (IOException ex) { LOG.error("Unable to persist data on exit: " + ex.toString(), ex); } catch (InterruptedException e) { LOG.warn("Failed to persist data on exit", e); } } }
LOG.trace("Read offset=" + bucketEntry.offset() + ", len=" + len); Cacheable cachedBlock = ioEngine.read(bucketEntry.offset(), len, bucketEntry.deserializerReference()); long timeTaken = System.nanoTime() - start;
ByteBuffer extraInfoBuffer = ByteBuffer.allocate(HFileBlock.EXTRA_SERIALIZATION_SPACE); block.serializeExtraInfo(extraInfoBuffer); ioEngine.write(sliceBuf, offset); ioEngine.write(extraInfoBuffer, offset + len - HFileBlock.EXTRA_SERIALIZATION_SPACE); } else { ByteBuffer bb = ByteBuffer.allocate(len); data.serialize(bb); ioEngine.write(bb, offset);
/** * @see #retrieveFromFile(int[]) */ @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="OBL_UNSATISFIED_OBLIGATION", justification = "false positive, try-with-resources ensures close is called.") private void persistToFile() throws IOException { assert !cacheEnabled; if (!ioEngine.isPersistent()) { throw new IOException("Attempt to persist non-persistent cache mappings!"); } try (FileOutputStream fos = new FileOutputStream(persistencePath, false)) { fos.write(ProtobufMagic.PB_MAGIC); BucketProtoUtils.toPB(this).writeDelimitedTo(fos); } }
int len = bucketEntry.getLength(); ByteBuffer bb = ByteBuffer.allocate(len); int lenRead = ioEngine.read(bb, bucketEntry.offset()); if (lenRead != len) { throw new RuntimeException("Only " + lenRead + " bytes read, " + len + " expected");
/** * Used to shut down the cache -or- turn it off in the case of something * broken. */ private void disableCache() { if (!cacheEnabled) return; cacheEnabled = false; ioEngine.shutdown(); this.scheduleThreadPool.shutdown(); for (int i = 0; i < writerThreads.length; ++i) writerThreads[i].interrupt(); this.ramCache.clear(); if (!ioEngine.isPersistent() || persistencePath == null) { this.backingMap.clear(); } }
if (ioEngine.isPersistent() && persistencePath != null) { try { retrieveFromFile(bucketSizes);
ioEngine.sync(); } catch (IOException ioex) { LOG.error("Failed syncing IO engine", ioex);
private void persistToFile() throws IOException { assert !cacheEnabled; FileOutputStream fos = null; ObjectOutputStream oos = null; try { if (!ioEngine.isPersistent()) throw new IOException( "Attempt to persist non-persistent cache mappings!"); fos = new FileOutputStream(persistencePath, false); oos = new ObjectOutputStream(fos); oos.writeLong(cacheCapacity); oos.writeUTF(ioEngine.getClass().getName()); oos.writeUTF(backingMap.getClass().getName()); oos.writeObject(deserialiserMap); oos.writeObject(backingMap); } finally { if (oos != null) oos.close(); if (fos != null) fos.close(); } }
ObjectInputStream ois = null; try { if (!ioEngine.isPersistent()) throw new IOException( "Attempt to restore non-persistent cache mappings!");
@Override public void shutdown() { disableCache(); LOG.info("Shutdown bucket cache: IO persistent=" + ioEngine.isPersistent() + "; path to write=" + persistencePath); if (ioEngine.isPersistent() && persistencePath != null) { try { join(); persistToFile(); } catch (IOException ex) { LOG.error("Unable to persist data on exit: " + ex.toString(), ex); } catch (InterruptedException e) { LOG.warn("Failed to persist data on exit", e); } } }
if (ioEngine.isPersistent() && persistencePath != null) { try { retrieveFromFile(bucketSizes);