Search in sources :

Example 11 with MemoryBlock

use of io.mycat.memory.unsafe.memory.MemoryBlock in project Mycat-Server by MyCATApache.

the class DataNodeMemoryManager method cleanUpAllAllocatedMemory.

/**
   * Clean up all allocated memory and pages. Returns the number of bytes freed. A non-zero return
   * value can be used to detect memory leaks.
   */
public long cleanUpAllAllocatedMemory() {
    synchronized (this) {
        for (MemoryConsumer c : consumers) {
            if (c != null && c.getUsed() > 0) {
                // In case of failed task, it's normal to see leaked memory
                logger.warn("leak " + JavaUtils.bytesToString(c.getUsed()) + " memory from " + c);
            }
        }
        consumers.clear();
        for (MemoryBlock page : pageTable) {
            if (page != null) {
                logger.warn("leak a page: " + page + " in task " + connectionAttemptId);
                memoryManager.tungstenMemoryAllocator().free(page);
            }
        }
        Arrays.fill(pageTable, null);
    }
    // release the memory that is not used by any consumer.
    memoryManager.releaseExecutionMemory(acquiredButNotUsed, connectionAttemptId, tungstenMemoryMode);
    return memoryManager.releaseAllExecutionMemoryForConnection(connectionAttemptId);
}
Also used : MemoryBlock(io.mycat.memory.unsafe.memory.MemoryBlock)

Aggregations

MemoryBlock (io.mycat.memory.unsafe.memory.MemoryBlock)11 CharArray (io.mycat.memory.unsafe.array.CharArray)1 LongArray (io.mycat.memory.unsafe.array.LongArray)1 TestMemoryConsumer (io.mycat.memory.unsafe.memory.TestMemoryConsumer)1 TestMemoryManager (io.mycat.memory.unsafe.memory.TestMemoryManager)1 DataNodeMemoryManager (io.mycat.memory.unsafe.memory.mm.DataNodeMemoryManager)1 MycatPropertyConf (io.mycat.memory.unsafe.utils.MycatPropertyConf)1 File (java.io.File)1 Test (org.junit.Test)1