Java Code Examples for org.apache.hadoop.hbase.client.Mutation#setAttribute()

The following examples show how to use org.apache.hadoop.hbase.client.Mutation#setAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void checkForReservedTagPresence(User user, Mutation m) throws IOException {
  // No need to check if we're not going to throw
  if (!authorizationEnabled) {
    m.setAttribute(TAG_CHECK_PASSED, TRUE);
    return;
  }
  // Superusers are allowed to store cells unconditionally.
  if (Superusers.isSuperUser(user)) {
    m.setAttribute(TAG_CHECK_PASSED, TRUE);
    return;
  }
  // We already checked (prePut vs preBatchMutation)
  if (m.getAttribute(TAG_CHECK_PASSED) != null) {
    return;
  }
  for (CellScanner cellScanner = m.cellScanner(); cellScanner.advance();) {
    Iterator<Tag> tagsItr = PrivateCellUtil.tagsIterator(cellScanner.current());
    while (tagsItr.hasNext()) {
      if (tagsItr.next().getType() == PermissionStorage.ACL_TAG_TYPE) {
        throw new AccessDeniedException("Mutation contains cell with reserved type tag");
      }
    }
  }
  m.setAttribute(TAG_CHECK_PASSED, TRUE);
}
 
Example 2
Source File: UngroupedAggregateRegionObserver.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private void setIndexAndTransactionProperties(List<Mutation> mutations, byte[] indexUUID,
        byte[] indexMaintainersPtr, byte[] txState, byte[] clientVersionBytes,
        boolean useIndexProto) {
    for (Mutation m : mutations) {
       if (indexMaintainersPtr != null) {
           m.setAttribute(useIndexProto ? PhoenixIndexCodec.INDEX_PROTO_MD : PhoenixIndexCodec.INDEX_MD, indexMaintainersPtr);
       }
       if (indexUUID != null) {
         m.setAttribute(PhoenixIndexCodec.INDEX_UUID, indexUUID);
       }
       if (txState != null) {
           m.setAttribute(BaseScannerRegionObserver.TX_STATE, txState);
       }
       if (clientVersionBytes != null) {
           m.setAttribute(BaseScannerRegionObserver.CLIENT_VERSION, clientVersionBytes);
       }
    }
}
 
Example 3
Source File: VerifySingleIndexRowTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private Mutation getUnverifiedPutMutation(Mutation orig, Long ts) {
    Mutation m = new Put(orig.getRow());
    if (orig.getAttributesMap() != null) {
        for (Map.Entry<String,byte[]> entry : orig.getAttributesMap().entrySet()) {
            m.setAttribute(entry.getKey(), entry.getValue());
        }
    }
    List<Cell> origList = orig.getFamilyCellMap().firstEntry().getValue();
    ts = ts == null ? EnvironmentEdgeManager.currentTimeMillis() : ts;
    Cell c = getNewPutCell(orig, origList, ts, KeyValue.Type.Put);
    Cell empty = getEmptyCell(orig, origList, ts, KeyValue.Type.Put, false);
    byte[] fam = CellUtil.cloneFamily(origList.get(0));
    List<Cell> famCells = Lists.newArrayList();
    m.getFamilyCellMap().put(fam, famCells);
    famCells.add(c);
    famCells.add(empty);
    return m;
}
 
Example 4
Source File: UngroupedAggregateRegionObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static void commitBatch(HRegion region, List<Mutation> mutations, byte[] indexUUID) throws IOException {
  if (indexUUID != null) {
      for (Mutation m : mutations) {
          m.setAttribute(PhoenixIndexCodec.INDEX_UUID, indexUUID);
      }
  }
  Mutation[] mutationArray = new Mutation[mutations.size()];
  // TODO: should we use the one that is all or none?
  region.batchMutate(mutations.toArray(mutationArray));
}
 
Example 5
Source File: IndexRebuildRegionScanner.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void setMutationAttributes(Mutation m, byte[] uuidValue) {
    m.setAttribute(useProto ? PhoenixIndexCodec.INDEX_PROTO_MD : PhoenixIndexCodec.INDEX_MD, indexMetaData);
    m.setAttribute(PhoenixIndexCodec.INDEX_UUID, uuidValue);
    m.setAttribute(BaseScannerRegionObserver.REPLAY_WRITES,
            BaseScannerRegionObserver.REPLAY_INDEX_REBUILD_WRITES);
    m.setAttribute(BaseScannerRegionObserver.CLIENT_VERSION, clientVersionBytes);
    // Since we're replaying existing mutations, it makes no sense to write them to the wal
    m.setDurability(Durability.SKIP_WAL);
}
 
