Search in sources :

Example 21 with RegionCoprocessorEnvironment

use of org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment in project phoenix by apache.

the class TestNonTxIndexBuilder method setup.

/**
     * Test setup so that {@link NonTxIndexBuilder#getIndexUpdate(Mutation, IndexMetaData)} can be
     * called, where any read requests to
     * {@link LocalTable#getCurrentRowState(Mutation, Collection, boolean)} are read from our test
     * field 'currentRowCells'
     */
@Before
public void setup() throws Exception {
    RegionCoprocessorEnvironment env = Mockito.mock(RegionCoprocessorEnvironment.class);
    Configuration conf = new Configuration(false);
    conf.set(NonTxIndexBuilder.CODEC_CLASS_NAME_KEY, PhoenixIndexCodec.class.getName());
    Mockito.when(env.getConfiguration()).thenReturn(conf);
    // the following is used by LocalTable#getCurrentRowState()
    Region mockRegion = Mockito.mock(Region.class);
    Mockito.when(env.getRegion()).thenReturn(mockRegion);
    Mockito.when(mockRegion.getScanner(Mockito.any(Scan.class))).thenAnswer(new Answer<RegionScanner>() {

        @Override
        public RegionScanner answer(InvocationOnMock invocation) throws Throwable {
            Scan sArg = (Scan) invocation.getArguments()[0];
            TimeRange timeRange = sArg.getTimeRange();
            return getMockTimeRangeRegionScanner(timeRange);
        }
    });
    // the following is called by PhoenixIndexCodec#getIndexUpserts() , getIndexDeletes()
    HRegionInfo mockRegionInfo = Mockito.mock(HRegionInfo.class);
    Mockito.when(mockRegion.getRegionInfo()).thenReturn(mockRegionInfo);
    Mockito.when(mockRegionInfo.getStartKey()).thenReturn(Bytes.toBytes("a"));
    Mockito.when(mockRegionInfo.getEndKey()).thenReturn(Bytes.toBytes("z"));
    mockIndexMetaData = Mockito.mock(PhoenixIndexMetaData.class);
    Mockito.when(mockIndexMetaData.isImmutableRows()).thenReturn(false);
    Mockito.when(mockIndexMetaData.getIndexMaintainers()).thenReturn(Collections.singletonList(getTestIndexMaintainer()));
    indexBuilder = new NonTxIndexBuilder();
    indexBuilder.setup(env);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TimeRange(org.apache.hadoop.hbase.io.TimeRange) RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment) PhoenixIndexMetaData(org.apache.phoenix.index.PhoenixIndexMetaData) BaseRegionScanner(org.apache.phoenix.coprocessor.BaseRegionScanner) RegionScanner(org.apache.hadoop.hbase.regionserver.RegionScanner) PhoenixIndexCodec(org.apache.phoenix.index.PhoenixIndexCodec) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Region(org.apache.hadoop.hbase.regionserver.Region) Scan(org.apache.hadoop.hbase.client.Scan) Before(org.junit.Before)

Example 22 with RegionCoprocessorEnvironment

use of org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment in project phoenix by apache.

the class TestLocalTableState method testScannerForMutableRows.

@Test(expected = ScannerCreatedException.class)
public void testScannerForMutableRows() throws Exception {
    IndexMetaData indexMetaData = new IndexMetaData() {

        @Override
        public boolean isImmutableRows() {
            return false;
        }

        @Override
        public boolean ignoreNewerMutations() {
            return false;
        }
    };
    Put m = new Put(row);
    m.add(fam, qual, ts, val);
    // setup mocks
    Configuration conf = new Configuration(false);
    RegionCoprocessorEnvironment env = Mockito.mock(RegionCoprocessorEnvironment.class);
    Mockito.when(env.getConfiguration()).thenReturn(conf);
    Region region = Mockito.mock(Region.class);
    Mockito.when(env.getRegion()).thenReturn(region);
    Mockito.when(region.getScanner(Mockito.any(Scan.class))).thenThrow(new ScannerCreatedException("Should not open scanner when data is immutable"));
    LocalHBaseState state = new LocalTable(env);
    LocalTableState table = new LocalTableState(env, state, m);
    //add the kvs from the mutation
    table.addPendingUpdates(KeyValueUtil.ensureKeyValues(m.get(fam, qual)));
    // setup the lookup
    ColumnReference col = new ColumnReference(fam, qual);
    table.setCurrentTimestamp(ts);
    table.getIndexedColumnsTableState(Arrays.asList(col), false, false, indexMetaData);
}
Also used : LocalTable(org.apache.phoenix.hbase.index.covered.data.LocalTable) RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment) LocalHBaseState(org.apache.phoenix.hbase.index.covered.data.LocalHBaseState) Configuration(org.apache.hadoop.conf.Configuration) Region(org.apache.hadoop.hbase.regionserver.Region) Scan(org.apache.hadoop.hbase.client.Scan) Put(org.apache.hadoop.hbase.client.Put) ColumnReference(org.apache.phoenix.hbase.index.covered.update.ColumnReference) Test(org.junit.Test)

Example 23 with RegionCoprocessorEnvironment

use of org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment in project cdap by caskdata.

the class DefaultTransactionProcessor method start.

