Search in sources :

Example 1 with GlobalMemoryManager

use of org.apache.phoenix.memory.GlobalMemoryManager in project phoenix by apache.

the class TenantCacheTest method testInvalidateClosesMemoryChunk.

@Test
public void testInvalidateClosesMemoryChunk() throws SQLException {
    int maxServerCacheTimeToLive = 10000;
    long maxBytes = 1000;
    int maxWaitMs = 1000;
    GlobalMemoryManager memoryManager = new GlobalMemoryManager(maxBytes, maxWaitMs);
    TenantCacheImpl newTenantCache = new TenantCacheImpl(memoryManager, maxServerCacheTimeToLive);
    ImmutableBytesPtr cacheId = new ImmutableBytesPtr(Bytes.toBytes("a"));
    ImmutableBytesWritable cachePtr = new ImmutableBytesWritable(Bytes.toBytes("a"));
    newTenantCache.addServerCache(cacheId, cachePtr, ByteUtil.EMPTY_BYTE_ARRAY, cacheFactory, true);
    assertEquals(maxBytes - 1, memoryManager.getAvailableMemory());
    newTenantCache.removeServerCache(cacheId);
    assertEquals(maxBytes, memoryManager.getAvailableMemory());
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) GlobalMemoryManager(org.apache.phoenix.memory.GlobalMemoryManager) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) Test(org.junit.Test)

Example 2 with GlobalMemoryManager

use of org.apache.phoenix.memory.GlobalMemoryManager in project phoenix by apache.

the class SpoolingResultIteratorTest method testSpooling.

private void testSpooling(int threshold, long maxSizeSpool) throws Throwable {
    Tuple[] results = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(1))), new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(1))) };
    PeekingResultIterator iterator = new MaterializedResultIterator(Arrays.asList(results));
    Tuple[] expectedResults = new Tuple[] { new SingleKeyValueTuple(new KeyValue(A, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(1))), new SingleKeyValueTuple(new KeyValue(B, SINGLE_COLUMN_FAMILY, SINGLE_COLUMN, Bytes.toBytes(1))) };
    MemoryManager memoryManager = new DelegatingMemoryManager(new GlobalMemoryManager(threshold, 0));
    ResultIterator scanner = new SpoolingResultIterator(SpoolingMetricsHolder.NO_OP_INSTANCE, MemoryMetricsHolder.NO_OP_INSTANCE, iterator, memoryManager, threshold, maxSizeSpool, "/tmp");
    AssertResults.assertResults(scanner, expectedResults);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) GlobalMemoryManager(org.apache.phoenix.memory.GlobalMemoryManager) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) MemoryManager(org.apache.phoenix.memory.MemoryManager) DelegatingMemoryManager(org.apache.phoenix.memory.DelegatingMemoryManager) GlobalMemoryManager(org.apache.phoenix.memory.GlobalMemoryManager) Tuple(org.apache.phoenix.schema.tuple.Tuple) SingleKeyValueTuple(org.apache.phoenix.schema.tuple.SingleKeyValueTuple) DelegatingMemoryManager(org.apache.phoenix.memory.DelegatingMemoryManager)

Example 3 with GlobalMemoryManager

use of org.apache.phoenix.memory.GlobalMemoryManager in project phoenix by apache.

the class TenantCacheTest method testTimeoutClosesMemoryChunk.

@Test
public void testTimeoutClosesMemoryChunk() throws Exception {
    int maxServerCacheTimeToLive = 10;
    long maxBytes = 1000;
    int maxWaitMs = 10;
    GlobalMemoryManager memoryManager = new GlobalMemoryManager(maxBytes, maxWaitMs);
    ManualTicker ticker = new ManualTicker();
    TenantCacheImpl cache = new TenantCacheImpl(memoryManager, maxServerCacheTimeToLive, ticker);
    ImmutableBytesPtr cacheId1 = new ImmutableBytesPtr(Bytes.toBytes("a"));
    ImmutableBytesWritable cachePtr = new ImmutableBytesWritable(Bytes.toBytes("a"));
    cache.addServerCache(cacheId1, cachePtr, ByteUtil.EMPTY_BYTE_ARRAY, cacheFactory, true);
    assertEquals(maxBytes - 1, memoryManager.getAvailableMemory());
    ticker.time += (maxServerCacheTimeToLive + 1) * 1000000;
    cache.cleanUp();
    assertEquals(maxBytes, memoryManager.getAvailableMemory());
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) GlobalMemoryManager(org.apache.phoenix.memory.GlobalMemoryManager) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) Test(org.junit.Test)

Aggregations

GlobalMemoryManager (org.apache.phoenix.memory.GlobalMemoryManager)3 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)2 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)2 Test (org.junit.Test)2 KeyValue (org.apache.hadoop.hbase.KeyValue)1 DelegatingMemoryManager (org.apache.phoenix.memory.DelegatingMemoryManager)1 MemoryManager (org.apache.phoenix.memory.MemoryManager)1 SingleKeyValueTuple (org.apache.phoenix.schema.tuple.SingleKeyValueTuple)1 Tuple (org.apache.phoenix.schema.tuple.Tuple)1