Java 类com.google.protobuf.HBaseZeroCopyByteString 实例源码

项目:HIndex    文件:VisibilityController.java   
@Override
public synchronized void getAuths(RpcController controller, GetAuthsRequest request,
    RpcCallback<GetAuthsResponse> done) {
  byte[] user = request.getUser().toByteArray();
  GetAuthsResponse.Builder response = GetAuthsResponse.newBuilder();
  response.setUser(request.getUser());
  try {
    List<String> labels = getUserAuthsFromLabelsTable(user);
    for (String label : labels) {
      response.addAuth(HBaseZeroCopyByteString.wrap(Bytes.toBytes(label)));
    }
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  }
  done.run(response.build());
}
项目:HIndex    文件:CellSetModel.java   
@Override
public byte[] createProtobufOutput() {
  CellSet.Builder builder = CellSet.newBuilder();
  for (RowModel row: getRows()) {
    CellSet.Row.Builder rowBuilder = CellSet.Row.newBuilder();
    rowBuilder.setKey(HBaseZeroCopyByteString.wrap(row.getKey()));
    for (CellModel cell: row.getCells()) {
      Cell.Builder cellBuilder = Cell.newBuilder();
      cellBuilder.setColumn(HBaseZeroCopyByteString.wrap(cell.getColumn()));
      cellBuilder.setData(HBaseZeroCopyByteString.wrap(cell.getValue()));
      if (cell.hasUserTimestamp()) {
        cellBuilder.setTimestamp(cell.getTimestamp());
      }
      rowBuilder.addValues(cellBuilder);
    }
    builder.addRows(rowBuilder);
  }
  return builder.build().toByteArray();
}
项目:HIndex    文件:TableSnapshotInputFormatImpl.java   
@Override
public void write(DataOutput out) throws IOException {
  MapReduceProtos.TableSnapshotRegionSplit.Builder builder =
    MapReduceProtos.TableSnapshotRegionSplit.newBuilder()
      .setRegion(HBaseProtos.RegionSpecifier.newBuilder()
        .setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.ENCODED_REGION_NAME)
        .setValue(HBaseZeroCopyByteString.wrap(Bytes.toBytes(regionName))).build());

  for (String location : locations) {
    builder.addLocations(location);
  }

  MapReduceProtos.TableSnapshotRegionSplit split = builder.build();

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  split.writeTo(baos);
  baos.close();
  byte[] buf = baos.toByteArray();
  out.writeInt(buf.length);
  out.write(buf);
}
项目:HIndex    文件:MessageCodec.java   
@Override
public void write(Cell cell) throws IOException {
  checkFlushed();
  CellProtos.Cell.Builder builder = CellProtos.Cell.newBuilder();
  // This copies bytes from Cell to ByteString.  I don't see anyway around the copy.
  // ByteString is final.
  builder.setRow(HBaseZeroCopyByteString.wrap(cell.getRowArray(), cell.getRowOffset(),
      cell.getRowLength()));
  builder.setFamily(HBaseZeroCopyByteString.wrap(cell.getFamilyArray(), cell.getFamilyOffset(),
      cell.getFamilyLength()));
  builder.setQualifier(HBaseZeroCopyByteString.wrap(cell.getQualifierArray(),
      cell.getQualifierOffset(), cell.getQualifierLength()));
  builder.setTimestamp(cell.getTimestamp());
  builder.setCellType(CellProtos.CellType.valueOf(cell.getTypeByte()));
  builder.setValue(HBaseZeroCopyByteString.wrap(cell.getValueArray(), cell.getValueOffset(),
      cell.getValueLength()));
  CellProtos.Cell pbcell = builder.build();
  pbcell.writeDelimitedTo(this.out);
}
项目:HIndex    文件:HRegionServer.java   
/**
 * Roll the WAL writer of the region server.
 * @param controller the RPC controller
 * @param request the request
 * @throws ServiceException
 */