Example 6
Source File: UngroupedAggregateRegionObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void handleIndexWriteException(final List<Mutation> localRegionMutations, IOException origIOE,
        MutateCommand mutateCommand) throws IOException {
    long serverTimestamp = ServerUtil.parseTimestampFromRemoteException(origIOE);
    SQLException inferredE = ServerUtil.parseLocalOrRemoteServerException(origIOE);
    if (inferredE != null && inferredE.getErrorCode() == SQLExceptionCode.INDEX_WRITE_FAILURE.getErrorCode()) {
        // For an index write failure, the data table write succeeded,
        // so when we retry we need to set REPLAY_WRITES
        for (Mutation mutation : localRegionMutations) {
            if (PhoenixIndexMetaData.isIndexRebuild(mutation.getAttributesMap())) {
                mutation.setAttribute(BaseScannerRegionObserver.REPLAY_WRITES,
                    BaseScannerRegionObserver.REPLAY_INDEX_REBUILD_WRITES);
            } else {
                mutation.setAttribute(BaseScannerRegionObserver.REPLAY_WRITES,
                    BaseScannerRegionObserver.REPLAY_ONLY_INDEX_WRITES);
            }
            // use the server timestamp for index write retries
            PhoenixKeyValueUtil.setTimestamp(mutation, serverTimestamp);
        }
        IndexWriteException iwe = PhoenixIndexFailurePolicy.getIndexWriteException(inferredE);
        try (PhoenixConnection conn =
                QueryUtil.getConnectionOnServer(indexWriteConfig)
                        .unwrap(PhoenixConnection.class)) {
            PhoenixIndexFailurePolicy.doBatchWithRetries(mutateCommand, iwe, conn,
                indexWriteProps);
        } catch (Exception e) {
            throw new DoNotRetryIOException(e);
        }
    } else {
        throw origIOE;
    }
}
 
Example 7
Source File: IndexUpdateManager.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private void markMutationForRemoval(Mutation m) {
  m.setAttribute(PHOENIX_HBASE_TEMP_DELETE_MARKER, TRUE_MARKER);
}
 
Example 8
Source File: IndexUpdateManager.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private void markMutationForRemoval(Mutation m) {
  m.setAttribute(PHOENIX_HBASE_TEMP_DELETE_MARKER, TRUE_MARKER);
}
 
Example 9
Source File: IndexMetaDataCacheClient.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static ServerCache setMetaDataOnMutations(PhoenixConnection connection, PTable table, List<? extends Mutation> mutations,
        ImmutableBytesWritable indexMetaDataPtr) throws SQLException {
    final byte[] tenantIdBytes;
    if (table.isMultiTenant()) {
        tenantIdBytes = connection.getTenantId() == null ? null : ScanUtil.getTenantIdBytes(
                table.getRowKeySchema(), table.getBucketNum() != null, connection.getTenantId(),
                table.getViewIndexId() != null);
    } else {
        tenantIdBytes = connection.getTenantId() == null ? null : connection.getTenantId().getBytes();
    }
    ServerCache cache = null;
    byte[] attribValue = null;
    byte[] uuidValue = null;
    byte[] txState = ByteUtil.EMPTY_BYTE_ARRAY;
    if (table.isTransactional()) {
        txState = connection.getMutationState().encodeTransaction();
    }
    boolean hasIndexMetaData = indexMetaDataPtr.getLength() > 0;
    if (hasIndexMetaData) {
        if (useIndexMetadataCache(connection, mutations, indexMetaDataPtr.getLength() + txState.length)) {
            IndexMetaDataCacheClient client = new IndexMetaDataCacheClient(connection, table);
            cache = client.addIndexMetadataCache(mutations, indexMetaDataPtr, txState);
            uuidValue = cache.getId();
        } else {
            attribValue = ByteUtil.copyKeyBytesIfNecessary(indexMetaDataPtr);
            uuidValue = ServerCacheClient.generateId();
        }
    } else if (txState.length == 0) { return null; }
    // Either set the UUID to be able to access the index metadata from the cache
    // or set the index metadata directly on the Mutation
    for (Mutation mutation : mutations) {
        if (connection.getTenantId() != null) {
            mutation.setAttribute(PhoenixRuntime.TENANT_ID_ATTRIB, tenantIdBytes);
        }
        mutation.setAttribute(PhoenixIndexCodec.INDEX_UUID, uuidValue);
        if (attribValue != null) {
            mutation.setAttribute(PhoenixIndexCodec.INDEX_PROTO_MD, attribValue);
            mutation.setAttribute(BaseScannerRegionObserver.CLIENT_VERSION,
                    Bytes.toBytes(MetaDataProtocol.PHOENIX_VERSION));
            if (txState.length > 0) {
                mutation.setAttribute(BaseScannerRegionObserver.TX_STATE, txState);
            }
        } else if (!hasIndexMetaData && txState.length > 0) {
            mutation.setAttribute(BaseScannerRegionObserver.TX_STATE, txState);
        }
    }
    return cache;
}
 
