Search in sources :

Example 76 with Mutation

use of org.apache.hadoop.hbase.client.Mutation in project hbase by apache.

the class AccessController method preBatchMutate.

@Override
public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
    if (cellFeaturesEnabled && !compatibleEarlyTermination) {
        TableName table = c.getEnvironment().getRegion().getRegionInfo().getTable();
        User user = getActiveUser(c);
        for (int i = 0; i < miniBatchOp.size(); i++) {
            Mutation m = miniBatchOp.getOperation(i);
            if (m.getAttribute(CHECK_COVERING_PERM) != null) {
                // We have a failure with table, cf and q perm checks and now giving a chance for cell
                // perm check
                OpType opType;
                if (m instanceof Put) {
                    checkForReservedTagPresence(user, m);
                    opType = OpType.PUT;
                } else {
                    opType = OpType.DELETE;
                }
                AuthResult authResult = null;
                if (checkCoveringPermission(user, opType, c.getEnvironment(), m.getRow(), m.getFamilyCellMap(), m.getTimeStamp(), Action.WRITE)) {
                    authResult = AuthResult.allow(opType.toString(), "Covering cell set", user, Action.WRITE, table, m.getFamilyCellMap());
                } else {
                    authResult = AuthResult.deny(opType.toString(), "Covering cell set", user, Action.WRITE, table, m.getFamilyCellMap());
                }
                logResult(authResult);
                if (authorizationEnabled && !authResult.isAllowed()) {
                    throw new AccessDeniedException("Insufficient permissions " + authResult.toContextString());
                }
            }
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) User(org.apache.hadoop.hbase.security.User) Mutation(org.apache.hadoop.hbase.client.Mutation) ReplicationEndpoint(org.apache.hadoop.hbase.replication.ReplicationEndpoint) Put(org.apache.hadoop.hbase.client.Put)

Example 77 with Mutation

use of org.apache.hadoop.hbase.client.Mutation in project hbase by apache.

the class SplitTableRegionProcedure method preSplitRegionBeforePONR.

/**
   * Post split region actions before the Point-of-No-Return step
   * @param env MasterProcedureEnv
   **/
private void preSplitRegionBeforePONR(final MasterProcedureEnv env) throws IOException, InterruptedException {
    final List<Mutation> metaEntries = new ArrayList<>();
    final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
    if (cpHost != null) {
        if (cpHost.preSplitBeforePONRAction(getSplitRow(), metaEntries, getUser())) {
            throw new IOException("Coprocessor bypassing region " + parentHRI.getRegionNameAsString() + " split.");
        }
        try {
            for (Mutation p : metaEntries) {
                HRegionInfo.parseRegionName(p.getRow());
            }
        } catch (IOException e) {
            LOG.error("Row key of mutation from coprocessor is not parsable as region name." + "Mutations from coprocessor should only for hbase:meta table.");
            throw e;
        }
    }
}
Also used : MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) ArrayList(java.util.ArrayList) Mutation(org.apache.hadoop.hbase.client.Mutation) InterruptedIOException(java.io.InterruptedIOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException)

Example 78 with Mutation

use of org.apache.hadoop.hbase.client.Mutation in project hbase by apache.

the class MergeTableRegionsProcedure method preMergeRegionsCommit.

/**
   * Post merge region action
   * @param env MasterProcedureEnv
   **/
private void preMergeRegionsCommit(final MasterProcedureEnv env) throws IOException {
    final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
    if (cpHost != null) {
        @MetaMutationAnnotation final List<Mutation> metaEntries = new ArrayList<>();
        boolean ret = cpHost.preMergeRegionsCommit(regionsToMerge, metaEntries, getUser());
        if (ret) {
            throw new IOException("Coprocessor bypassing regions " + getRegionsToMergeListFullNameString() + " merge.");
        }
        try {
            for (Mutation p : metaEntries) {
                HRegionInfo.parseRegionName(p.getRow());
            }
        } catch (IOException e) {
            LOG.error("Row key of mutation from coprocessor is not parsable as region name." + "Mutations from coprocessor should only be for hbase:meta table.", e);
            throw e;
        }
    }
}
Also used : MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) MetaMutationAnnotation(org.apache.hadoop.hbase.MetaMutationAnnotation) ArrayList(java.util.ArrayList) Mutation(org.apache.hadoop.hbase.client.Mutation) InterruptedIOException(java.io.InterruptedIOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException)

Example 79 with Mutation

use of org.apache.hadoop.hbase.client.Mutation in project hbase by apache.

