@Override public CachedData encode(HFileBlock block) { ByteBuffer bb = ByteBuffer.allocate(block.getSerializedLength()); block.serialize(bb, true); return new CachedData(0, bb.array(), CachedData.MAX_SIZE); }
@Override public String toString() { return "EVCacheEvent [call=" + call + ", appName=" + appName + ", cacheName=" + cacheName + ", Num of Clients=" + clients.size() + ", keys=" + keys + ", canonicalKeys=" + canonicalKeys + ", ttl=" + ttl + ", cachedData=" + (cachedData != null ? "[ Flags : " + cachedData.getFlags() + "; Data Array length : " +cachedData.getData().length + "] " : "null") + ", Attributes=" + data + "]"; }
+ " is smaller than the key size. Will not be able to proceed. key size = " + key.length()); final int len = cd.getData().length; checksum.update(cd.getData(), 0, len); final long checkSumValue = checksum.getValue(); + checkSumValue + "; Checksum Duration : " + (System.nanoTime() - sTime)); chunkData[0] = decodingTranscoder.encode(numOfChunks + ":" + actualChunkSize + ":" + lastChunkSize + ":" + cd .getFlags() + ":" + checkSumValue); for (int i = 1; i < numOfChunks; i++) { int lengthOfArray = actualChunkSize; System.arraycopy(cd.getData(), srcPos, dest, 0, lengthOfArray); if (actualChunkSize > lengthOfArray) { for (int j = lengthOfArray; j < actualChunkSize; j++) { chunkData[i] = new CachedData(SPECIAL_BYTEARRAY, dest, Integer.MAX_VALUE);
if (log.isDebugEnabled()) log.debug("Chunk Key " + _key + "; Value : " + cd); if (cd == null) continue; final byte[] val = cd.getData(); for (int j = 0; j < ciKeys.size(); j++) { final String skey = ciKeys.get(j); final byte[] sval = dataMap.get(skey).getData(); sb.append(skey + "=" + sval.length + "\n"); final CachedData cd = new CachedData(ci.getFlags(), data, Integer.MAX_VALUE); returnMap.put(ci.getKey(), tc.decode(cd)); } else {
@Override public HFileBlock decode(CachedData d) { try { ByteBuff buf = new SingleByteBuff(ByteBuffer.wrap(d.getData())); return (HFileBlock) HFileBlock.BLOCK_DESERIALIZER.deserialize(buf, true, MemoryType.EXCLUSIVE); } catch (IOException e) { LOG.warn("Error deserializing data from memcached",e); } return null; }
@Override public String decode(CachedData d) { return new String(d.getData()); }
@Override public T decode(CachedData cachedData) { int flags = cachedData.getFlags(); boolean compressed = (flags & compressionFlag) > 0; byte[] decodedBytes = cachedData.getData(); if (compressed) { decodedBytes = decompressor.decompress(cachedData.getData()); } return wrappedTranscoder.decode(new CachedData(flags, decodedBytes, getMaxSize())); }
if (log.isDebugEnabled()) log.debug("Chunk Key " + _key + "; Value : " + cd); if (cd == null) continue; final byte[] val = cd.getData(); for (int j = 0; j < ciKeys.size(); j++) { final String skey = ciKeys.get(j); final byte[] sval = dataMap.get(skey).getData(); sb.append(skey + "=" + sval.length + "\n"); final CachedData cd = new CachedData(ci.getFlags(), data, Integer.MAX_VALUE); returnMap.put(ci.getKey(), tc.decode(cd)); } else {
public void gotData(String k, int flags, long cas, byte[] data) { if (!key.equals(k)) log.warn("Wrong key returned. Key - {}; Returned Key {}", key, k); if (data != null) { if(getAndTouchDataSize == null) getAndTouchDataSize = EVCacheMetricsFactory.getDistributionSummary(appName + "-GATOperation-DataSize", appName, serverGroup.getName()); if (getAndTouchDataSize != null) getAndTouchDataSize.record(data.length); } val = new CASValue<T>(cas, tc.decode(new CachedData(flags, data, tc.getMaxSize()))); } });
public EVCacheLatch add(String canonicalKey, CachedData cd, int timeToLive, Policy policy) throws Exception { if (cd == null) return null; addDataSizeSummary.record(cd.getData().length); addTTLSummary.record(timeToLive); final EVCacheClient[] clients = _pool.getEVCacheClientForWrite(); final EVCacheLatchImpl latch = new EVCacheLatchImpl(policy, clients.length - _pool.getWriteOnlyEVCacheClients().length, _appName){ @Override public void onComplete(OperationFuture<?> operationFuture) throws Exception { super.onComplete(operationFuture); if (getPendingFutureCount() == 0 && fixup.get()) { final RemoteRequest req = new RemoteRequest(this, canonicalKey, timeToLive); threadPool.submit(req); } } }; for (EVCacheClient client : clients) { final Future<Boolean> future = client.add(canonicalKey, timeToLive, cd, ct, latch); if(log.isDebugEnabled()) log.debug("ADD : Op Submitted : APP " + _appName + ", key " + canonicalKey + "; future : " + future); } return latch; }
@Override public CachedData encode(T object) { final CachedData encodedCachedData = wrappedTranscoder.encode(object); final byte[] encodedBytes = encodedCachedData.getData(); if (encodedBytes.length < compressionThresholdByteLength) { return encodedCachedData; } final byte[] compressed = compressor.compress(encodedBytes); final int flags = encodedCachedData.getFlags() | compressionFlag; return new CachedData(flags, compressed, getMaxSize()); }
if (_cd == null) continue; final byte[] val = _cd.getData(); for (int j = 0; j < keys.size(); j++) { final String skey = keys.get(j); final byte[] sval = (byte[]) dataMap.get(skey).getData(); sb.append(skey + "=" + sval.length + "\n"); final Transcoder<T> transcoder = (tc == null ? (Transcoder<T>) evcacheMemcachedClient.getTranscoder() : tc); return transcoder.decode(new CachedData(ci.getFlags(), data, Integer.MAX_VALUE));
@Override public CachedData encode(String o) { return new CachedData(0, o.getBytes(), getMaxSize()); } }
final int dataSize = ((CachedData) value).getData().length; if (enableChunking.get() && dataSize > chunkSize.get()) { final CachedData[] cd = createChunks(value, key);
if (_cd == null) continue; final byte[] val = _cd.getData(); for (int j = 0; j < keys.size(); j++) { final String skey = keys.get(j); final byte[] sval = (byte[]) dataMap.get(skey).getData(); sb.append(skey + "=" + sval.length + "\n"); final Transcoder<T> transcoder = (tc == null ? (Transcoder<T>) evcacheMemcachedClient.getTranscoder() : tc); return transcoder.decode(new CachedData(ci.getFlags(), data, Integer.MAX_VALUE)); });