Search in sources :

Example 16 with PFunction

use of org.apache.phoenix.parse.PFunction in project phoenix by apache.

the class MetaDataEndpointImpl method doDropFunction.

private MetaDataMutationResult doDropFunction(long clientTimeStamp, List<byte[]> keys, List<Mutation> functionMetaData, List<ImmutableBytesPtr> invalidateList) throws IOException, SQLException {
    List<byte[]> keysClone = new ArrayList<byte[]>(keys);
    List<PFunction> functions = doGetFunctions(keysClone, clientTimeStamp);
    // there was a table, but it's been deleted. In either case we want to return.
    if (functions == null || functions.isEmpty()) {
        if (buildDeletedFunction(keys.get(0), new FunctionBytesPtr(keys.get(0)), env.getRegion(), clientTimeStamp) != null) {
            return new MetaDataMutationResult(MutationCode.FUNCTION_ALREADY_EXISTS, EnvironmentEdgeManager.currentTimeMillis(), null);
        }
        return new MetaDataMutationResult(MutationCode.FUNCTION_NOT_FOUND, EnvironmentEdgeManager.currentTimeMillis(), null);
    }
    if (functions != null && !functions.isEmpty()) {
        if (functions.get(0).getTimeStamp() < clientTimeStamp) {
            // continue
            if (isFunctionDeleted(functions.get(0))) {
                return new MetaDataMutationResult(MutationCode.FUNCTION_NOT_FOUND, EnvironmentEdgeManager.currentTimeMillis(), null);
            }
            invalidateList.add(new FunctionBytesPtr(keys.get(0)));
            Region region = env.getRegion();
            Scan scan = MetaDataUtil.newTableRowsScan(keys.get(0), MIN_TABLE_TIMESTAMP, clientTimeStamp);
            List<Cell> results = Lists.newArrayList();
            try (RegionScanner scanner = region.getScanner(scan)) {
                scanner.next(results);
                if (results.isEmpty()) {
                    // Should not be possible
                    return new MetaDataMutationResult(MutationCode.FUNCTION_NOT_FOUND, EnvironmentEdgeManager.currentTimeMillis(), null);
                }
                do {
                    Cell kv = results.get(0);
                    Delete delete = new Delete(kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(), clientTimeStamp);
                    functionMetaData.add(delete);
                    results.clear();
                    scanner.next(results);
                } while (!results.isEmpty());
            }
            return new MetaDataMutationResult(MutationCode.FUNCTION_ALREADY_EXISTS, EnvironmentEdgeManager.currentTimeMillis(), functions, true);
        }
    }
    return new MetaDataMutationResult(MutationCode.FUNCTION_NOT_FOUND, EnvironmentEdgeManager.currentTimeMillis(), null);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) PFunction(org.apache.phoenix.parse.PFunction) RegionScanner(org.apache.hadoop.hbase.regionserver.RegionScanner) ArrayList(java.util.ArrayList) Region(org.apache.hadoop.hbase.regionserver.Region) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) FunctionBytesPtr(org.apache.phoenix.cache.GlobalCache.FunctionBytesPtr)

Aggregations

PFunction (org.apache.phoenix.parse.PFunction)16 ArrayList (java.util.ArrayList)8 Scan (org.apache.hadoop.hbase.client.Scan)5 Region (org.apache.hadoop.hbase.regionserver.Region)5 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)5 PMetaDataEntity (org.apache.phoenix.schema.PMetaDataEntity)5 FunctionBytesPtr (org.apache.phoenix.cache.GlobalCache.FunctionBytesPtr)4 MetaDataMutationResult (org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult)4 Cell (org.apache.hadoop.hbase.Cell)3 Delete (org.apache.hadoop.hbase.client.Delete)3 Mutation (org.apache.hadoop.hbase.client.Mutation)3 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)3 MutationCode (org.apache.phoenix.coprocessor.MetaDataProtocol.MutationCode)3 FunctionNotFoundException (org.apache.phoenix.schema.FunctionNotFoundException)3 PSmallint (org.apache.phoenix.schema.types.PSmallint)3 PTinyint (org.apache.phoenix.schema.types.PTinyint)3 SQLException (java.sql.SQLException)2 List (java.util.List)2 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)2 RowLock (org.apache.hadoop.hbase.regionserver.Region.RowLock)2