the class RequestConverter method buildNoDataRegionAction.

/**
   * Create a protocol buffer MultiRequest for row mutations that does not hold data.  Data/Cells
   * are carried outside of protobuf.  Return references to the Cells in <code>cells</code> param.
    * Does not propagate Action absolute position.  Does not set atomic action on the created
   * RegionAtomic.  Caller should do that if wanted.
   * @param regionName
   * @param rowMutations
   * @param cells Return in here a list of Cells as CellIterable.
   * @return a region mutation minus data
   * @throws IOException
   */
public static RegionAction.Builder buildNoDataRegionAction(final byte[] regionName, final RowMutations rowMutations, final List<CellScannable> cells, final RegionAction.Builder regionActionBuilder, final ClientProtos.Action.Builder actionBuilder, final MutationProto.Builder mutationBuilder) throws IOException {
    for (Mutation mutation : rowMutations.getMutations()) {
        MutationType type = null;
        if (mutation instanceof Put) {
            type = MutationType.PUT;
        } else if (mutation instanceof Delete) {
            type = MutationType.DELETE;
        } else {
            throw new DoNotRetryIOException("RowMutations supports only put and delete, not " + mutation.getClass().getName());
        }
        mutationBuilder.clear();
        MutationProto mp = ProtobufUtil.toMutationNoData(type, mutation, mutationBuilder);
        cells.add(mutation);
        actionBuilder.clear();
        regionActionBuilder.addAction(actionBuilder.setMutation(mp).build());
    }
    return regionActionBuilder;
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) MutationType(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.MutationType) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) Mutation(org.apache.hadoop.hbase.client.Mutation) Put(org.apache.hadoop.hbase.client.Put) MutationProto(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto)

Example 80 with Mutation

use of org.apache.hadoop.hbase.client.Mutation in project hbase by apache.

the class RequestConverter method buildRegionAction.

/**
   * Create a protocol buffer MultiRequest for row mutations.
   * Does not propagate Action absolute position.  Does not set atomic action on the created
   * RegionAtomic.  Caller should do that if wanted.
   * @param regionName
   * @param rowMutations
   * @return a data-laden RegionMutation.Builder
   * @throws IOException
   */
public static RegionAction.Builder buildRegionAction(final byte[] regionName, final RowMutations rowMutations) throws IOException {
    RegionAction.Builder builder = getRegionActionBuilderWithRegion(RegionAction.newBuilder(), regionName);
    ClientProtos.Action.Builder actionBuilder = ClientProtos.Action.newBuilder();
    MutationProto.Builder mutationBuilder = MutationProto.newBuilder();
    for (Mutation mutation : rowMutations.getMutations()) {
        MutationType mutateType = null;
        if (mutation instanceof Put) {
            mutateType = MutationType.PUT;
        } else if (mutation instanceof Delete) {
            mutateType = MutationType.DELETE;
        } else {
            throw new DoNotRetryIOException("RowMutations supports only put and delete, not " + mutation.getClass().getName());
        }
        mutationBuilder.clear();
        MutationProto mp = ProtobufUtil.toMutation(mutateType, mutation, mutationBuilder);
        actionBuilder.clear();
        actionBuilder.setMutation(mp);
        builder.addAction(actionBuilder.build());
    }
    return builder;
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Action(org.apache.hadoop.hbase.client.Action) RegionAction(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction) MutationType(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.MutationType) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) RegionAction(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction) Mutation(org.apache.hadoop.hbase.client.Mutation) MutationProto(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto) Put(org.apache.hadoop.hbase.client.Put)

Aggregations

Mutation (org.apache.hadoop.hbase.client.Mutation)139 Put (org.apache.hadoop.hbase.client.Put)53 ArrayList (java.util.ArrayList)46 IOException (java.io.IOException)35 Delete (org.apache.hadoop.hbase.client.Delete)32 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)31 List (java.util.List)28 Cell (org.apache.hadoop.hbase.Cell)25 Pair (org.apache.hadoop.hbase.util.Pair)23 MetaDataMutationResult (org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult)23 HashMap (java.util.HashMap)19 PTable (org.apache.phoenix.schema.PTable)18 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)17 MetaDataResponse (org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataResponse)15 Region (org.apache.hadoop.hbase.regionserver.Region)14 RowLock (org.apache.hadoop.hbase.regionserver.Region.RowLock)14 Test (org.junit.Test)14 MutationCode (org.apache.phoenix.coprocessor.MetaDataProtocol.MutationCode)13 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)12 MutationProto (org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto)12