Example 10
Source File: PhoenixIndexBuilder.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private static void transferAttributes(Mutation source, Mutation target) {
    for (Map.Entry<String, byte[]> entry : source.getAttributesMap().entrySet()) {
        target.setAttribute(entry.getKey(), entry.getValue());
    }
}
 
Example 11
Source File: MutationState.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private void generateMutations(final TableRef tableRef, final long mutationTimestamp, final long serverTimestamp,
        final MultiRowMutationState values, final List<Mutation> mutationList,
        final List<Mutation> mutationsPertainingToIndex) {
    final PTable table = tableRef.getTable();
    boolean tableWithRowTimestampCol = table.getRowTimestampColPos() != -1;
    Iterator<Map.Entry<ImmutableBytesPtr, RowMutationState>> iterator = values.entrySet().iterator();
    long timestampToUse = mutationTimestamp;
    MultiRowMutationState modifiedValues = new MultiRowMutationState(16);
    boolean wildcardIncludesDynamicCols = connection.getQueryServices().getProps().getBoolean(
            WILDCARD_QUERY_DYNAMIC_COLS_ATTRIB, DEFAULT_WILDCARD_QUERY_DYNAMIC_COLS_ATTRIB);
    while (iterator.hasNext()) {
        Map.Entry<ImmutableBytesPtr, RowMutationState> rowEntry = iterator.next();
        byte[] onDupKeyBytes = rowEntry.getValue().getOnDupKeyBytes();
        boolean hasOnDupKey = onDupKeyBytes != null;
        ImmutableBytesPtr key = rowEntry.getKey();
        RowMutationState state = rowEntry.getValue();
        if (tableWithRowTimestampCol) {
            RowTimestampColInfo rowTsColInfo = state.getRowTimestampColInfo();
            if (rowTsColInfo.useServerTimestamp()) {
                // regenerate the key with this timestamp.
                key = getNewRowKeyWithRowTimestamp(key, serverTimestamp, table);
                // since we are about to modify the byte[] stored in key (which changes its hashcode)
                // we need to remove the entry from the values map and add a new entry with the modified byte[]
                modifiedValues.put(key, state);
                iterator.remove();
                timestampToUse = serverTimestamp;
            } else {
                if (rowTsColInfo.getTimestamp() != null) {
                    timestampToUse = rowTsColInfo.getTimestamp();
                }
            }
        }
        PRow row = table.newRow(connection.getKeyValueBuilder(), timestampToUse, key, hasOnDupKey);
        List<Mutation> rowMutations, rowMutationsPertainingToIndex;
        if (rowEntry.getValue().getColumnValues() == PRow.DELETE_MARKER) { // means delete
            row.delete();
            rowMutations = row.toRowMutations();
            // The DeleteCompiler already generates the deletes for indexes, so no need to do it again
            rowMutationsPertainingToIndex = Collections.emptyList();
        } else {
            for (Map.Entry<PColumn, byte[]> valueEntry : rowEntry.getValue().getColumnValues().entrySet()) {
                row.setValue(valueEntry.getKey(), valueEntry.getValue());
            }
            if (wildcardIncludesDynamicCols && row.setAttributesForDynamicColumnsIfReqd()) {
                row.setAttributeToProcessDynamicColumnsMetadata();
            }
            rowMutations = row.toRowMutations();
            // Pass through ON DUPLICATE KEY info through mutations
            // In the case of the same clause being used on many statements, this will be
            // inefficient because we're transmitting the same information for each mutation.
            // TODO: use our ServerCache
            for (Mutation mutation : rowMutations) {
                if (onDupKeyBytes != null) {
                    mutation.setAttribute(PhoenixIndexBuilder.ATOMIC_OP_ATTRIB, onDupKeyBytes);
                }
            }
            rowMutationsPertainingToIndex = rowMutations;
        }
        mutationList.addAll(rowMutations);
        if (mutationsPertainingToIndex != null) mutationsPertainingToIndex.addAll(rowMutationsPertainingToIndex);
    }
    values.putAll(modifiedValues);
}
 
Example 12
Source File: IndexUpdateManager.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void markMutationForRemoval(Mutation m) {
  m.setAttribute(PHOENIX_HBASE_TEMP_DELETE_MARKER, TRUE_MARKER);
}