private static void eagerlyCleanupReadBuffersFromIdleConnection(CassandraClient idleClient, InetSocketAddress host) { // eagerly cleanup idle-connection read buffer to keep a smaller memory footprint try { TTransport transport = idleClient.getInputProtocol().getTransport(); if (transport instanceof TFramedTransport) { Field readBuffer = ((TFramedTransport) transport).getClass().getDeclaredField("readBuffer_"); readBuffer.setAccessible(true); TMemoryInputTransport memoryInputTransport = (TMemoryInputTransport) readBuffer.get(transport); byte[] underlyingBuffer = memoryInputTransport.getBuffer(); if (underlyingBuffer != null && memoryInputTransport.getBytesRemainingInBuffer() == 0) { log.debug("During {} check-in, cleaned up a read buffer of {} bytes of host {}", UnsafeArg.of("pool", idleClient), SafeArg.of("bufferLength", underlyingBuffer.length), SafeArg.of("host", CassandraLogHelper.host(host))); memoryInputTransport.reset(PtBytes.EMPTY_BYTE_ARRAY); } } } catch (Exception e) { log.debug("Couldn't clean up read buffers on pool check-in.", e); } }
private static void eagerlyCleanupReadBuffersFromIdleConnection(CassandraClient idleClient, InetSocketAddress host) { // eagerly cleanup idle-connection read buffer to keep a smaller memory footprint try { TTransport transport = idleClient.getInputProtocol().getTransport(); if (transport instanceof TFramedTransport) { Field readBuffer = ((TFramedTransport) transport).getClass().getDeclaredField("readBuffer_"); readBuffer.setAccessible(true); TMemoryInputTransport memoryInputTransport = (TMemoryInputTransport) readBuffer.get(transport); byte[] underlyingBuffer = memoryInputTransport.getBuffer(); if (underlyingBuffer != null && memoryInputTransport.getBytesRemainingInBuffer() == 0) { log.debug("During {} check-in, cleaned up a read buffer of {} bytes of host {}", UnsafeArg.of("pool", idleClient), SafeArg.of("bufferLength", underlyingBuffer.length), SafeArg.of("host", CassandraLogHelper.host(host))); memoryInputTransport.reset(PtBytes.EMPTY_BYTE_ARRAY); } } } catch (Exception e) { log.debug("Couldn't clean up read buffers on pool check-in.", e); } }