当前位置: 首页>>代码示例>>Java>>正文


Java Mutation类代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.client.Mutation的典型用法代码示例。如果您正苦于以下问题:Java Mutation类的具体用法?Java Mutation怎么用?Java Mutation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Mutation类属于org.apache.hadoop.hbase.client包,在下文中一共展示了Mutation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addMultipleCounts

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
private void addMultipleCounts(final Map<RowKey, List<CountCellIncrementHolder>> rowChanges) {
    LOGGER.trace(() -> String.format("addMultipleCounts called for %s rows", rowChanges.size()));

    // create an action for each row we have data for
    final List<Mutation> actions = rowChanges.entrySet().stream()
            .map(entry -> createIncrementOperation(entry.getKey(), entry.getValue()))
            .collect(Collectors.toList());

    final Object[] results = null;
    // don't care about what is written to results as we are doing puts send the mutations to HBase

    // long startTime = System.currentTimeMillis();
    doBatch(actions, results);
    LOGGER.trace(() -> String.format("%s puts sent to HBase", actions.size()));

    // LOGGER.info("Sent %s ADDs to HBase from thread %s in %s ms",
    // cellQualifiersFromBuffer.size(),
    // Thread.currentThread().getName(), (System.currentTimeMillis() -
    // startTime));

}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:22,代码来源:HBaseEventStoreTable.java

示例2: mutateLabelsRegion

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
/**
 * Adds the mutations to labels region and set the results to the finalOpStatus. finalOpStatus
 * might have some entries in it where the OpStatus is FAILURE. We will leave those and set in
 * others in the order.
 * @param mutations
 * @param finalOpStatus
 * @return whether we need a ZK update or not.
 */
