@Override protected Transaction wrap(Transaction transaction) { return new CachingTransaction(transaction); } }
@Override public void put(TableReference tableRef, Map<Cell, byte[]> values) { super.put(tableRef, values); addToCache(tableRef, values); }
private void cacheLoadedCells(TableReference tableRef, Set<Cell> toLoad, Map<Cell, byte[]> toCache) { for (Cell key : toLoad) { byte[] value = toCache.get(key); if (value == null) { value = PtBytes.EMPTY_BYTE_ARRAY; } cacheLoadedCell(tableRef, key, value); } }
@Override public Map<Cell, byte[]> get(TableReference tableRef, Set<Cell> cells) { if (cells.isEmpty()) { return ImmutableMap.of(); } Set<Cell> toLoad = Sets.newHashSet(); Map<Cell, byte[]> cacheHit = Maps.newHashMapWithExpectedSize(cells.size()); for (Cell cell : cells) { byte[] val = getCachedCellIfPresent(tableRef, cell); if (val != null) { if (val.length > 0) { cacheHit.put(cell, val); } } else { toLoad.add(cell); } } final Map<Cell, byte[]> loaded = super.get(tableRef, toLoad); cacheLoadedCells(tableRef, toLoad, loaded); cacheHit.putAll(loaded); return cacheHit; }
cacheLoadedRows(tableRef, loaded.values()); return loaded; } else { boolean shouldLoad = false; for (byte[] col : columnSelection.getSelectedColumns()) { byte[] val = getCachedCellIfPresent(tableRef, Cell.create(row, col)); if (val == null) { shouldLoad = true; cacheLoadedRows(tableRef, results.values()); inCache.putAll(results); return inCache.build();
/** * Hack to get reference to underlying {@link SnapshotTransaction}. See how transaction managers are composed at * {@link AtlasDbTestCase#setUp()}. */ private static SnapshotTransaction unwrapSnapshotTransaction(Transaction cachingTransaction) { Transaction unwrapped = ((CachingTransaction) cachingTransaction).delegate(); return (SnapshotTransaction) unwrapped; }
@Override public Map<Cell, byte[]> get(TableReference tableRef, Set<Cell> cells) { if (cells.isEmpty()) { return ImmutableMap.of(); } Set<Cell> toLoad = Sets.newHashSet(); Map<Cell, byte[]> cacheHit = Maps.newHashMapWithExpectedSize(cells.size()); for (Cell cell : cells) { byte[] val = getCachedCellIfPresent(tableRef, cell); if (val != null) { if (val.length > 0) { cacheHit.put(cell, val); } } else { toLoad.add(cell); } } final Map<Cell, byte[]> loaded = super.get(tableRef, toLoad); cacheLoadedCells(tableRef, toLoad, loaded); cacheHit.putAll(loaded); return cacheHit; }
cacheLoadedRows(tableRef, loaded.values()); return loaded; } else { boolean shouldLoad = false; for (byte[] col : columnSelection.getSelectedColumns()) { byte[] val = getCachedCellIfPresent(tableRef, Cell.create(row, col)); if (val == null) { shouldLoad = true; cacheLoadedRows(tableRef, results.values()); inCache.putAll(results); return inCache.build();
@Override protected Transaction wrap(Transaction transaction) { return new CachingTransaction(transaction); } }
private void addToCache(TableReference tableRef, Map<Cell, byte[]> values) { for (Map.Entry<Cell, byte[]> e : values.entrySet()) { byte[] value = e.getValue(); if (value == null) { value = PtBytes.EMPTY_BYTE_ARRAY; } cacheLoadedCell(tableRef, e.getKey(), value); } }
@Override public final void delete(TableReference tableRef, Set<Cell> cells) { super.delete(tableRef, cells); addToCache(tableRef, Cells.constantValueMap(cells, PtBytes.EMPTY_BYTE_ARRAY)); }
@Override protected Transaction wrap(Transaction transaction) { return new CachingTransaction(transaction); } }
private void cacheLoadedRows(TableReference tableRef, Iterable<RowResult<byte[]>> rowView) { for (RowResult<byte[]> loadedRow : rowView) { for (Map.Entry<Cell, byte[]> e : loadedRow.getCells()) { cacheLoadedCell(tableRef, e.getKey(), e.getValue()); } } }
@Override public void put(TableReference tableRef, Map<Cell, byte[]> values) { super.put(tableRef, values); addToCache(tableRef, values); }
@Override protected Transaction wrap(Transaction transaction) { return new CachingTransaction(transaction); } }
private void cacheLoadedCells(TableReference tableRef, Set<Cell> toLoad, Map<Cell, byte[]> toCache) { for (Cell key : toLoad) { byte[] value = toCache.get(key); if (value == null) { value = PtBytes.EMPTY_BYTE_ARRAY; } cacheLoadedCell(tableRef, key, value); } }
@Override public final void delete(TableReference tableRef, Set<Cell> cells) { super.delete(tableRef, cells); addToCache(tableRef, Cells.constantValueMap(cells, PtBytes.EMPTY_BYTE_ARRAY)); }
private void addToCache(TableReference tableRef, Map<Cell, byte[]> values) { for (Map.Entry<Cell, byte[]> e : values.entrySet()) { byte[] value = e.getValue(); if (value == null) { value = PtBytes.EMPTY_BYTE_ARRAY; } cacheLoadedCell(tableRef, e.getKey(), value); } }
private void cacheLoadedRows(TableReference tableRef, Iterable<RowResult<byte[]>> rowView) { for (RowResult<byte[]> loadedRow : rowView) { for (Map.Entry<Cell, byte[]> e : loadedRow.getCells()) { cacheLoadedCell(tableRef, e.getKey(), e.getValue()); } } }