Search in sources :

Example 6 with MemoryChunk

use of org.apache.phoenix.memory.MemoryManager.MemoryChunk in project phoenix by apache.

the class MemoryManagerTest method testResizeWaitForMemoryAvailable.

@Ignore("See PHOENIX-2840")
@Test
public void testResizeWaitForMemoryAvailable() throws Exception {
    final GlobalMemoryManager gmm = spy(new GlobalMemoryManager(100, 80));
    final ChildMemoryManager rmm1 = new ChildMemoryManager(gmm, 100);
    final ChildMemoryManager rmm2 = new ChildMemoryManager(gmm, 100);
    final CountDownLatch latch = new CountDownLatch(2);
    Thread t1 = new Thread() {

        @Override
        public void run() {
            MemoryChunk c1 = rmm1.allocate(50);
            MemoryChunk c2 = rmm1.allocate(40);
            sleepFor(40);
            c1.close();
            sleepFor(20);
            c2.close();
            latch.countDown();
        }
    };
    Thread t2 = new Thread() {

        @Override
        public void run() {
            sleepFor(20);
            MemoryChunk c3 = rmm2.allocate(10);
            // Will require waiting for a bit of time before t1 frees the requested memory
            c3.resize(50);
            Mockito.verify(gmm, atLeastOnce()).waitForBytesToFree(anyLong(), anyLong());
            c3.close();
            latch.countDown();
        }
    };
    t1.start();
    t2.start();
    latch.await(1, TimeUnit.SECONDS);
    // Main thread competes with others to get all memory, but should wait
    // until both threads are complete (since that's when the memory will
    // again be all available.
    ChildMemoryManager rmm = new ChildMemoryManager(gmm, 100);
    MemoryChunk c = rmm.allocate(100);
    c.close();
    assertTrue(rmm.getAvailableMemory() == rmm.getMaxMemory());
    assertTrue(rmm1.getAvailableMemory() == rmm1.getMaxMemory());
    assertTrue(rmm2.getAvailableMemory() == rmm2.getMaxMemory());
}
Also used : MemoryChunk(org.apache.phoenix.memory.MemoryManager.MemoryChunk) CountDownLatch(java.util.concurrent.CountDownLatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with MemoryChunk

use of org.apache.phoenix.memory.MemoryManager.MemoryChunk in project phoenix by apache.

the class MemoryManagerTest method testChildDecreaseAllocation.

@Test
public void testChildDecreaseAllocation() throws Exception {
    MemoryManager gmm = spy(new GlobalMemoryManager(100, 1));
    ChildMemoryManager rmm1 = new ChildMemoryManager(gmm, 100);
    ChildMemoryManager rmm2 = new ChildMemoryManager(gmm, 10);
    MemoryChunk c1 = rmm1.allocate(50);
    MemoryChunk c2 = rmm2.allocate(5, 50);
    assertTrue(c2.getSize() == 10);
    c1.close();
    assertTrue(rmm1.getAvailableMemory() == rmm1.getMaxMemory());
    c2.close();
    assertTrue(rmm2.getAvailableMemory() == rmm2.getMaxMemory());
    assertTrue(gmm.getAvailableMemory() == gmm.getMaxMemory());
}
Also used : MemoryChunk(org.apache.phoenix.memory.MemoryManager.MemoryChunk) Test(org.junit.Test)

Example 8 with MemoryChunk

use of org.apache.phoenix.memory.MemoryManager.MemoryChunk in project phoenix by apache.

the class MemoryManagerTest method testWaitUntilResize.

@Ignore("See PHOENIX-2840")
@Test
public void testWaitUntilResize() throws Exception {
    final GlobalMemoryManager gmm = spy(new GlobalMemoryManager(100, 80));
    final ChildMemoryManager rmm1 = new ChildMemoryManager(gmm, 100);
    final MemoryChunk c1 = rmm1.allocate(70);
    final CountDownLatch latch = new CountDownLatch(2);
    Thread t1 = new Thread() {

        @Override
        public void run() {
            MemoryChunk c2 = rmm1.allocate(20);
            sleepFor(40);
            // resize down to test that other thread is notified
            c1.resize(20);
            sleepFor(20);
            c2.close();
            c1.close();
            assertTrue(rmm1.getAvailableMemory() == rmm1.getMaxMemory());
            latch.countDown();
        }
    };
    Thread t2 = new Thread() {

        @Override
        public void run() {
            sleepFor(20);
            ChildMemoryManager rmm2 = new ChildMemoryManager(gmm, 100);
            MemoryChunk c3 = rmm2.allocate(10);
            long startTime = System.currentTimeMillis();
            // Test that resize waits if memory not available
            c3.resize(60);
            // c1 was resized not closed
            assertTrue(c1.getSize() == 20);
            // we waited some time before the allocate happened
            Mockito.verify(gmm, atLeastOnce()).waitForBytesToFree(anyLong(), anyLong());
            c3.close();
            assertTrue(rmm2.getAvailableMemory() == rmm2.getMaxMemory());
            latch.countDown();
        }
    };
    t1.start();
    t2.start();
    latch.await(1, TimeUnit.SECONDS);
    // Main thread competes with others to get all memory, but should wait
    // until both threads are complete (since that's when the memory will
    // again be all available.
    ChildMemoryManager rmm = new ChildMemoryManager(gmm, 100);
    MemoryChunk c = rmm.allocate(100);
    c.close();
    assertTrue(rmm.getAvailableMemory() == rmm.getMaxMemory());
}
Also used : MemoryChunk(org.apache.phoenix.memory.MemoryManager.MemoryChunk) CountDownLatch(java.util.concurrent.CountDownLatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

MemoryChunk (org.apache.phoenix.memory.MemoryManager.MemoryChunk)8 Test (org.junit.Test)6 CountDownLatch (java.util.concurrent.CountDownLatch)3 Ignore (org.junit.Ignore)3 Closeable (java.io.Closeable)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)1 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)1 BlockingRpcCallback (org.apache.hadoop.hbase.ipc.BlockingRpcCallback)1 ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)1 ServerCacheFactory (org.apache.phoenix.coprocessor.ServerCachingProtocol.ServerCacheFactory)1 AddServerCacheRequest (org.apache.phoenix.coprocessor.generated.ServerCachingProtos.AddServerCacheRequest)1 AddServerCacheResponse (org.apache.phoenix.coprocessor.generated.ServerCachingProtos.AddServerCacheResponse)1 ServerCachingService (org.apache.phoenix.coprocessor.generated.ServerCachingProtos.ServerCachingService)1 JobCallable (org.apache.phoenix.job.JobManager.JobCallable)1