/** * @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); } }
private void parsePB(BucketCacheProtos.BucketCacheEntry proto) throws IOException { verifyCapacityAndClasses(proto.getCacheCapacity(), proto.getIoClass(), proto.getMapClass()); backingMap = BucketProtoUtils.fromPB(proto.getDeserializersMap(), proto.getBackingMap()); }
BucketCacheProtos.BlockCacheKey protoKey = entry.getKey(); BlockCacheKey key = new BlockCacheKey(protoKey.getHfilename(), protoKey.getOffset(), protoKey.getPrimaryReplicaBlock(), fromPb(protoKey.getBlockType())); BucketCacheProtos.BucketEntry protoValue = entry.getValue(); BucketCache.BucketEntry value = new BucketCache.BucketEntry(
private static BucketCacheProtos.BackingMap toPB( Map<BlockCacheKey, BucketCache.BucketEntry> backingMap) { BucketCacheProtos.BackingMap.Builder builder = BucketCacheProtos.BackingMap.newBuilder(); for (Map.Entry<BlockCacheKey, BucketCache.BucketEntry> entry : backingMap.entrySet()) { builder.addEntry(BucketCacheProtos.BackingMapEntry.newBuilder() .setKey(toPB(entry.getKey())) .setValue(toPB(entry.getValue())) .build()); } return builder.build(); }
static BucketCacheProtos.BucketCacheEntry toPB(BucketCache cache) { return BucketCacheProtos.BucketCacheEntry.newBuilder() .setCacheCapacity(cache.getMaxSize()) .setIoClass(cache.ioEngine.getClass().getName()) .setMapClass(cache.backingMap.getClass().getName()) .putAllDeserializers(CacheableDeserializerIdManager.save()) .setBackingMap(BucketProtoUtils.toPB(cache.backingMap)) .build(); }
private static BucketCacheProtos.BlockCacheKey toPB(BlockCacheKey key) { return BucketCacheProtos.BlockCacheKey.newBuilder() .setHfilename(key.getHfileName()) .setOffset(key.getOffset()) .setPrimaryReplicaBlock(key.isPrimary()) .setBlockType(toPB(key.getBlockType())) .build(); }
private static BucketCacheProtos.BucketEntry toPB(BucketCache.BucketEntry entry) { return BucketCacheProtos.BucketEntry.newBuilder() .setOffset(entry.offset()) .setLength(entry.getLength()) .setDeserialiserIndex(entry.deserialiserIndex) .setAccessCounter(entry.getAccessCounter()) .setPriority(toPB(entry.getPriority())) .build(); }