/** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) @Override public GridTcpCommunicationMessageAdapter clone() { GridGgfsBlockKey _clone = new GridGgfsBlockKey(); clone0(_clone); return _clone; }
/** {@inheritDoc} */ @Override public Object affinityKey(Object key) { if (key != null && GridGgfsBlockKey.class.equals(key.getClass())) { GridGgfsBlockKey blockKey = (GridGgfsBlockKey)key; if (blockKey.affinityKey() != null) return blockKey.affinityKey(); long grpId = blockKey.getBlockId() / grpSize; return blockKey.getFileId().hashCode() + (int)(grpId ^ (grpId >>> 32)); } return super.affinityKey(key); }
/** {@inheritDoc} */ @Override public boolean evictAllowed(GridCacheEntry entry) { Object key = entry.getKey(); return !(key instanceof GridGgfsBlockKey && ((GridGgfsBlockKey)key).evictExclude()); } }
if (colocatedKey.affinityKey() == null) { dataCachePrj.transform(colocatedKey, new UpdateClosure(startOff, data)); GridGgfsBlockKey key = new GridGgfsBlockKey(colocatedKey.getFileId(), null, colocatedKey.evictExclude(), colocatedKey.getBlockId());
/** * @param blockIdx Block index. * @param fileInfo File info. * @return Block key. */ public GridGgfsBlockKey blockKey(long blockIdx, GridGgfsFileInfo fileInfo) { if (fileInfo.affinityKey() != null) return new GridGgfsBlockKey(fileInfo.id(), fileInfo.affinityKey(), fileInfo.evictExclude(), blockIdx); if (fileInfo.fileMap() != null) { GridUuid affKey = fileInfo.fileMap().affinityKey(blockIdx * fileInfo.blockSize(), false); return new GridGgfsBlockKey(fileInfo.id(), affKey, fileInfo.evictExclude(), blockIdx); } return new GridGgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), blockIdx); }
/** {@inheritDoc} */ @SuppressWarnings("fallthrough") @Override public boolean writeTo(ByteBuffer buf) { commState.setBuffer(buf); if (!commState.typeWritten) { if (!commState.putByte(directType())) return false; commState.typeWritten = true; } switch (commState.idx) { case 0: if (!commState.putGridUuid(affKey)) return false; commState.idx++; case 1: if (!commState.putLong(blockId)) return false; commState.idx++; case 2: if (!commState.putBoolean(evictExclude)) return false; commState.idx++; case 3: if (!commState.putGridUuid(fileId)) return false; commState.idx++; } return true; }
if (colocatedKey.affinityKey() == null) { dataCachePrj.transform(colocatedKey, new UpdateClosure(startOff, data)); GridGgfsBlockKey key = new GridGgfsBlockKey(colocatedKey.getFileId(), null, colocatedKey.evictExclude(), colocatedKey.getBlockId());
/** * @param blockIdx Block index. * @param fileInfo File info. * @return Block key. */ public GridGgfsBlockKey blockKey(long blockIdx, GridGgfsFileInfo fileInfo) { if (fileInfo.affinityKey() != null) return new GridGgfsBlockKey(fileInfo.id(), fileInfo.affinityKey(), fileInfo.evictExclude(), blockIdx); if (fileInfo.fileMap() != null) { GridUuid affKey = fileInfo.fileMap().affinityKey(blockIdx * fileInfo.blockSize(), false); return new GridGgfsBlockKey(fileInfo.id(), affKey, fileInfo.evictExclude(), blockIdx); } return new GridGgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), blockIdx); }
/** {@inheritDoc} */ @SuppressWarnings("fallthrough") @Override public boolean writeTo(ByteBuffer buf) { commState.setBuffer(buf); if (!commState.typeWritten) { if (!commState.putByte(directType())) return false; commState.typeWritten = true; } switch (commState.idx) { case 0: if (!commState.putGridUuid(affKey)) return false; commState.idx++; case 1: if (!commState.putLong(blockId)) return false; commState.idx++; case 2: if (!commState.putBoolean(evictExclude)) return false; commState.idx++; case 3: if (!commState.putGridUuid(fileId)) return false; commState.idx++; } return true; }
GridGgfsBlockKey key = new GridGgfsBlockKey(fileInfo.id(), fileInfo.affinityKey(), fileInfo.evictExclude(), i);
/** {@inheritDoc} */ @Override public Object affinityKey(Object key) { if (key != null && GridGgfsBlockKey.class.equals(key.getClass())) { GridGgfsBlockKey blockKey = (GridGgfsBlockKey)key; if (blockKey.affinityKey() != null) return blockKey.affinityKey(); long grpId = blockKey.getBlockId() / grpSize; return blockKey.getFileId().hashCode() + (int)(grpId ^ (grpId >>> 32)); } return super.affinityKey(key); }
/** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) @Override public GridTcpCommunicationMessageAdapter clone() { GridGgfsBlockKey _clone = new GridGgfsBlockKey(); clone0(_clone); return _clone; }
/** {@inheritDoc} */ @Override public boolean evictAllowed(GridCacheEntry entry) { Object key = entry.getKey(); return !(key instanceof GridGgfsBlockKey && ((GridGgfsBlockKey)key).evictExclude()); } }
GridGgfsBlockKey key = new GridGgfsBlockKey(fileInfo.id(), fileInfo.affinityKey(), fileInfo.evictExclude(), i);
return new GridGgfsBlockKey(fileInfo.id(), fileInfo.affinityKey(), fileInfo.evictExclude(), block); return new GridGgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), block); GridUuid affKey = fileInfo.fileMap().affinityKey(blockStart, false); return new GridGgfsBlockKey(fileInfo.id(), affKey, fileInfo.evictExclude(), block); return new GridGgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), block); locRange.expand(blockStart, fileInfo.blockSize()); return new GridGgfsBlockKey(fileInfo.id(), locRange.affinityKey(), fileInfo.evictExclude(), block);
return new GridGgfsBlockKey(fileInfo.id(), fileInfo.affinityKey(), fileInfo.evictExclude(), block); return new GridGgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), block); GridUuid affKey = fileInfo.fileMap().affinityKey(blockStart, false); return new GridGgfsBlockKey(fileInfo.id(), affKey, fileInfo.evictExclude(), block); return new GridGgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), block); locRange.expand(blockStart, fileInfo.blockSize()); return new GridGgfsBlockKey(fileInfo.id(), locRange.affinityKey(), fileInfo.evictExclude(), block);
@Override public GridTcpCommunicationMessageAdapter create(byte type) { switch (type) { case 65: return new GridGgfsAckMessage(); case 66: return new GridGgfsBlockKey(); case 67: return new GridGgfsBlocksMessage(); case 68: return new GridGgfsDeleteMessage(); case 69: return new GridGgfsFileAffinityRange(); case 70: return new GridGgfsFragmentizerRequest(); case 71: return new GridGgfsFragmentizerResponse(); case 72: return new GridGgfsSyncMessage(); default: assert false : "Invalid GGFS message type."; return null; } } }, 65, 66, 67, 68, 69,70, 71, 72);
@Override public GridTcpCommunicationMessageAdapter create(byte type) { switch (type) { case 65: return new GridGgfsAckMessage(); case 66: return new GridGgfsBlockKey(); case 67: return new GridGgfsBlocksMessage(); case 68: return new GridGgfsDeleteMessage(); case 69: return new GridGgfsFileAffinityRange(); case 70: return new GridGgfsFragmentizerRequest(); case 71: return new GridGgfsFragmentizerResponse(); case 72: return new GridGgfsSyncMessage(); default: assert false : "Invalid GGFS message type."; return null; } } }, 65, 66, 67, 68, 69,70, 71, 72);
/** * Tries to remove blocks affected by fragmentizer. If {@code cleanNonColocated} is {@code true}, will remove * non-colocated blocks as well. * * @param fileInfo File info to clean up. * @param range Range to clean up. * @param cleanNonColocated {@code True} if all blocks should be cleaned. */ public void cleanBlocks(GridGgfsFileInfo fileInfo, GridGgfsFileAffinityRange range, boolean cleanNonColocated) { long startIdx = range.startOffset() / fileInfo.blockSize(); long endIdx = range.endOffset() / fileInfo.blockSize(); if (log.isDebugEnabled()) log.debug("Cleaning blocks [fileInfo=" + fileInfo + ", range=" + range + ", cleanNonColocated=" + cleanNonColocated + ", startIdx=" + startIdx + ", endIdx=" + endIdx + ']'); try { try (GridDataLoader<GridGgfsBlockKey, byte[]> ldr = dataLoader()) { for (long idx = startIdx; idx <= endIdx; idx++) { ldr.removeData(new GridGgfsBlockKey(fileInfo.id(), range.affinityKey(), fileInfo.evictExclude(), idx)); if (cleanNonColocated) ldr.removeData(new GridGgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), idx)); } } } catch (GridException e) { log.error("Failed to clean up file range [fileInfo=" + fileInfo + ", range=" + range + ']', e); } }
/** * Tries to remove blocks affected by fragmentizer. If {@code cleanNonColocated} is {@code true}, will remove * non-colocated blocks as well. * * @param fileInfo File info to clean up. * @param range Range to clean up. * @param cleanNonColocated {@code True} if all blocks should be cleaned. */ public void cleanBlocks(GridGgfsFileInfo fileInfo, GridGgfsFileAffinityRange range, boolean cleanNonColocated) { long startIdx = range.startOffset() / fileInfo.blockSize(); long endIdx = range.endOffset() / fileInfo.blockSize(); if (log.isDebugEnabled()) log.debug("Cleaning blocks [fileInfo=" + fileInfo + ", range=" + range + ", cleanNonColocated=" + cleanNonColocated + ", startIdx=" + startIdx + ", endIdx=" + endIdx + ']'); try { try (GridDataLoader<GridGgfsBlockKey, byte[]> ldr = dataLoader()) { for (long idx = startIdx; idx <= endIdx; idx++) { ldr.removeData(new GridGgfsBlockKey(fileInfo.id(), range.affinityKey(), fileInfo.evictExclude(), idx)); if (cleanNonColocated) ldr.removeData(new GridGgfsBlockKey(fileInfo.id(), null, fileInfo.evictExclude(), idx)); } } } catch (GridException e) { log.error("Failed to clean up file range [fileInfo=" + fileInfo + ", range=" + range + ']', e); } }