@Override
public RollWALWriterResponse rollWALWriter(final RpcController controller,
    final RollWALWriterRequest request) throws ServiceException {
  try {
    checkOpen();
    requestCount.increment();
    HLog wal = this.getWAL();
    byte[][] regionsToFlush = wal.rollWriter(true);
    RollWALWriterResponse.Builder builder = RollWALWriterResponse.newBuilder();
    if (regionsToFlush != null) {
      for (byte[] region: regionsToFlush) {
        builder.addRegionToFlush(HBaseZeroCopyByteString.wrap(region));
      }
    }
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
项目:HIndex    文件:TestCoprocessorEndpoint.java   
private Map<byte [], Long> sum(final HTable table, final byte [] family,
    final byte [] qualifier, final byte [] start, final byte [] end)
throws ServiceException, Throwable {
  return table.coprocessorService(ColumnAggregationProtos.ColumnAggregationService.class,
      start, end,
    new Batch.Call<ColumnAggregationProtos.ColumnAggregationService, Long>() {
      @Override
      public Long call(ColumnAggregationProtos.ColumnAggregationService instance)
      throws IOException {
        BlockingRpcCallback<ColumnAggregationProtos.SumResponse> rpcCallback =
            new BlockingRpcCallback<ColumnAggregationProtos.SumResponse>();
        ColumnAggregationProtos.SumRequest.Builder builder =
          ColumnAggregationProtos.SumRequest.newBuilder();
        builder.setFamily(HBaseZeroCopyByteString.wrap(family));
        if (qualifier != null && qualifier.length > 0) {
          builder.setQualifier(HBaseZeroCopyByteString.wrap(qualifier));
        }
        instance.sum(null, builder.build(), rpcCallback);
        return rpcCallback.get().getSum();
      }
    });
}
项目:HIndex    文件:RequestConverter.java   
/**
 * Create a new protocol buffer GetRequest to get a row, all columns in a family.
 * If there is no such row, return the closest row before it.
 *
 * @param regionName the name of the region to get
 * @param row the row to get
 * @param family the column family to get
 * should return the immediate row before
 * @return a protocol buffer GetReuqest
 */
public static GetRequest buildGetRowOrBeforeRequest(
    final byte[] regionName, final byte[] row, final byte[] family) {
  GetRequest.Builder builder = GetRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(
    RegionSpecifierType.REGION_NAME, regionName);
  builder.setRegion(region);

  Column.Builder columnBuilder = Column.newBuilder();
  columnBuilder.setFamily(HBaseZeroCopyByteString.wrap(family));
  ClientProtos.Get.Builder getBuilder =
    ClientProtos.Get.newBuilder();
  getBuilder.setRow(HBaseZeroCopyByteString.wrap(row));
  getBuilder.addColumn(columnBuilder.build());
  getBuilder.setClosestRowBefore(true);
  builder.setGet(getBuilder.build());
  return builder.build();
}
项目:HIndex    文件:RequestConverter.java   
/**
 * Create a protocol buffer bulk load request
 *
 * @param familyPaths
 * @param regionName
 * @param assignSeqNum
 * @return a bulk load request
 */
public static BulkLoadHFileRequest buildBulkLoadHFileRequest(
    final List<Pair<byte[], String>> familyPaths,
    final byte[] regionName, boolean assignSeqNum) {
  BulkLoadHFileRequest.Builder builder = BulkLoadHFileRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(
    RegionSpecifierType.REGION_NAME, regionName);
  builder.setRegion(region);
  FamilyPath.Builder familyPathBuilder = FamilyPath.newBuilder();
  for (Pair<byte[], String> familyPath: familyPaths) {
    familyPathBuilder.setFamily(HBaseZeroCopyByteString.wrap(familyPath.getFirst()));
    familyPathBuilder.setPath(familyPath.getSecond());
    builder.addFamilyPath(familyPathBuilder.build());
  }
  builder.setAssignSeqNum(assignSeqNum);
  return builder.build();
}
项目:HIndex    文件:ProtobufUtil.java   
/**
 * Code shared by {@link #toMutation(MutationType, Mutation)} and
 * {@link #toMutationNoData(MutationType, Mutation)}
 * @param type
 * @param mutation
 * @return A partly-filled out protobuf'd Mutation.
 */
private static MutationProto.Builder getMutationBuilderAndSetCommonFields(final MutationType type,
    final Mutation mutation, MutationProto.Builder builder) {
  builder.setRow(HBaseZeroCopyByteString.wrap(mutation.getRow()));
  builder.setMutateType(type);
  builder.setDurability(toDurability(mutation.getDurability()));
  builder.setTimestamp(mutation.getTimeStamp());
  Map<String, byte[]> attributes = mutation.getAttributesMap();
  if (!attributes.isEmpty()) {
    NameBytesPair.Builder attributeBuilder = NameBytesPair.newBuilder();
    for (Map.Entry<String, byte[]> attribute: attributes.entrySet()) {
      attributeBuilder.setName(attribute.getKey());
      attributeBuilder.setValue(HBaseZeroCopyByteString.wrap(attribute.getValue()));
      builder.addAttribute(attributeBuilder.build());
    }
  }
  return builder;
}
项目:HIndex    文件:ProtobufUtil.java   
/**
 * A utility used to get permissions for selected namespace.
 * <p>
 * It's also called by the shell, in case you want to find references.
 *
 * @param protocol the AccessControlService protocol proxy
 * @param namespace name of the namespace
 * @throws ServiceException
 */
public static List<UserPermission> getUserPermissions(
    AccessControlService.BlockingInterface protocol,
    byte[] namespace) throws ServiceException {
  AccessControlProtos.GetUserPermissionsRequest.Builder builder =
    AccessControlProtos.GetUserPermissionsRequest.newBuilder();
  if (namespace != null) {
    builder.setNamespaceName(HBaseZeroCopyByteString.wrap(namespace));
  }
  builder.setType(AccessControlProtos.Permission.Type.Namespace);
  AccessControlProtos.GetUserPermissionsRequest request = builder.build();
  AccessControlProtos.GetUserPermissionsResponse response =
    protocol.getUserPermissions(null, request);
  List<UserPermission> perms = new ArrayList<UserPermission>();
  for (AccessControlProtos.UserPermission perm: response.getUserPermissionList()) {
    perms.add(ProtobufUtil.toUserPermission(perm));
  }
  return perms;
}
项目:HIndex    文件:ProtobufUtil.java   
public static CellProtos.Cell toCell(final Cell kv) {
  // Doing this is going to kill us if we do it for all data passed.
  // St.Ack 20121205
  CellProtos.Cell.Builder kvbuilder = CellProtos.Cell.newBuilder();
  kvbuilder.setRow(HBaseZeroCopyByteString.wrap(kv.getRowArray(), kv.getRowOffset(),
      kv.getRowLength()));
  kvbuilder.setFamily(HBaseZeroCopyByteString.wrap(kv.getFamilyArray(),
      kv.getFamilyOffset(), kv.getFamilyLength()));
  kvbuilder.setQualifier(HBaseZeroCopyByteString.wrap(kv.getQualifierArray(),
      kv.getQualifierOffset(), kv.getQualifierLength()));
  kvbuilder.setCellType(CellProtos.CellType.valueOf(kv.getTypeByte()));
  kvbuilder.setTimestamp(kv.getTimestamp());
  kvbuilder.setValue(HBaseZeroCopyByteString.wrap(kv.getValueArray(), kv.getValueOffset(),
      kv.getValueLength()));
  return kvbuilder.build();
}
项目:HIndex    文件:ProtobufUtil.java   
public static CompactionDescriptor toCompactionDescriptor(HRegionInfo info, byte[] family,
    List<Path> inputPaths, List<Path> outputPaths, Path storeDir) {
  // compaction descriptor contains relative paths.
  // input / output paths are relative to the store dir
  // store dir is relative to region dir
  CompactionDescriptor.Builder builder = CompactionDescriptor.newBuilder()
      .setTableName(HBaseZeroCopyByteString.wrap(info.getTableName()))
      .setEncodedRegionName(HBaseZeroCopyByteString.wrap(info.getEncodedNameAsBytes()))
      .setFamilyName(HBaseZeroCopyByteString.wrap(family))
      .setStoreHomeDir(storeDir.getName()); //make relative
  for (Path inputPath : inputPaths) {
    builder.addCompactionInput(inputPath.getName()); //relative path
  }
  for (Path outputPath : outputPaths) {
    builder.addCompactionOutput(outputPath.getName());
  }
  return builder.build();
}
项目:HIndex    文件:ZKUtil.java   
/**
 * @param regionLastFlushedSequenceId the flushed sequence id of a region which is the min of its
 *          store max seq ids
 * @param storeSequenceIds column family to sequence Id map
 * @return Serialized protobuf of <code>RegionSequenceIds</code> with pb magic prefix prepended
 *         suitable for use to filter wal edits in distributedLogReplay mode
 */
public static byte[] regionSequenceIdsToByteArray(final Long regionLastFlushedSequenceId,
    final Map<byte[], Long> storeSequenceIds) {
  ZooKeeperProtos.RegionStoreSequenceIds.Builder regionSequenceIdsBuilder =
      ZooKeeperProtos.RegionStoreSequenceIds.newBuilder();
  ZooKeeperProtos.StoreSequenceId.Builder storeSequenceIdBuilder =
      ZooKeeperProtos.StoreSequenceId.newBuilder();
  if (storeSequenceIds != null) {
    for (Map.Entry<byte[], Long> e : storeSequenceIds.entrySet()){
      byte[] columnFamilyName = e.getKey();
      Long curSeqId = e.getValue();
      storeSequenceIdBuilder.setFamilyName(HBaseZeroCopyByteString.wrap(columnFamilyName));
      storeSequenceIdBuilder.setSequenceId(curSeqId);
      regionSequenceIdsBuilder.addStoreSequenceId(storeSequenceIdBuilder.build());
      storeSequenceIdBuilder.clear();
    }
  }
  regionSequenceIdsBuilder.setLastFlushedSequenceId(regionLastFlushedSequenceId);
  byte[] result = regionSequenceIdsBuilder.build().toByteArray();
  return ProtobufUtil.prependPBMagic(result);
}
项目:HIndex    文件:HRegionInfo.java   
/**
 * Convert a HRegionInfo to a RegionInfo
 *
 * @param info the HRegionInfo to convert
 * @return the converted RegionInfo
 */
public static RegionInfo convert(final HRegionInfo info) {
  if (info == null) return null;
  RegionInfo.Builder builder = RegionInfo.newBuilder();
  builder.setTableName(ProtobufUtil.toProtoTableName(info.getTable()));
  builder.setRegionId(info.getRegionId());
  if (info.getStartKey() != null) {
    builder.setStartKey(HBaseZeroCopyByteString.wrap(info.getStartKey()));
  }
  if (info.getEndKey() != null) {
    builder.setEndKey(HBaseZeroCopyByteString.wrap(info.getEndKey()));
  }
  builder.setOffline(info.isOffline());
  builder.setSplit(info.isSplit());
  return builder.build();
}
项目:HIndex    文件:SingleColumnValueFilter.java   
public FilterProtos.SingleColumnValueFilter convert() {
  FilterProtos.SingleColumnValueFilter.Builder builder =
    FilterProtos.SingleColumnValueFilter.newBuilder();
  if (this.columnFamily != null) {
    builder.setColumnFamily(HBaseZeroCopyByteString.wrap(this.columnFamily));
  }
  if (this.columnQualifier != null) {
    builder.setColumnQualifier(HBaseZeroCopyByteString.wrap(this.columnQualifier));
  }
  HBaseProtos.CompareType compareOp = CompareType.valueOf(this.compareOp.name());
  builder.setCompareOp(compareOp);
  builder.setComparator(ProtobufUtil.toComparator(this.comparator));
  builder.setFilterIfMissing(this.filterIfMissing);
  builder.setLatestVersionOnly(this.latestVersionOnly);

  return builder.build();
}
项目:kylin    文件:CubeHBaseEndpointRPC.java   
private ByteString serializeGTScanReq(GTScanRequest scanRequest) {
    ByteString scanRequestByteString;
    int scanRequestBufferSize = BytesSerializer.SERIALIZE_BUFFER_SIZE;
    while (true) {
        try {
            ByteBuffer buffer = ByteBuffer.allocate(scanRequestBufferSize);
            GTScanRequest.serializer.serialize(scanRequest, buffer);
            buffer.flip();
            scanRequestByteString = HBaseZeroCopyByteString.wrap(buffer.array(), buffer.position(), buffer.limit());
            break;
        } catch (BufferOverflowException boe) {
            logger.info("Buffer size {} cannot hold the scan request, resizing to 4 times", scanRequestBufferSize);
            scanRequestBufferSize *= 4;
        }
    }
    return scanRequestByteString;
}
项目:kylin    文件:CubeHBaseEndpointRPC.java   
private ByteString serializeRawScans(List<RawScan> rawScans) {
    ByteString rawScanByteString;
    int rawScanBufferSize = BytesSerializer.SERIALIZE_BUFFER_SIZE;
    while (true) {
        try {
            ByteBuffer rawScanBuffer = ByteBuffer.allocate(rawScanBufferSize);
            BytesUtil.writeVInt(rawScans.size(), rawScanBuffer);
            for (RawScan rs : rawScans) {
                RawScan.serializer.serialize(rs, rawScanBuffer);
            }
            rawScanBuffer.flip();
            rawScanByteString = HBaseZeroCopyByteString.wrap(rawScanBuffer.array(), rawScanBuffer.position(), rawScanBuffer.limit());
            break;
        } catch (BufferOverflowException boe) {
            logger.info("Buffer size {} cannot hold the raw scans, resizing to 4 times", rawScanBufferSize);
            rawScanBufferSize *= 4;
        }
    }
    return rawScanByteString;
}
项目:kylin    文件:CubeHBaseEndpointRPC.java   
private String getStatsString(byte[] region, CubeVisitResponse result) {
    StringBuilder sb = new StringBuilder();
    Stats stats = result.getStats();
    byte[] compressedRows = HBaseZeroCopyByteString.zeroCopyGetBytes(result.getCompressedRows());

    sb.append("Endpoint RPC returned from HTable ").append(cubeSeg.getStorageLocationIdentifier()).append(" Shard ").append(BytesUtil.toHex(region)).append(" on host: ").append(stats.getHostname()).append(".");
    sb.append("Total scanned row: ").append(stats.getScannedRowCount()).append(". ");
    sb.append("Total scanned bytes: ").append(stats.getScannedBytes()).append(". ");
    sb.append("Total filtered row: ").append(stats.getFilteredRowCount()).append(". ");
    sb.append("Total aggred row: ").append(stats.getAggregatedRowCount()).append(". ");
    sb.append("Time elapsed in EP: ").append(stats.getServiceEndTime() - stats.getServiceStartTime()).append("(ms). ");
    sb.append("Server CPU usage: ").append(stats.getSystemCpuLoad()).append(", server physical mem left: ").append(stats.getFreePhysicalMemorySize()).append(", server swap mem left:").append(stats.getFreeSwapSpaceSize()).append(".");
    sb.append("Etc message: ").append(stats.getEtcMsg()).append(".");
    sb.append("Normal Complete: ").append(stats.getNormalComplete() == 1).append(".");
    sb.append("Compressed row size: ").append(compressedRows.length);
    return sb.toString();

}
项目:CSBT    文件:TestCrossSiteCoprocessor.java   
private Map<byte[], SumResponse> sumInBatch(final CrossSiteHTable table,
    final String[] clusterNames, final byte[] family, final byte[] qualifier, final byte[] start,
    final byte[] end) throws ServiceException, Throwable {
  ColumnAggregationProtos.SumRequest.Builder builder = ColumnAggregationProtos.SumRequest
      .newBuilder();
  builder.setFamily(HBaseZeroCopyByteString.wrap(family));
  if (qualifier != null && qualifier.length > 0) {
    builder.setQualifier(HBaseZeroCopyByteString.wrap(qualifier));
  }
  final Map<byte[], ColumnAggregationProtos.SumResponse> results = Collections
      .synchronizedMap(new TreeMap<byte[], ColumnAggregationProtos.SumResponse>(
          Bytes.BYTES_COMPARATOR));
  table.batchCoprocessorService(ColumnAggregationProtos.ColumnAggregationService.getDescriptor()
      .findMethodByName("sum"), builder.build(), start, end, clusterNames,
      ColumnAggregationProtos.SumResponse.getDefaultInstance(),
      new Callback<ColumnAggregationProtos.SumResponse>() {

        @Override
        public void update(byte[] region, byte[] row, ColumnAggregationProtos.SumResponse result) {
          if (region != null) {
            results.put(region, result);
          }
        }
      });
  return results;
}
项目:PyroDB    文件:VisibilityController.java   
@Override
public synchronized void getAuths(RpcController controller, GetAuthsRequest request,
    RpcCallback<GetAuthsResponse> done) {
  byte[] user = request.getUser().toByteArray();
  GetAuthsResponse.Builder response = GetAuthsResponse.newBuilder();
  response.setUser(request.getUser());
  try {
    List<String> labels = getUserAuthsFromLabelsTable(user);
    for (String label : labels) {
      response.addAuth(HBaseZeroCopyByteString.wrap(Bytes.toBytes(label)));
    }
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  }
  done.run(response.build());
}
项目:PyroDB    文件:CellSetModel.java   
@Override
public byte[] createProtobufOutput() {
  CellSet.Builder builder = CellSet.newBuilder();
  for (RowModel row: getRows()) {
    CellSet.Row.Builder rowBuilder = CellSet.Row.newBuilder();
    rowBuilder.setKey(HBaseZeroCopyByteString.wrap(row.getKey()));
    for (CellModel cell: row.getCells()) {
      Cell.Builder cellBuilder = Cell.newBuilder();
      cellBuilder.setColumn(HBaseZeroCopyByteString.wrap(cell.getColumn()));
      cellBuilder.setData(HBaseZeroCopyByteString.wrap(cell.getValue()));
      if (cell.hasUserTimestamp()) {
        cellBuilder.setTimestamp(cell.getTimestamp());
      }
      rowBuilder.addValues(cellBuilder);
    }
    builder.addRows(rowBuilder);
  }
  return builder.build().toByteArray();
}
项目:PyroDB    文件:MessageCodec.java   
@Override
public void write(Cell cell) throws IOException {
  checkFlushed();
  CellProtos.Cell.Builder builder = CellProtos.Cell.newBuilder();
  // This copies bytes from Cell to ByteString.  I don't see anyway around the copy.
  // ByteString is final.
  builder.setRow(HBaseZeroCopyByteString.wrap(cell.getRowArray(), cell.getRowOffset(),
      cell.getRowLength()));
  builder.setFamily(HBaseZeroCopyByteString.wrap(cell.getFamilyArray(), cell.getFamilyOffset(),
      cell.getFamilyLength()));
  builder.setQualifier(HBaseZeroCopyByteString.wrap(cell.getQualifierArray(),
      cell.getQualifierOffset(), cell.getQualifierLength()));
  builder.setTimestamp(cell.getTimestamp());
  builder.setCellType(CellProtos.CellType.valueOf(cell.getTypeByte()));
  builder.setValue(HBaseZeroCopyByteString.wrap(cell.getValueArray(), cell.getValueOffset(),
      cell.getValueLength()));
  CellProtos.Cell pbcell = builder.build();
  pbcell.writeDelimitedTo(this.out);
}
项目:PyroDB    文件:RSRpcServices.java   
/**
 * Roll the WAL writer of the region server.
 * @param controller the RPC controller
 * @param request the request
 * @throws ServiceException
 */
@Override
public RollWALWriterResponse rollWALWriter(final RpcController controller,
    final RollWALWriterRequest request) throws ServiceException {
  try {
    checkOpen();
    requestCount.increment();
    HLog wal = regionServer.getWAL();
    byte[][] regionsToFlush = wal.rollWriter(true);
    RollWALWriterResponse.Builder builder = RollWALWriterResponse.newBuilder();
    if (regionsToFlush != null) {
      for (byte[] region: regionsToFlush) {
        builder.addRegionToFlush(HBaseZeroCopyByteString.wrap(region));
      }
    }
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
项目:PyroDB    文件:TestCoprocessorEndpoint.java   
private Map<byte [], Long> sum(final HTable table, final byte [] family,
    final byte [] qualifier, final byte [] start, final byte [] end)
throws ServiceException, Throwable {
  return table.coprocessorService(ColumnAggregationProtos.ColumnAggregationService.class,
      start, end,
    new Batch.Call<ColumnAggregationProtos.ColumnAggregationService, Long>() {
      @Override
      public Long call(ColumnAggregationProtos.ColumnAggregationService instance)
      throws IOException {
        BlockingRpcCallback<ColumnAggregationProtos.SumResponse> rpcCallback =
            new BlockingRpcCallback<ColumnAggregationProtos.SumResponse>();
        ColumnAggregationProtos.SumRequest.Builder builder =
          ColumnAggregationProtos.SumRequest.newBuilder();
        builder.setFamily(HBaseZeroCopyByteString.wrap(family));
        if (qualifier != null && qualifier.length > 0) {
          builder.setQualifier(HBaseZeroCopyByteString.wrap(qualifier));
        }
        instance.sum(null, builder.build(), rpcCallback);
        return rpcCallback.get().getSum();
      }
    });
}
项目:PyroDB    文件:RequestConverter.java   
/**
 * Create a new protocol buffer GetRequest to get a row, all columns in a family.
 * If there is no such row, return the closest row before it.
 *
 * @param regionName the name of the region to get
 * @param row the row to get
 * @param family the column family to get
 * should return the immediate row before
 * @return a protocol buffer GetReuqest
 */
public static GetRequest buildGetRowOrBeforeRequest(
    final byte[] regionName, final byte[] row, final byte[] family) {
  GetRequest.Builder builder = GetRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(
    RegionSpecifierType.REGION_NAME, regionName);
  builder.setRegion(region);

  Column.Builder columnBuilder = Column.newBuilder();
  columnBuilder.setFamily(HBaseZeroCopyByteString.wrap(family));
  ClientProtos.Get.Builder getBuilder =
    ClientProtos.Get.newBuilder();
  getBuilder.setRow(HBaseZeroCopyByteString.wrap(row));
  getBuilder.addColumn(columnBuilder.build());
  getBuilder.setClosestRowBefore(true);
  builder.setGet(getBuilder.build());
  return builder.build();
}
项目:PyroDB    文件:RequestConverter.java   
/**
 * Create a protocol buffer bulk load request
 *
 * @param familyPaths
 * @param regionName
 * @param assignSeqNum
 * @return a bulk load request
 */
public static BulkLoadHFileRequest buildBulkLoadHFileRequest(
    final List<Pair<byte[], String>> familyPaths,
    final byte[] regionName, boolean assignSeqNum) {
  BulkLoadHFileRequest.Builder builder = BulkLoadHFileRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(
    RegionSpecifierType.REGION_NAME, regionName);
  builder.setRegion(region);
  FamilyPath.Builder familyPathBuilder = FamilyPath.newBuilder();
  for (Pair<byte[], String> familyPath: familyPaths) {
    familyPathBuilder.setFamily(HBaseZeroCopyByteString.wrap(familyPath.getFirst()));
    familyPathBuilder.setPath(familyPath.getSecond());
    builder.addFamilyPath(familyPathBuilder.build());
  }
  builder.setAssignSeqNum(assignSeqNum);
  return builder.build();
}
项目:PyroDB    文件:RequestConverter.java   
/**
 * Shen Li: add parameter reuseFile
 */
public static SplitRegionRequest buildSplitRegionRequest(
    final byte[] regionName, final byte[] splitPoint,
    boolean reuseFile) {
  SplitRegionRequest.Builder builder = SplitRegionRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(
    RegionSpecifierType.REGION_NAME, regionName);
  builder.setRegion(region);
  if (splitPoint != null) {
    builder.setSplitPoint(HBaseZeroCopyByteString.wrap(splitPoint));
  }
  if (reuseFile) {
    builder.setReuseFile(reuseFile);
  }
  return builder.build();
}
项目:PyroDB    文件:RequestConverter.java   
/**
 * Shen Li: add parameter replicaNum
 */
public static CreateTableRequest buildCreateTableRequest(
    final HTableDescriptor hTableDesc, final byte [][] splitKeys,
    int replicaNum) {
  CreateTableRequest.Builder builder = CreateTableRequest.newBuilder();
  builder.setTableSchema(hTableDesc.convert());
  if (splitKeys != null) {
    for (byte [] splitKey : splitKeys) {
      builder.addSplitKeys(HBaseZeroCopyByteString.wrap(splitKey));
    }
  }
  if (replicaNum > 1) {
    builder.setReplicaNum(replicaNum);
  }
  return builder.build();
}
项目:PyroDB    文件:ProtobufUtil.java   
/**
 * Code shared by {@link #toMutation(MutationType, Mutation)} and
 * {@link #toMutationNoData(MutationType, Mutation)}
 * @param type
 * @param mutation
 * @return A partly-filled out protobuf'd Mutation.
 */
private static MutationProto.Builder getMutationBuilderAndSetCommonFields(final MutationType type,
    final Mutation mutation, MutationProto.Builder builder) {
  builder.setRow(HBaseZeroCopyByteString.wrap(mutation.getRow()));
  builder.setMutateType(type);
  builder.setDurability(toDurability(mutation.getDurability()));
  builder.setTimestamp(mutation.getTimeStamp());
  Map<String, byte[]> attributes = mutation.getAttributesMap();
  if (!attributes.isEmpty()) {
    NameBytesPair.Builder attributeBuilder = NameBytesPair.newBuilder();
    for (Map.Entry<String, byte[]> attribute: attributes.entrySet()) {
      attributeBuilder.setName(attribute.getKey());
      attributeBuilder.setValue(HBaseZeroCopyByteString.wrap(attribute.getValue()));
      builder.addAttribute(attributeBuilder.build());
    }
  }
  return builder;
}
项目:PyroDB    文件:ProtobufUtil.java   
/**
 * A utility used to get permissions for selected namespace.
 * <p>
 * It's also called by the shell, in case you want to find references.
 *
 * @param protocol the AccessControlService protocol proxy
 * @param namespace name of the namespace
 * @throws ServiceException
 */
public static List<UserPermission> getUserPermissions(
    AccessControlService.BlockingInterface protocol,
    byte[] namespace) throws ServiceException {
  AccessControlProtos.GetUserPermissionsRequest.Builder builder =
    AccessControlProtos.GetUserPermissionsRequest.newBuilder();
  if (namespace != null) {
    builder.setNamespaceName(HBaseZeroCopyByteString.wrap(namespace));
  }
  builder.setType(AccessControlProtos.Permission.Type.Namespace);
  AccessControlProtos.GetUserPermissionsRequest request = builder.build();
  AccessControlProtos.GetUserPermissionsResponse response =
    protocol.getUserPermissions(null, request);
  List<UserPermission> perms = new ArrayList<UserPermission>();
  for (AccessControlProtos.UserPermission perm: response.getUserPermissionList()) {
    perms.add(ProtobufUtil.toUserPermission(perm));
  }
  return perms;
}
项目:PyroDB    文件:ProtobufUtil.java   
public static CellProtos.Cell toCell(final Cell kv) {
  // Doing this is going to kill us if we do it for all data passed.
  // St.Ack 20121205
  CellProtos.Cell.Builder kvbuilder = CellProtos.Cell.newBuilder();
  kvbuilder.setRow(HBaseZeroCopyByteString.wrap(kv.getRowArray(), kv.getRowOffset(),
      kv.getRowLength()));
  kvbuilder.setFamily(HBaseZeroCopyByteString.wrap(kv.getFamilyArray(),
      kv.getFamilyOffset(), kv.getFamilyLength()));
  kvbuilder.setQualifier(HBaseZeroCopyByteString.wrap(kv.getQualifierArray(),
      kv.getQualifierOffset(), kv.getQualifierLength()));
  kvbuilder.setCellType(CellProtos.CellType.valueOf(kv.getTypeByte()));
  kvbuilder.setTimestamp(kv.getTimestamp());
  kvbuilder.setValue(HBaseZeroCopyByteString.wrap(kv.getValueArray(), kv.getValueOffset(),
      kv.getValueLength()));
  return kvbuilder.build();
}
项目:PyroDB    文件:ProtobufUtil.java   
public static CompactionDescriptor toCompactionDescriptor(HRegionInfo info, byte[] family,
    List<Path> inputPaths, List<Path> outputPaths, Path storeDir) {
  // compaction descriptor contains relative paths.
  // input / output paths are relative to the store dir
  // store dir is relative to region dir
  CompactionDescriptor.Builder builder = CompactionDescriptor.newBuilder()
      .setTableName(HBaseZeroCopyByteString.wrap(info.getTableName()))
      .setEncodedRegionName(HBaseZeroCopyByteString.wrap(info.getEncodedNameAsBytes()))
      .setFamilyName(HBaseZeroCopyByteString.wrap(family))
      .setStoreHomeDir(storeDir.getName()); //make relative
  for (Path inputPath : inputPaths) {
    builder.addCompactionInput(inputPath.getName()); //relative path
  }
  for (Path outputPath : outputPaths) {
    builder.addCompactionOutput(outputPath.getName());
  }
  return builder.build();
}
项目:PyroDB    文件:ZKUtil.java   
/**
 * @param regionLastFlushedSequenceId the flushed sequence id of a region which is the min of its
 *          store max seq ids
 * @param storeSequenceIds column family to sequence Id map
 * @return Serialized protobuf of <code>RegionSequenceIds</code> with pb magic prefix prepended
 *         suitable for use to filter wal edits in distributedLogReplay mode
 */
public static byte[] regionSequenceIdsToByteArray(final Long regionLastFlushedSequenceId,
    final Map<byte[], Long> storeSequenceIds) {
  ZooKeeperProtos.RegionStoreSequenceIds.Builder regionSequenceIdsBuilder =
      ZooKeeperProtos.RegionStoreSequenceIds.newBuilder();
  ZooKeeperProtos.StoreSequenceId.Builder storeSequenceIdBuilder =
      ZooKeeperProtos.StoreSequenceId.newBuilder();
  if (storeSequenceIds != null) {
    for (Map.Entry<byte[], Long> e : storeSequenceIds.entrySet()){
      byte[] columnFamilyName = e.getKey();
      Long curSeqId = e.getValue();
      storeSequenceIdBuilder.setFamilyName(HBaseZeroCopyByteString.wrap(columnFamilyName));
      storeSequenceIdBuilder.setSequenceId(curSeqId);
      regionSequenceIdsBuilder.addStoreSequenceId(storeSequenceIdBuilder.build());
      storeSequenceIdBuilder.clear();
    }
  }
  regionSequenceIdsBuilder.setLastFlushedSequenceId(regionLastFlushedSequenceId);
  byte[] result = regionSequenceIdsBuilder.build().toByteArray();
  return ProtobufUtil.prependPBMagic(result);
}
项目:PyroDB    文件:SingleColumnValueFilter.java   
FilterProtos.SingleColumnValueFilter convert() {
  FilterProtos.SingleColumnValueFilter.Builder builder =
    FilterProtos.SingleColumnValueFilter.newBuilder();
  if (this.columnFamily != null) {
    builder.setColumnFamily(HBaseZeroCopyByteString.wrap(this.columnFamily));
  }
  if (this.columnQualifier != null) {
    builder.setColumnQualifier(HBaseZeroCopyByteString.wrap(this.columnQualifier));
  }
  HBaseProtos.CompareType compareOp = CompareType.valueOf(this.compareOp.name());
  builder.setCompareOp(compareOp);
  builder.setComparator(ProtobufUtil.toComparator(this.comparator));
  builder.setFilterIfMissing(this.filterIfMissing);
  builder.setLatestVersionOnly(this.latestVersionOnly);

  return builder.build();
}
项目:knowledge    文件:PostfixFilter.java   
@Override
public byte[] toByteArray() throws IOException
{
    CustomFilterProtos.PostfixFilter.Builder builder = CustomFilterProtos.PostfixFilter.newBuilder();
    builder.setCompareOp(compareOp.ordinal());
    builder.setOffset(offset);
    builder.setPostfix(HBaseZeroCopyByteString.wrap(postfix));

    return builder.build().toByteArray();
}
项目:HIndex    文件:VisibilityUtils.java   
/**
 * Creates the labels data to be written to zookeeper.
 * @param existingLabels
 * @return Bytes form of labels and their ordinal details to be written to zookeeper.
 */
public static byte[] getDataToWriteToZooKeeper(Map<String, Integer> existingLabels) {
  VisibilityLabelsRequest.Builder visReqBuilder = VisibilityLabelsRequest.newBuilder();
  for (Entry<String, Integer> entry : existingLabels.entrySet()) {
    VisibilityLabel.Builder visLabBuilder = VisibilityLabel.newBuilder();
    visLabBuilder.setLabel(HBaseZeroCopyByteString.wrap(Bytes.toBytes(entry.getKey())));
    visLabBuilder.setOrdinal(entry.getValue());
    visReqBuilder.addVisLabel(visLabBuilder.build());
  }
  return ProtobufUtil.prependPBMagic(visReqBuilder.build().toByteArray());
}
项目:HIndex    文件:VisibilityUtils.java   
/**
 * Creates the user auth data to be written to zookeeper.
 * @param userAuths
 * @return Bytes form of user auths details to be written to zookeeper.
 */
public static byte[] getUserAuthsDataToWriteToZooKeeper(Map<String, List<Integer>> userAuths) {
  MultiUserAuthorizations.Builder builder = MultiUserAuthorizations.newBuilder();
  for (Entry<String, List<Integer>> entry : userAuths.entrySet()) {
    UserAuthorizations.Builder userAuthsBuilder = UserAuthorizations.newBuilder();
    userAuthsBuilder.setUser(HBaseZeroCopyByteString.wrap(Bytes.toBytes(entry.getKey())));
    for (Integer label : entry.getValue()) {
      userAuthsBuilder.addAuth(label);
    }
    builder.addUserAuths(userAuthsBuilder.build());
  }
  return ProtobufUtil.prependPBMagic(builder.build().toByteArray());
}
项目:HIndex    文件:TableInfoModel.java   
@Override
public byte[] createProtobufOutput() {
  TableInfo.Builder builder = TableInfo.newBuilder();
  builder.setName(name);
  for (TableRegionModel aRegion: regions) {
    TableInfo.Region.Builder regionBuilder = TableInfo.Region.newBuilder();
    regionBuilder.setName(aRegion.getName());
    regionBuilder.setId(aRegion.getId());
    regionBuilder.setStartKey(HBaseZeroCopyByteString.wrap(aRegion.getStartKey()));
    regionBuilder.setEndKey(HBaseZeroCopyByteString.wrap(aRegion.getEndKey()));
    regionBuilder.setLocation(aRegion.getLocation());
    builder.addRegions(regionBuilder);
  }
  return builder.build().toByteArray();
}
项目:HIndex    文件:ScannerModel.java   
@Override
public byte[] createProtobufOutput() {
  Scanner.Builder builder = Scanner.newBuilder();
  if (!Bytes.equals(startRow, HConstants.EMPTY_START_ROW)) {
    builder.setStartRow(HBaseZeroCopyByteString.wrap(startRow));
  }
  if (!Bytes.equals(endRow, HConstants.EMPTY_START_ROW)) {
    builder.setEndRow(HBaseZeroCopyByteString.wrap(endRow));
  }
  for (byte[] column: columns) {
    builder.addColumns(HBaseZeroCopyByteString.wrap(column));
  }
  if (startTime != 0) {
    builder.setStartTime(startTime);
  }
  if (endTime != 0) {
    builder.setEndTime(endTime);
  }
  builder.setBatch(getBatch());
  if (caching > 0) {
    builder.setCaching(caching);
  }
  builder.setMaxVersions(maxVersions);
  if (filter != null) {
    builder.setFilter(filter);
  }
  if (labels != null && labels.size() > 0) {
    for (String label : labels)
      builder.addLabels(label);
  }
  builder.setCacheBlocks(cacheBlocks);
  return builder.build().toByteArray();
}
项目:HIndex    文件:CellModel.java   
@Override
public byte[] createProtobufOutput() {
  Cell.Builder builder = Cell.newBuilder();
  builder.setColumn(HBaseZeroCopyByteString.wrap(getColumn()));
  builder.setData(HBaseZeroCopyByteString.wrap(getValue()));
  if (hasUserTimestamp()) {
    builder.setTimestamp(getTimestamp());
  }
  return builder.build().toByteArray();
}