private byte[] readv(final long addr, boolean charChunk, SerializationContext serContext) { SortedSet<Long> tails = serContext.textBufferAddresses().tailSet(addr); int nPages = Math.min(tails.size(), 16); // minimum 16 MB final long[] addrs; if (nPages == 0) { addrs = new long[] {addr}; } else { addrs = new long[nPages]; int n = 0; for (long l : tails) { addrs[n++] = l; if (n == nPages) { break; } } } final byte[][] tmp; try { // read from disk tmp = _paged.readv(addrs); } catch (IOException e) { throw new IllegalStateException("read from disk failed", e); } for (int i = 1; i < nPages; i++) { final long tmpAddr = addrs[i]; if ((tmpAddr & BIG_STRING_MASK) != 0L) { // is big string? _cache.putIfAbsent(tmpAddr, tmp[i]); } else { char[] cc = decompress(compressor, tmp[i]); _cache.putIfAbsent(tmpAddr, cc); } } return tmp[0]; }
private byte[] prepareBigString(final int addr) { assert ((addr & BIG_STRING_MASK) != 0L); byte[] b = (byte[]) _cache.get(addr); if (b == null) { // read from disk if (_tranfered) { b = readv(addr, false, _serContext); } else { b = read(addr); } assert (b != null) : "Illegal addr: " + addr; _cache.putIfAbsent(addr, b); } return b; }
private char[] prepareCharChunk(final int page) { final long addr = chunkKey(page * DEFAULT_BLOCK_SIZE_L); char[] cc = (char[]) _cache.get(addr); if (cc == null) { // read from disk final byte[] v; if (_tranfered) { v = readv(addr, true, _serContext); } else { v = read(addr); } assert (v != null) : "Illegal addr: " + addr + ", page: " + page + ", ccwritten:" + ccwritten + ", lccwritten:" + lccwritten; cc = decompress(compressor, v); _cache.putIfAbsent(addr, cc); } return cc; }