private synchronized boolean tryEvict()

in src/main/java/com/microsoft/azure/datalake/store/ReadBufferManager.java [199:234]


    private synchronized boolean tryEvict() {
        ReadBuffer nodeToEvict = null;
        if (completedReadList.size() <= 0) return false;  // there are no evict-able buffers

        // first, try buffers where all bytes have been consumed (approximated as first and last bytes consumed)
        for (ReadBuffer buf : completedReadList) {
            if (buf.firstByteConsumed && buf.lastByteConsumed) {
                nodeToEvict = buf;
                break;
            }
        }
        if (nodeToEvict != null) return evict(nodeToEvict);

        // next, try buffers where any bytes have been consumed (may be a bad idea? have to experiment and see)
        for (ReadBuffer buf : completedReadList) {
            if (buf.anyByteConsumed) {
                nodeToEvict = buf;
                break;
            }
        }
        if (nodeToEvict != null) return evict(nodeToEvict);

        // next, try any old nodes that have not been consumed
        long earliestBirthday = Long.MAX_VALUE;
        for (ReadBuffer buf : completedReadList) {
            if (buf.birthday < earliestBirthday) {
                nodeToEvict = buf;
                earliestBirthday = buf.birthday;
            }
        }
        if ((currentTimeMillis() - earliestBirthday > thresholdAgeMilliseconds) && (nodeToEvict != null) )
        { return evict(nodeToEvict); }

        // nothing can be evicted
        return false;
    }