Search in sources :

Example 1 with CachingHTableFactory

use of org.apache.phoenix.hbase.index.table.CachingHTableFactory in project phoenix by apache.

the class ParallelWriterIndexCommitter method setup.

/**
     * Setup <tt>this</tt>.
     * <p>
     * Exposed for TESTING
     */
void setup(HTableFactory factory, ExecutorService pool, Abortable abortable, Stoppable stop, int cacheSize, RegionCoprocessorEnvironment env) {
    this.factory = new CachingHTableFactory(factory, cacheSize, env);
    this.pool = new QuickFailingTaskRunner(pool);
    this.stopped = stop;
}
Also used : QuickFailingTaskRunner(org.apache.phoenix.hbase.index.parallel.QuickFailingTaskRunner) CachingHTableFactory(org.apache.phoenix.hbase.index.table.CachingHTableFactory)

Example 2 with CachingHTableFactory

use of org.apache.phoenix.hbase.index.table.CachingHTableFactory in project phoenix by apache.

the class TrackingParallelWriterIndexCommitter method setup.

/**
     * Setup <tt>this</tt>.
     * <p>
     * Exposed for TESTING
     */
void setup(HTableFactory factory, ExecutorService pool, Abortable abortable, Stoppable stop, int cacheSize, RegionCoprocessorEnvironment env) {
    this.pool = new WaitForCompletionTaskRunner(pool);
    this.factory = new CachingHTableFactory(factory, cacheSize, env);
    this.abortable = new CapturingAbortable(abortable);
    this.stopped = stop;
}
Also used : CachingHTableFactory(org.apache.phoenix.hbase.index.table.CachingHTableFactory) CapturingAbortable(org.apache.phoenix.hbase.index.CapturingAbortable) WaitForCompletionTaskRunner(org.apache.phoenix.hbase.index.parallel.WaitForCompletionTaskRunner)

Example 3 with CachingHTableFactory

use of org.apache.phoenix.hbase.index.table.CachingHTableFactory in project phoenix by apache.

the class TestCachingHTableFactory method testCacheCorrectlyExpiresTable.

@Test
public void testCacheCorrectlyExpiresTable() throws Exception {
    // setup the mocks for the tables we will request
    HTableFactory delegate = Mockito.mock(HTableFactory.class);
    RegionCoprocessorEnvironment e = Mockito.mock(RegionCoprocessorEnvironment.class);
    Configuration conf = new Configuration();
    Mockito.when(e.getConfiguration()).thenReturn(conf);
    Mockito.when(e.getSharedData()).thenReturn(new ConcurrentHashMap<String, Object>());
    ImmutableBytesPtr t1 = new ImmutableBytesPtr(Bytes.toBytes("t1"));
    ImmutableBytesPtr t2 = new ImmutableBytesPtr(Bytes.toBytes("t2"));
    ImmutableBytesPtr t3 = new ImmutableBytesPtr(Bytes.toBytes("t3"));
    HTableInterface table1 = Mockito.mock(HTableInterface.class);
    HTableInterface table2 = Mockito.mock(HTableInterface.class);
    HTableInterface table3 = Mockito.mock(HTableInterface.class);
    // setup our factory with a cache size of 2
    CachingHTableFactory factory = new CachingHTableFactory(delegate, 2, e);
    Mockito.when(delegate.getTable(t1, factory.getPool())).thenReturn(table1);
    Mockito.when(delegate.getTable(t2, factory.getPool())).thenReturn(table2);
    Mockito.when(delegate.getTable(t3, factory.getPool())).thenReturn(table3);
    HTableInterface ft1 = factory.getTable(t1);
    HTableInterface ft2 = factory.getTable(t2);
    ft1.close();
    HTableInterface ft3 = factory.getTable(t3);
    // get the same table a second time, after it has gone out of cache
    factory.getTable(t1);
    Mockito.verify(delegate, Mockito.times(2)).getTable(t1, factory.getPool());
    Mockito.verify(delegate, Mockito.times(1)).getTable(t2, factory.getPool());
    Mockito.verify(delegate, Mockito.times(1)).getTable(t3, factory.getPool());
    Mockito.verify(table1).close();
}
Also used : RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment) Configuration(org.apache.hadoop.conf.Configuration) CachingHTableFactory(org.apache.phoenix.hbase.index.table.CachingHTableFactory) CachingHTableFactory(org.apache.phoenix.hbase.index.table.CachingHTableFactory) HTableFactory(org.apache.phoenix.hbase.index.table.HTableFactory) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) Test(org.junit.Test)

Aggregations

CachingHTableFactory (org.apache.phoenix.hbase.index.table.CachingHTableFactory)3 Configuration (org.apache.hadoop.conf.Configuration)1 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)1 RegionCoprocessorEnvironment (org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment)1 CapturingAbortable (org.apache.phoenix.hbase.index.CapturingAbortable)1 QuickFailingTaskRunner (org.apache.phoenix.hbase.index.parallel.QuickFailingTaskRunner)1 WaitForCompletionTaskRunner (org.apache.phoenix.hbase.index.parallel.WaitForCompletionTaskRunner)1 HTableFactory (org.apache.phoenix.hbase.index.table.HTableFactory)1 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)1 Test (org.junit.Test)1