public static byte[] longsBytes(long[] _longs) { int len = _longs.length; byte[] bytes = new byte[len * 8]; for (int i = 0; i < len; i++) { longBytes(_longs[i], bytes, i * 8); } return bytes; }
public static byte[] longBytes(long _v) { return longBytes(_v, new byte[8], 0); }
@Override public BolBuffer toRawEntry( byte[] key, long timestamp, boolean tombstoned, long version, byte[] value, BolBuffer rawEntryBuffer) throws IOException { rawEntryBuffer.allocate(keyLength + 8 + 1 + 8 + LABUtils.rawArrayLength(value)); int o = 0; o = LABUtils.writeFixedWidthByteArray(key, rawEntryBuffer.bytes, o); UIO.longBytes(timestamp, rawEntryBuffer.bytes, o); o += 8; rawEntryBuffer.bytes[o] = tombstoned ? (byte) 1 : (byte) 0; o++; UIO.longBytes(version, rawEntryBuffer.bytes, o); o += 8; LABUtils.writeByteArray(value, rawEntryBuffer.bytes, o); return rawEntryBuffer; }
@Override public BolBuffer toRawEntry( byte[] key, long timestamp, boolean tombstoned, long version, byte[] value, BolBuffer rawEntryBuffer) throws IOException { rawEntryBuffer.allocate(LABUtils.rawArrayLength(key) + 8 + 1 + 8 + LABUtils.rawArrayLength(value)); int o = 0; o = LABUtils.writeByteArray(key, rawEntryBuffer.bytes, o); UIO.longBytes(timestamp, rawEntryBuffer.bytes, o); o += 8; rawEntryBuffer.bytes[o] = tombstoned ? (byte) 1 : (byte) 0; o++; UIO.longBytes(version, rawEntryBuffer.bytes, o); o += 8; LABUtils.writeByteArray(value, rawEntryBuffer.bytes, o); return rawEntryBuffer; }
public int load() throws Exception { int collisions = 0; PointerReadableByteBufferFile readable = readOnlyFile.pointerReadable(-1); long o = 0; try { while (o < readable.length()) { int keyLength = readable.readInt(o); o += 4; byte[] key = new byte[keyLength]; readable.read(o, key, 0, keyLength); o += keyLength; byte[] got = offsetKeyOffsetValueCache.get(key); if (got != null) { collisions++; } long valueFp = o; int valueLength = readable.readInt(o); o += 4; o += valueLength; if (valueLength > 0) { offsetKeyOffsetValueCache.put(key, UIO.longBytes(valueFp)); } else { offsetKeyOffsetValueCache.remove(key); } } } catch (Exception x) { LOG.error("Failed to full load labMeta: {} fp:{} length:{}", new Object[] { metaFile, o, metaFile.length() }, x); } return collisions; }
public boolean append(byte[] key, byte[] value, boolean flush) throws Exception { appender.appendInt(key.length); appender.append(key, 0, key.length); long valuePointer = appender.getFilePointer(); appender.appendInt(value.length); appender.append(value, 0, value.length); if (flush) { appender.flush(flush); ReadOnlyFile current = readOnlyFile; readOnlyFile = new ReadOnlyFile(metaFile); current.close(); } if (value.length == 0) { offsetKeyOffsetValueCache.remove(key); return true; } else { byte[] had = offsetKeyOffsetValueCache.get(key); offsetKeyOffsetValueCache.put(key, UIO.longBytes(valuePointer)); return had != null; } }