Search in sources :

Example 6 with MemoryBlock

use of org.apache.carbondata.core.memory.MemoryBlock in project carbondata by apache.

the class VarLengthColumnPageBase method ensureMemory.

/**
 * reallocate memory if capacity length than current size + request size
 */
protected void ensureMemory(int requestSize) throws MemoryException {
    if (totalLength + requestSize > capacity) {
        int newSize = Math.max(2 * capacity, totalLength + requestSize);
        MemoryBlock newBlock = UnsafeMemoryManager.allocateMemoryWithRetry(taskId, newSize);
        CarbonUnsafe.getUnsafe().copyMemory(baseAddress, baseOffset, newBlock.getBaseObject(), newBlock.getBaseOffset(), capacity);
        UnsafeMemoryManager.INSTANCE.freeMemory(taskId, memoryBlock);
        memoryBlock = newBlock;
        baseAddress = newBlock.getBaseObject();
        baseOffset = newBlock.getBaseOffset();
        capacity = newSize;
    }
}
Also used : MemoryBlock(org.apache.carbondata.core.memory.MemoryBlock)

Example 7 with MemoryBlock

use of org.apache.carbondata.core.memory.MemoryBlock in project carbondata by apache.

the class UnsafeMemoryDMStore method increaseMemory.

private void increaseMemory() throws MemoryException {
    MemoryBlock allocate = UnsafeMemoryManager.allocateMemoryWithRetry(taskId, allocatedSize + capacity);
    getUnsafe().copyMemory(memoryBlock.getBaseObject(), memoryBlock.getBaseOffset(), allocate.getBaseObject(), allocate.getBaseOffset(), runningLength);
    UnsafeMemoryManager.INSTANCE.freeMemory(taskId, memoryBlock);
    allocatedSize = allocatedSize + capacity;
    memoryBlock = allocate;
}
Also used : MemoryBlock(org.apache.carbondata.core.memory.MemoryBlock)

Example 8 with MemoryBlock

use of org.apache.carbondata.core.memory.MemoryBlock in project carbondata by apache.

the class UnsafeSortDataRows method createUnsafeRowPage.

private UnsafeCarbonRowPage createUnsafeRowPage() {
    MemoryBlock baseBlock = UnsafeMemoryManager.allocateMemoryWithRetry(this.taskId, inMemoryChunkSize);
    boolean isSaveToDisk = UnsafeSortMemoryManager.INSTANCE.isMemoryAvailable(baseBlock.size());
    if (!isSaveToDisk) {
        // merge and spill in-memory pages to disk if memory is not enough
        unsafeInMemoryIntermediateFileMerger.tryTriggerInMemoryMerging(true);
    }
    return new UnsafeCarbonRowPage(tableFieldStat, baseBlock, taskId, true);
}
Also used : MemoryBlock(org.apache.carbondata.core.memory.MemoryBlock)

Example 9 with MemoryBlock

use of org.apache.carbondata.core.memory.MemoryBlock in project carbondata by apache.

the class UnsafeFixLengthColumnPage method ensureMemory.

/**
 * reallocate memory if capacity length than current size + request size
 */
protected void ensureMemory(int requestSize) {
    checkDataFileSize();
    if (totalLength + requestSize > capacity) {
        int newSize = Math.max(2 * capacity, totalLength + requestSize);
        MemoryBlock newBlock = UnsafeMemoryManager.allocateMemoryWithRetry(taskId, newSize);
        CarbonUnsafe.getUnsafe().copyMemory(baseAddress, baseOffset, newBlock.getBaseObject(), newBlock.getBaseOffset(), totalLength);
        UnsafeMemoryManager.INSTANCE.freeMemory(taskId, memoryBlock);
        memoryBlock = newBlock;
        baseAddress = newBlock.getBaseObject();
        baseOffset = newBlock.getBaseOffset();
        capacity = newSize;
    }
}
Also used : MemoryBlock(org.apache.carbondata.core.memory.MemoryBlock)

Example 10 with MemoryBlock

use of org.apache.carbondata.core.memory.MemoryBlock in project carbondata by apache.

the class UnsafeMemoryManager method allocateMemory.

public synchronized MemoryBlock allocateMemory(long memoryRequested) {
    if (memoryUsed + memoryRequested <= totalMemory) {
        MemoryBlock allocate = allocator.allocate(memoryRequested);
        memoryUsed += allocate.size();
        LOGGER.info("Memory block is created with size " + allocate.size() + " Total memory used " + memoryUsed + " memory left " + (getAvailableMemory()));
        return allocate;
    }
    return null;
}
Also used : MemoryBlock(org.apache.carbondata.core.memory.MemoryBlock)

Aggregations

MemoryBlock (org.apache.carbondata.core.memory.MemoryBlock)15 CarbonSortKeyAndGroupByException (org.apache.carbondata.processing.sortandgroupby.exception.CarbonSortKeyAndGroupByException)3 File (java.io.File)2 IOException (java.io.IOException)2 Random (java.util.Random)1 Semaphore (java.util.concurrent.Semaphore)1 IntPointerBuffer (org.apache.carbondata.core.memory.IntPointerBuffer)1 UnsafeRowComparator (org.apache.carbondata.processing.loading.sort.unsafe.comparator.UnsafeRowComparator)1 UnsafeRowComparatorForNormalDims (org.apache.carbondata.processing.loading.sort.unsafe.comparator.UnsafeRowComparatorForNormalDims)1 UnsafeCarbonRow (org.apache.carbondata.processing.loading.sort.unsafe.holder.UnsafeCarbonRow)1 TimSort (org.apache.carbondata.processing.loading.sort.unsafe.sort.TimSort)1 UnsafeIntSortDataFormat (org.apache.carbondata.processing.loading.sort.unsafe.sort.UnsafeIntSortDataFormat)1 CarbonSortKeyAndGroupByException (org.apache.carbondata.processing.sort.exception.CarbonSortKeyAndGroupByException)1