@Override
public void start(CoprocessorEnvironment e) throws IOException {
    if (e instanceof RegionCoprocessorEnvironment) {
        RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) e;
        HTableDescriptor tableDesc = env.getRegion().getTableDesc();
        String hbaseNamespacePrefix = tableDesc.getValue(Constants.Dataset.TABLE_PREFIX);
        this.sysConfigTablePrefix = HTableNameConverter.getSysConfigTablePrefix(hbaseNamespacePrefix);
        this.cConfCacheSupplier = new CConfigurationCacheSupplier(env.getConfiguration(), sysConfigTablePrefix, TxConstants.Manager.CFG_TX_MAX_LIFETIME, TxConstants.Manager.DEFAULT_TX_MAX_LIFETIME);
        this.cConfCache = cConfCacheSupplier.get();
    }
    // Need to create the cConf cache before calling start on the parent, since it is required for
    // initializing some properties in the parent class.
    super.start(e);
}
Also used : RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment) CConfigurationCacheSupplier(co.cask.cdap.data2.transaction.coprocessor.CConfigurationCacheSupplier) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 24 with RegionCoprocessorEnvironment

use of org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment in project cdap by caskdata.

the class MessageTableRegionObserver method start.

@Override
public void start(CoprocessorEnvironment e) throws IOException {
    if (e instanceof RegionCoprocessorEnvironment) {
        RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) e;
        HTableDescriptor tableDesc = env.getRegion().getTableDesc();
        String metadataTableNamespace = tableDesc.getValue(Constants.MessagingSystem.HBASE_METADATA_TABLE_NAMESPACE);
        String hbaseNamespacePrefix = tableDesc.getValue(Constants.Dataset.TABLE_PREFIX);
        prefixLength = Integer.valueOf(tableDesc.getValue(Constants.MessagingSystem.HBASE_MESSAGING_TABLE_PREFIX_NUM_BYTES));
        String sysConfigTablePrefix = HTableNameConverter.getSysConfigTablePrefix(hbaseNamespacePrefix);
        CConfigurationReader cConfReader = new CConfigurationReader(env.getConfiguration(), sysConfigTablePrefix);
        txStateCacheSupplier = getTransactionStateCacheSupplier(hbaseNamespacePrefix, env.getConfiguration());
        txStateCache = txStateCacheSupplier.get();
        topicMetadataCacheSupplier = new TopicMetadataCacheSupplier(env, cConfReader, hbaseNamespacePrefix, metadataTableNamespace, new DefaultScanBuilder());
        topicMetadataCache = topicMetadataCacheSupplier.get();
    }
}
Also used : TopicMetadataCacheSupplier(co.cask.cdap.messaging.TopicMetadataCacheSupplier) RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment) CConfigurationReader(co.cask.cdap.data2.transaction.queue.hbase.coprocessor.CConfigurationReader) DefaultScanBuilder(co.cask.cdap.data2.util.hbase.DefaultScanBuilder) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 25 with RegionCoprocessorEnvironment

use of org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment in project cdap by caskdata.

the class PayloadTableRegionObserver method start.

@Override
public void start(CoprocessorEnvironment e) throws IOException {
    if (e instanceof RegionCoprocessorEnvironment) {
        RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) e;
        HTableDescriptor tableDesc = env.getRegion().getTableDesc();
        String metadataTableNamespace = tableDesc.getValue(Constants.MessagingSystem.HBASE_METADATA_TABLE_NAMESPACE);
        String hbaseNamespacePrefix = tableDesc.getValue(Constants.Dataset.TABLE_PREFIX);
        prefixLength = Integer.valueOf(tableDesc.getValue(Constants.MessagingSystem.HBASE_MESSAGING_TABLE_PREFIX_NUM_BYTES));
        String sysConfigTablePrefix = HTableNameConverter.getSysConfigTablePrefix(hbaseNamespacePrefix);
        CConfigurationReader cConfReader = new CConfigurationReader(env.getConfiguration(), sysConfigTablePrefix);
        topicMetadataCacheSupplier = new TopicMetadataCacheSupplier(env, cConfReader, hbaseNamespacePrefix, metadataTableNamespace, new DefaultScanBuilder());
        topicMetadataCache = topicMetadataCacheSupplier.get();
    }
}
Also used : TopicMetadataCacheSupplier(co.cask.cdap.messaging.TopicMetadataCacheSupplier) RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment) CConfigurationReader(co.cask.cdap.data2.transaction.queue.hbase.coprocessor.CConfigurationReader) DefaultScanBuilder(co.cask.cdap.data2.util.hbase.DefaultScanBuilder) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Aggregations

RegionCoprocessorEnvironment (org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment)78 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)37 Configuration (org.apache.hadoop.conf.Configuration)25 CConfigurationReader (co.cask.cdap.data2.transaction.queue.hbase.coprocessor.CConfigurationReader)21 Test (org.junit.Test)16 TopicMetadataCacheSupplier (co.cask.cdap.messaging.TopicMetadataCacheSupplier)14 Put (org.apache.hadoop.hbase.client.Put)14 Region (org.apache.hadoop.hbase.regionserver.Region)14 DefaultScanBuilder (co.cask.cdap.data2.util.hbase.DefaultScanBuilder)11 Mutation (org.apache.hadoop.hbase.client.Mutation)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 Cell (org.apache.hadoop.hbase.Cell)8 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)8 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)8 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)8 AccessDeniedException (org.apache.hadoop.hbase.security.AccessDeniedException)8 User (org.apache.hadoop.hbase.security.User)8 CConfiguration (co.cask.cdap.common.conf.CConfiguration)7 IncrementHandlerState (co.cask.cdap.data2.increment.hbase.IncrementHandlerState)7 CConfigurationCacheSupplier (co.cask.cdap.data2.transaction.coprocessor.CConfigurationCacheSupplier)7