Search in sources :

Example 26 with PMetaDataEntity

use of org.apache.phoenix.schema.PMetaDataEntity in project phoenix by apache.

the class MetaDataEndpointImpl method buildFunctions.

private List<PFunction> buildFunctions(List<byte[]> keys, Region region, long clientTimeStamp, boolean isReplace, List<Mutation> deleteMutationsForReplace) throws IOException, SQLException {
    List<KeyRange> keyRanges = Lists.newArrayListWithExpectedSize(keys.size());
    for (byte[] key : keys) {
        byte[] stopKey = ByteUtil.concat(key, QueryConstants.SEPARATOR_BYTE_ARRAY);
        ByteUtil.nextKey(stopKey, stopKey.length);
        keyRanges.add(PVarbinary.INSTANCE.getKeyRange(key, true, stopKey, false));
    }
    Scan scan = new Scan();
    scan.setTimeRange(MIN_TABLE_TIMESTAMP, clientTimeStamp);
    ScanRanges scanRanges = ScanRanges.createPointLookup(keyRanges);
    scanRanges.initializeScan(scan);
    scan.setFilter(scanRanges.getSkipScanFilter());
    Cache<ImmutableBytesPtr, PMetaDataEntity> metaDataCache = GlobalCache.getInstance(this.env).getMetaDataCache();
    List<PFunction> functions = new ArrayList<PFunction>();
    PFunction function = null;
    try (RegionScanner scanner = region.getScanner(scan)) {
        for (int i = 0; i < keys.size(); i++) {
            function = null;
            function = getFunction(scanner, isReplace, clientTimeStamp, deleteMutationsForReplace);
            if (function == null) {
                return null;
            }
            byte[] functionKey = SchemaUtil.getFunctionKey(function.getTenantId() == null ? ByteUtil.EMPTY_BYTE_ARRAY : function.getTenantId().getBytes(), Bytes.toBytes(function.getFunctionName()));
            metaDataCache.put(new FunctionBytesPtr(functionKey), function);
            functions.add(function);
        }
        return functions;
    }
}
Also used : PFunction(org.apache.phoenix.parse.PFunction) KeyRange(org.apache.phoenix.query.KeyRange) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) ArrayList(java.util.ArrayList) ScanRanges(org.apache.phoenix.compile.ScanRanges) PTinyint(org.apache.phoenix.schema.types.PTinyint) PSmallint(org.apache.phoenix.schema.types.PSmallint) PMetaDataEntity(org.apache.phoenix.schema.PMetaDataEntity) RegionScanner(org.apache.hadoop.hbase.regionserver.RegionScanner) Scan(org.apache.hadoop.hbase.client.Scan) FunctionBytesPtr(org.apache.phoenix.cache.GlobalCache.FunctionBytesPtr)

Example 27 with PMetaDataEntity

use of org.apache.phoenix.schema.PMetaDataEntity in project phoenix by apache.

the class MetaDataEndpointImpl method clearTableFromCache.

@Override
public void clearTableFromCache(RpcController controller, ClearTableFromCacheRequest request, RpcCallback<ClearTableFromCacheResponse> done) {
    byte[] schemaName = request.getSchemaName().toByteArray();
    byte[] tableName = request.getTableName().toByteArray();
    try {
        byte[] tenantId = request.getTenantId().toByteArray();
        byte[] key = SchemaUtil.getTableKey(tenantId, schemaName, tableName);
        ImmutableBytesPtr cacheKey = new ImmutableBytesPtr(key);
        Cache<ImmutableBytesPtr, PMetaDataEntity> metaDataCache = GlobalCache.getInstance(this.env).getMetaDataCache();
        metaDataCache.invalidate(cacheKey);
    } catch (Throwable t) {
        logger.error("clearTableFromCache failed", t);
        ProtobufUtil.setControllerException(controller, ServerUtil.createIOException(SchemaUtil.getTableName(schemaName, tableName), t));
    }
}
Also used : PMetaDataEntity(org.apache.phoenix.schema.PMetaDataEntity) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)

Aggregations

ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)27 PMetaDataEntity (org.apache.phoenix.schema.PMetaDataEntity)27 Region (org.apache.hadoop.hbase.regionserver.Region)18 PTable (org.apache.phoenix.schema.PTable)14 ArrayList (java.util.ArrayList)11 RowLock (org.apache.hadoop.hbase.regionserver.Region.RowLock)10 Scan (org.apache.hadoop.hbase.client.Scan)9 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)9 Cell (org.apache.hadoop.hbase.Cell)7 Mutation (org.apache.hadoop.hbase.client.Mutation)7 PSmallint (org.apache.phoenix.schema.types.PSmallint)7 PTinyint (org.apache.phoenix.schema.types.PTinyint)7 MetaDataResponse (org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataResponse)5 PFunction (org.apache.phoenix.parse.PFunction)5 ByteString (com.google.protobuf.ByteString)4 PSchema (org.apache.phoenix.parse.PSchema)4 FirstKeyOnlyFilter (org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter)3 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)3 FunctionBytesPtr (org.apache.phoenix.cache.GlobalCache.FunctionBytesPtr)3 PName (org.apache.phoenix.schema.PName)3