/** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) @Override public GridTcpCommunicationMessageAdapter clone() { GridGgfsFileAffinityRange _clone = new GridGgfsFileAffinityRange(); clone0(_clone); return _clone; }
/** * Tries to concatenate this range with a given one. If ranges are not adjacent, will return {@code null}. * * @param range Range to concatenate with. * @return Concatenation result or {@code null} if ranges are not adjacent. */ @Nullable public GridGgfsFileAffinityRange concat(GridGgfsFileAffinityRange range) { if (endOff + 1 != range.startOff || !F.eq(affKey, range.affKey) || status != RANGE_STATUS_INITIAL) return null; return new GridGgfsFileAffinityRange(startOff, range.endOff, affKey); }
/** * Tries to concatenate this range with a given one. If ranges are not adjacent, will return {@code null}. * * @param range Range to concatenate with. * @return Concatenation result or {@code null} if ranges are not adjacent. */ @Nullable public GridGgfsFileAffinityRange concat(GridGgfsFileAffinityRange range) { if (endOff + 1 != range.startOff || !F.eq(affKey, range.affKey) || status != RANGE_STATUS_INITIAL) return null; return new GridGgfsFileAffinityRange(startOff, range.endOff, affKey); }
/** {@inheritDoc} */ @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"}) @Override public GridTcpCommunicationMessageAdapter clone() { GridGgfsFileAffinityRange _clone = new GridGgfsFileAffinityRange(); clone0(_clone); return _clone; }
/** * Splits range into collection if smaller ranges with length equal to {@code maxSize}. * * @param maxSize Split part maximum size. * @return Collection of range parts. */ public Collection<GridGgfsFileAffinityRange> split(long maxSize) { long len = endOff - startOff + 1; if (len > maxSize) { int size = (int)(len / maxSize + 1); Collection<GridGgfsFileAffinityRange> res = new ArrayList<>(size); long pos = startOff; while (pos < endOff + 1) { long end = Math.min(pos + maxSize - 1, endOff); GridGgfsFileAffinityRange part = new GridGgfsFileAffinityRange(pos, end, affKey); part.status = status; res.add(part); pos = end + 1; } return res; } else return Collections.singletonList(this); }
/** * Splits range into collection if smaller ranges with length equal to {@code maxSize}. * * @param maxSize Split part maximum size. * @return Collection of range parts. */ public Collection<GridGgfsFileAffinityRange> split(long maxSize) { long len = endOff - startOff + 1; if (len > maxSize) { int size = (int)(len / maxSize + 1); Collection<GridGgfsFileAffinityRange> res = new ArrayList<>(size); long pos = startOff; while (pos < endOff + 1) { long end = Math.min(pos + maxSize - 1, endOff); GridGgfsFileAffinityRange part = new GridGgfsFileAffinityRange(pos, end, affKey); part.status = status; res.add(part); pos = end + 1; } return res; } else return Collections.singletonList(this); }
/** * Updates range status at given position (will split range into two if necessary). * * @param origIdx Original range index. * @param orig Original range at index. * @param update Range being updated. * @param status New status for range. */ private void updateRangeStatus0(int origIdx, GridGgfsFileAffinityRange orig, GridGgfsFileAffinityRange update, int status) { assert F.eq(orig.affinityKey(), update.affinityKey()); assert ranges.get(origIdx) == orig; if (orig.regionEqual(update)) ranges.set(origIdx, new GridGgfsFileAffinityRange(update, status)); else { // If range was expanded, new one should be larger. assert orig.endOffset() > update.endOffset(); ranges.set(origIdx, new GridGgfsFileAffinityRange(update, status)); ranges.add(origIdx + 1, new GridGgfsFileAffinityRange(update.endOffset() + 1, orig.endOffset(), orig.affinityKey())); } }
/** * Updates range status at given position (will split range into two if necessary). * * @param origIdx Original range index. * @param orig Original range at index. * @param update Range being updated. * @param status New status for range. */ private void updateRangeStatus0(int origIdx, GridGgfsFileAffinityRange orig, GridGgfsFileAffinityRange update, int status) { assert F.eq(orig.affinityKey(), update.affinityKey()); assert ranges.get(origIdx) == orig; if (orig.regionEqual(update)) { ranges.set(origIdx, new GridGgfsFileAffinityRange(update, status)); } else { // If range was expanded, new one should be larger. assert orig.endOffset() > update.endOffset(); ranges.set(origIdx, new GridGgfsFileAffinityRange(update, status)); ranges.add(origIdx + 1, new GridGgfsFileAffinityRange(update.endOffset() + 1, orig.endOffset(), orig.affinityKey())); } }
/** * Gets initial affinity range. This range will have 0 length and will start from first * non-occupied file block. * * @param fileInfo File info to build initial range for. * @return Affinity range. */ private GridGgfsFileAffinityRange initialStreamRange(GridGgfsFileInfo fileInfo) { if (!ggfsCtx.configuration().isFragmentizerEnabled()) return null; if (!Boolean.parseBoolean(fileInfo.properties().get(GridGgfs.PROP_PREFER_LOCAL_WRITES))) return null; int blockSize = fileInfo.blockSize(); // Find first non-occupied block offset. long off = ((fileInfo.length() + blockSize - 1) / blockSize) * blockSize; // Need to get last affinity key and reuse it if we are on the same node. long lastBlockOff = off - fileInfo.blockSize(); if (lastBlockOff < 0) lastBlockOff = 0; GridGgfsFileMap map = fileInfo.fileMap(); GridUuid prevAffKey = map == null ? null : map.affinityKey(lastBlockOff, false); GridUuid affKey = data.nextAffinityKey(prevAffKey); return affKey == null ? null : new GridGgfsFileAffinityRange(off, off, affKey); }
/** * Gets initial affinity range. This range will have 0 length and will start from first * non-occupied file block. * * @param fileInfo File info to build initial range for. * @return Affinity range. */ private GridGgfsFileAffinityRange initialStreamRange(GridGgfsFileInfo fileInfo) { if (!ggfsCtx.configuration().isFragmentizerEnabled()) return null; if (!Boolean.parseBoolean(fileInfo.properties().get(GridGgfs.PROP_PREFER_LOCAL_WRITES))) return null; int blockSize = fileInfo.blockSize(); // Find first non-occupied block offset. long off = ((fileInfo.length() + blockSize - 1) / blockSize) * blockSize; // Need to get last affinity key and reuse it if we are on the same node. long lastBlockOff = off - fileInfo.blockSize(); if (lastBlockOff < 0) lastBlockOff = 0; GridGgfsFileMap map = fileInfo.fileMap(); GridUuid prevAffKey = map == null ? null : map.affinityKey(lastBlockOff, false); GridUuid affKey = data.nextAffinityKey(prevAffKey); return affKey == null ? null : new GridGgfsFileAffinityRange(off, off, affKey); }
@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);