private boolean mutateLabelsRegion(List<Mutation> mutations, OperationStatus[] finalOpStatus)
    throws IOException {
  OperationStatus[] opStatus = this.labelsRegion.batchMutate(mutations
    .toArray(new Mutation[mutations.size()]), HConstants.NO_NONCE, HConstants.NO_NONCE);
  int i = 0;
  boolean updateZk = false;
  for (OperationStatus status : opStatus) {
    // Update the zk when atleast one of the mutation was added successfully.
    updateZk = updateZk || (status.getOperationStatusCode() == OperationStatusCode.SUCCESS);
    for (; i < finalOpStatus.length; i++) {
      if (finalOpStatus[i] == null) {
        finalOpStatus[i] = status;
        break;
      }
    }
  }
  return updateZk;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:27,代码来源:DefaultVisibilityLabelServiceImpl.java

示例3: write

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
/**
 * Writes an action (Put or Delete) to the specified table.
 *
 * @param tableName
 *          the table being updated.
 * @param action
 *          the update, either a put or a delete.
 * @throws IllegalArgumentException
 *          if the action is not a put or a delete.
 */
@Override
public void write(ImmutableBytesWritable tableName, Mutation action) throws IOException {
  BufferedMutator mutator = getBufferedMutator(tableName);
  // The actions are not immutable, so we defensively copy them
  if (action instanceof Put) {
    Put put = new Put((Put) action);
    put.setDurability(useWriteAheadLogging ? Durability.SYNC_WAL
        : Durability.SKIP_WAL);
    mutator.mutate(put);
  } else if (action instanceof Delete) {
    Delete delete = new Delete((Delete) action);
    mutator.mutate(delete);
  } else
    throw new IllegalArgumentException(
        "action must be either Delete or Put");
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:27,代码来源:MultiTableOutputFormat.java

示例4: buildRegionAction

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:35,代码来源:RequestConverter.java

示例5: preProcess

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
@Override
public void preProcess(HRegion region, WALEdit walEdit) throws IOException {
  RegionCoprocessorHost coprocessorHost = region.getCoprocessorHost();
  if (coprocessorHost != null) {
    for (Mutation m : mutations) {
      if (m instanceof Put) {
        if (coprocessorHost.prePut((Put) m, walEdit, m.getDurability())) {
          // by pass everything
          return;
        }
      } else if (m instanceof Delete) {
        Delete d = (Delete) m;
        region.prepareDelete(d);
        if (coprocessorHost.preDelete(d, walEdit, d.getDurability())) {
          // by pass everything
          return;
        }
      }
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:22,代码来源:MultiRowMutationProcessor.java

示例6: preMergeCommit

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
@Override
public void preMergeCommit(ObserverContext<RegionServerCoprocessorEnvironment> ctx,
    Region regionA, Region regionB, List<Mutation> metaEntries) throws IOException {
  preMergeBeforePONRCalled = true;
  RegionServerCoprocessorEnvironment environment = ctx.getEnvironment();
  HRegionServer rs = (HRegionServer) environment.getRegionServerServices();
  List<Region> onlineRegions =
      rs.getOnlineRegions(TableName.valueOf("testRegionServerObserver_2"));
  rmt = (RegionMergeTransactionImpl) new RegionMergeTransactionFactory(rs.getConfiguration())
    .create(onlineRegions.get(0), onlineRegions.get(1), true);
  if (!rmt.prepare(rs)) {
    LOG.error("Prepare for the region merge of table "
        + onlineRegions.get(0).getTableDesc().getNameAsString()
        + " failed. So returning null. ");
    ctx.bypass();
    return;
  }
  mergedRegion = rmt.stepsBeforePONR(rs, rs, false);
  rmt.prepareMutationsForMerge(mergedRegion.getRegionInfo(), regionA.getRegionInfo(),
    regionB.getRegionInfo(), rs.getServerName(), metaEntries,
    regionA.getTableDesc().getRegionReplication());
  MetaTableAccessor.mutateMetaTable(rs.getConnection(), metaEntries);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:24,代码来源:TestRegionServerObserver.java

示例7: recordFailure

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
private void recordFailure(final Mutation m, final long keyBase,
    final long start, IOException e) {
  failedKeySet.add(keyBase);
  String exceptionInfo;
  if (e instanceof RetriesExhaustedWithDetailsException) {
    RetriesExhaustedWithDetailsException aggEx = (RetriesExhaustedWithDetailsException) e;
    exceptionInfo = aggEx.getExhaustiveDescription();
  } else {
    StringWriter stackWriter = new StringWriter();
    PrintWriter pw = new PrintWriter(stackWriter);
    e.printStackTrace(pw);
    pw.flush();
    exceptionInfo = StringUtils.stringifyException(e);
  }
  LOG.error("Failed to mutate: " + keyBase + " after " + (System.currentTimeMillis() - start)
      + "ms; region information: " + getRegionDebugInfoSafe(table, m.getRow()) + "; errors: "
      + exceptionInfo);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:19,代码来源:MultiThreadedUpdaterWithACL.java

示例8: beforeMutate

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
@Override
public Mutation beforeMutate(long rowkeyBase, Mutation m) throws IOException {
  if (!(m instanceof Delete)) {
    if (userNames != null && userNames.length > 0) {
      int mod = ((int) rowkeyBase % this.userNames.length);
      if (((int) rowkeyBase % specialPermCellInsertionFactor) == 0) {
        // These cells cannot be read back when running as user userName[mod]
        if (LOG.isTraceEnabled()) {
          LOG.trace("Adding special perm " + rowkeyBase);
        }
        m.setACL(userNames[mod], new Permission(Permission.Action.WRITE));
      } else {
        m.setACL(userNames[mod], new Permission(Permission.Action.READ));
      }
    }
  }
  return m;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:19,代码来源:LoadTestDataGeneratorWithACL.java

示例9: buildNoDataRegionAction

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:36,代码来源:RequestConverter.java

示例10: TablestoreBufferedMutator

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
public TablestoreBufferedMutator(TablestoreConnection connection, TableName tableName) {
    this.tableName = tableName;
    this.connection = connection;
    writeBuffer = new ConcurrentLinkedQueue<Mutation>();
    this.writeBufferSize = this.connection.getConfiguration().getLong("hbase.client.write.buffer", 2097152);
    this.currentWriteBufferSize = 0;
    this.columnMapping = new ColumnMapping(tableName.getNameAsString(), this.connection.getConfiguration());
    this.adapter = OTSAdapter.getInstance(this.connection.getTablestoreConf());
    this.clearBufferOnFail = true;
}
 
开发者ID:aliyun,项目名称:aliyun-tablestore-hbase-client,代码行数:11,代码来源:TablestoreBufferedMutator.java

示例11: mutate

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
@Override
public void mutate(List<? extends Mutation> list) throws IOException {
    List<OPut> flushPuts = new ArrayList<OPut>();
    List<ODelete> flushDeletes = new ArrayList<ODelete>();

    for (Mutation mutation : list) {
        writeBuffer.add(mutation);
        currentWriteBufferSize += mutation.heapSize();
    }
    if (currentWriteBufferSize >= writeBufferSize) {
        extractOMutation(flushPuts, flushDeletes);
    }

    flush(flushPuts, flushDeletes);
}
 
开发者ID:aliyun,项目名称:aliyun-tablestore-hbase-client,代码行数:16,代码来源:TablestoreBufferedMutator.java

示例12: extractOMutation

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
private void extractOMutation(List<OPut> flushPuts, List<ODelete> flushDeletes) {
    for (Mutation mutation : writeBuffer) {
        if (mutation instanceof Put) {
            flushPuts.add(ElementConvertor.toOtsPut((Put)mutation, this.columnMapping));
        } else if (mutation instanceof Delete) {
            flushDeletes.add(ElementConvertor.toOtsDelete((Delete)mutation, this.columnMapping));
        }
    }
    writeBuffer.clear();
    currentWriteBufferSize = 0;
}
 
开发者ID:aliyun,项目名称:aliyun-tablestore-hbase-client,代码行数:12,代码来源:TablestoreBufferedMutator.java

示例13: updateMutationAddingTags

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
private void updateMutationAddingTags(final Mutation m) {
  byte[] attribute = m.getAttribute("visibility");
  byte[] cf = null;
  List<Cell> updatedCells = new ArrayList<Cell>();
  if (attribute != null) {
    for (List<? extends Cell> edits : m.getFamilyCellMap().values()) {
      for (Cell cell : edits) {
        KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
        if (cf == null) {
          cf = kv.getFamily();
        }
        Tag tag = new Tag((byte) 1, attribute);
        List<Tag> tagList = new ArrayList<Tag>();
        tagList.add(tag);

        KeyValue newKV = new KeyValue(kv.getRow(), 0, kv.getRowLength(), kv.getFamily(), 0,
            kv.getFamilyLength(), kv.getQualifier(), 0, kv.getQualifierLength(),
            kv.getTimestamp(), KeyValue.Type.codeToType(kv.getType()), kv.getValue(), 0,
            kv.getValueLength(), tagList);
        ((List<Cell>) updatedCells).add(newKV);
      }
    }
    m.getFamilyCellMap().remove(cf);
    // Update the family map
    m.getFamilyCellMap().put(cf, updatedCells);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:28,代码来源:TestTags.java

示例14: postMutationBeforeWAL

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
@Override
public Cell postMutationBeforeWAL(ObserverContext<RegionCoprocessorEnvironment> ctx,
    MutationType opType, Mutation mutation, Cell oldCell, Cell newCell) throws IOException {
  List<Tag> tags = Lists.newArrayList();
  CellVisibility cellVisibility = null;
  try {
    cellVisibility = mutation.getCellVisibility();
  } catch (DeserializationException e) {
    throw new IOException(e);
  }
  if (cellVisibility == null) {
    return newCell;
  }
  // Prepend new visibility tags to a new list of tags for the cell
  // Don't check user auths for labels with Mutations when the user is super user
  boolean authCheck = authorizationEnabled && checkAuths && !(isSystemOrSuperUser());
  tags.addAll(this.visibilityLabelService.createVisibilityExpTags(cellVisibility.getExpression(),
      true, authCheck));
  // Save an object allocation where we can
  if (newCell.getTagsLength() > 0) {
    // Carry forward all other tags
    Iterator<Tag> tagsItr = CellUtil.tagsIterator(newCell.getTagsArray(),
        newCell.getTagsOffset(), newCell.getTagsLength());
    while (tagsItr.hasNext()) {
      Tag tag = tagsItr.next();
      if (tag.getType() != TagType.VISIBILITY_TAG_TYPE
          && tag.getType() != TagType.VISIBILITY_EXP_SERIALIZATION_FORMAT_TAG_TYPE) {
        tags.add(tag);
      }
    }
  }

  Cell rewriteCell = new TagRewriteCell(newCell, Tag.fromList(tags));
  return rewriteCell;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:36,代码来源:VisibilityController.java

示例15: checkForReservedTagPresence

import org.apache.hadoop.hbase.client.Mutation; //导入依赖的package包/类
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();) {
    Cell cell = cellScanner.current();
    if (cell.getTagsLength() > 0) {
      Iterator<Tag> tagsItr = CellUtil.tagsIterator(cell.getTagsArray(), cell.getTagsOffset(),
        cell.getTagsLength());
      while (tagsItr.hasNext()) {
        if (tagsItr.next().getType() == AccessControlLists.ACL_TAG_TYPE) {
          throw new AccessDeniedException("Mutation contains cell with reserved type tag");
        }
      }
    }
  }
  m.setAttribute(TAG_CHECK_PASSED, TRUE);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:30,代码来源:AccessController.java


注:本文中的org.apache.hadoop.hbase.client.Mutation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。