co.cask.cdap.api.common.Bytes.stopKeyForPrefix()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中co.cask.cdap.api.common.Bytes.stopKeyForPrefix()方法的一些代码示例,展示了Bytes.stopKeyForPrefix()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.stopKeyForPrefix()方法的具体详情如下:
包路径:co.cask.cdap.api.common.Bytes
类名称:Bytes
方法名:stopKeyForPrefix

Bytes.stopKeyForPrefix介绍

[英]Returns the given prefix, incremented by one, in the form that will be suitable for prefix matching.
[中]以适合于前缀匹配的形式返回给定前缀(递增1)。

代码示例

代码示例来源:origin: co.cask.cdap/cdap-watchdog

private byte[] getNextContextStartKey(byte[] rowkey) {
 // rowkey : <prefix-bytes>:context:event-ts(8):creation-time(8)
 int contextLength = rowkey.length -
  (LoggingStoreTableUtil.NEW_FILE_META_ROW_KEY_PREFIX.length + 2 * Bytes.SIZEOF_LONG);
 Preconditions.checkState(contextLength > 0, String.format("Invalid row-key with length %s", rowkey.length));
 byte[] context = new byte[contextLength];
 System.arraycopy(rowkey, LoggingStoreTableUtil.NEW_FILE_META_ROW_KEY_PREFIX.length, context, 0, contextLength);
 return Bytes.stopKeyForPrefix(context);
}

代码示例来源:origin: caskdata/cdap

private byte[] getNextContextStartKey(byte[] rowkey) {
 // rowkey : <prefix-bytes>:context:event-ts(8):creation-time(8)
 int contextLength = rowkey.length -
  (LoggingStoreTableUtil.NEW_FILE_META_ROW_KEY_PREFIX.length + 2 * Bytes.SIZEOF_LONG);
 Preconditions.checkState(contextLength > 0, String.format("Invalid row-key with length %s", rowkey.length));
 byte[] context = new byte[contextLength];
 System.arraycopy(rowkey, LoggingStoreTableUtil.NEW_FILE_META_ROW_KEY_PREFIX.length, context, 0, contextLength);
 return Bytes.stopKeyForPrefix(context);
}

代码示例来源:origin: caskdata/cdap

@Override
public List<TopicId> listTopics(NamespaceId namespaceId) throws IOException {
 byte[] startKey = MessagingUtils.topicScanKey(namespaceId);
 byte[] stopKey = Bytes.stopKeyForPrefix(startKey);
 return listTopics(startKey, stopKey);
}

代码示例来源:origin: co.cask.cdap/cdap-tms

@Override
public List<TopicId> listTopics(NamespaceId namespaceId) throws IOException {
 byte[] startKey = MessagingUtils.topicScanKey(namespaceId);
 byte[] stopKey = Bytes.stopKeyForPrefix(startKey);
 return listTopics(startKey, stopKey);
}

代码示例来源:origin: co.cask.cdap/cdap-app-fabric

private Scan scanPlugins(Id.Artifact parentArtifactId, @Nullable String type) {
 byte[] startRow = Bytes.toBytes(Joiner.on(":").skipNulls().join(PLUGIN_PREFIX,
                                 parentArtifactId.getNamespace().getId(),
                                 parentArtifactId.getName(), type) + ":");
 return new Scan(startRow, Bytes.stopKeyForPrefix(startRow));
}

代码示例来源:origin: co.cask.cdap/cdap-app-fabric

private Scan scanAppClasses(NamespaceId namespace) {
 byte[] startRow = Bytes.toBytes(String.format("%s:%s:", APPCLASS_PREFIX, namespace.getNamespace()));
 return new Scan(startRow, Bytes.stopKeyForPrefix(startRow));
}

代码示例来源:origin: co.cask.cdap/cdap-app-fabric

@Override
public CloseableIterator<Job> getJobsForSchedule(ScheduleId scheduleId) {
 byte[] keyPrefix = getRowKeyPrefix(scheduleId);
 return createCloseableIterator(table.scan(keyPrefix, Bytes.stopKeyForPrefix(keyPrefix)));
}

代码示例来源:origin: cdapio/cdap

@Override
public CloseableIterator<Job> getJobsForSchedule(ScheduleId scheduleId) {
 byte[] keyPrefix = getRowKeyPrefix(scheduleId);
 return createCloseableIterator(table.scan(keyPrefix, Bytes.stopKeyForPrefix(keyPrefix)));
}

代码示例来源:origin: co.cask.cdap/cdap-app-fabric

public List<Config> list(String namespace, String type) {
 List<Config> configList = Lists.newArrayList();
 byte[] prefixBytes = rowKeyPrefix(namespace, type);
 try (Scanner rows = table.scan(prefixBytes, Bytes.stopKeyForPrefix(prefixBytes))) {
  Row row;
  while ((row = rows.next()) != null) {
   Map<String, String> properties = GSON.fromJson(Bytes.toString(row.get(PROPERTY_COLUMN)),
                           MAP_STRING_STRING_TYPE);
   configList.add(new Config(getPart(row.getRow(), prefixBytes.length), properties));
  }
  return configList;
 }
}

代码示例来源:origin: co.cask.cdap/cdap-data-fabric

static MDSKey getMDSScanStopKey(MetadataEntity metadataEntity) {
 MDSKey.Builder builder = getKeyPart(metadataEntity);
 return new MDSKey(Bytes.stopKeyForPrefix(builder.build().getKey()));
}

代码示例来源:origin: caskdata/cdap

@Override
public List<TopicId> listTopics(NamespaceId namespaceId) throws IOException {
 byte[] startRow = MessagingUtils.topicScanKey(namespaceId);
 ScanBuilder scanBuilder = tableUtil.buildScan()
  .setStartRow(startRow)
  .setStopRow(Bytes.stopKeyForPrefix(startRow));
 return scanTopics(scanBuilder);
}

代码示例来源:origin: caskdata/cdap

@Override
public CloseableIterator<Entry> fetch(TopicMetadata metadata, long startTime, int limit,
                   @Nullable Transaction transaction) throws IOException {
 byte[] topic = MessagingUtils.toDataKeyPrefix(metadata.getTopicId(), metadata.getGeneration());
 byte[] startRow = new byte[topic.length + Bytes.SIZEOF_LONG];
 Bytes.putBytes(startRow, 0, topic, 0, topic.length);
 Bytes.putLong(startRow, topic.length, startTime);
 byte[] stopRow = Bytes.stopKeyForPrefix(topic);
 final CloseableIterator<RawMessageTableEntry> scanner = read(startRow, stopRow);
 return new FetchIterator(scanner, limit, null, transaction);
}

代码示例来源:origin: co.cask.cdap/cdap-tms

@Override
public CloseableIterator<Entry> fetch(TopicMetadata metadata, long startTime, int limit,
                   @Nullable Transaction transaction) throws IOException {
 byte[] topic = MessagingUtils.toDataKeyPrefix(metadata.getTopicId(), metadata.getGeneration());
 byte[] startRow = new byte[topic.length + Bytes.SIZEOF_LONG];
 Bytes.putBytes(startRow, 0, topic, 0, topic.length);
 Bytes.putLong(startRow, topic.length, startTime);
 byte[] stopRow = Bytes.stopKeyForPrefix(topic);
 final CloseableIterator<RawMessageTableEntry> scanner = read(startRow, stopRow);
 return new FetchIterator(scanner, limit, null, transaction);
}

代码示例来源:origin: co.cask.cdap/cdap-app-fabric

@Override
public void remove(ApplicationId applicationId) {
 byte[] startRowKey = new MDSKey.Builder().add(applicationId.getNamespace())
  .add(applicationId.getApplication()).build().getKey();
 byte[] stopRowKey = new MDSKey(Bytes.stopKeyForPrefix(startRowKey)).getKey();
 try {
  table.deleteRange(startRowKey, stopRowKey, null, null);
 } catch (IOException e) {
  String message = String.format("Error while removing preview data for application '%s'.", applicationId);
  throw new RuntimeException(message, e);
 }
}

代码示例来源:origin: cdapio/cdap

@Override
public void remove(ApplicationId applicationId) {
 byte[] startRowKey = new MDSKey.Builder().add(applicationId.getNamespace())
  .add(applicationId.getApplication()).build().getKey();
 byte[] stopRowKey = new MDSKey(Bytes.stopKeyForPrefix(startRowKey)).getKey();
 try {
  table.deleteRange(startRowKey, stopRowKey, null, null);
 } catch (IOException e) {
  String message = String.format("Error while removing preview data for application '%s'.", applicationId);
  throw new RuntimeException(message, e);
 }
}

代码示例来源:origin: co.cask.cdap/cdap-data-fabric

HBaseConsumerStateStore(String datasetName, QueueName queueName, Table table) {
 super(datasetName, table);
 this.queueName = queueName;
 this.table = table;
 this.barrierScanStartRow = Bytes.add(queueName.toBytes(), QueueEntryRow.getQueueEntryRowKey(queueName, 0L, 0));
 this.barrierScanEndRow = Bytes.stopKeyForPrefix(
  Bytes.add(queueName.toBytes(), QueueEntryRow.getQueueEntryRowKey(queueName, Long.MAX_VALUE, 0)));
}

代码示例来源:origin: caskdata/cdap

@Override
public CloseableIterator<Entry> fetch(TopicMetadata metadata, MessageId messageId, boolean inclusive,
                   final int limit, @Nullable final Transaction transaction) throws IOException {
 byte[] topic = MessagingUtils.toDataKeyPrefix(metadata.getTopicId(), metadata.getGeneration());
 byte[] startRow = new byte[topic.length + Bytes.SIZEOF_LONG + Bytes.SIZEOF_SHORT];
 Bytes.putBytes(startRow, 0, topic, 0, topic.length);
 Bytes.putLong(startRow, topic.length, messageId.getPublishTimestamp());
 Bytes.putShort(startRow, topic.length + Bytes.SIZEOF_LONG, messageId.getSequenceId());
 byte[] stopRow = Bytes.stopKeyForPrefix(topic);
 final CloseableIterator<RawMessageTableEntry> scanner = read(startRow, stopRow);
 return new FetchIterator(scanner, limit, inclusive ? null : startRow, transaction);
}

代码示例来源:origin: co.cask.cdap/cdap-tms

@Override
public CloseableIterator<Entry> fetch(TopicMetadata metadata, MessageId messageId, boolean inclusive,
                   final int limit, @Nullable final Transaction transaction) throws IOException {
 byte[] topic = MessagingUtils.toDataKeyPrefix(metadata.getTopicId(), metadata.getGeneration());
 byte[] startRow = new byte[topic.length + Bytes.SIZEOF_LONG + Bytes.SIZEOF_SHORT];
 Bytes.putBytes(startRow, 0, topic, 0, topic.length);
 Bytes.putLong(startRow, topic.length, messageId.getPublishTimestamp());
 Bytes.putShort(startRow, topic.length + Bytes.SIZEOF_LONG, messageId.getSequenceId());
 byte[] stopRow = Bytes.stopKeyForPrefix(topic);
 final CloseableIterator<RawMessageTableEntry> scanner = read(startRow, stopRow);
 return new FetchIterator(scanner, limit, inclusive ? null : startRow, transaction);
}

代码示例来源:origin: cdapio/cdap

public void delete(ApplicationId id) {
 MDSKey mdsKey = new MDSKey.Builder().add(id.getNamespace()).add(id.getApplication()).build();
 Scanner scanner = table.scan(mdsKey.getKey(), Bytes.stopKeyForPrefix(mdsKey.getKey()));
 Row row;
 try {
  while ((row = scanner.next()) != null) {
   table.delete(row.getRow());
  }
 } finally {
  scanner.close();
 }
}

代码示例来源:origin: co.cask.cdap/cdap-app-fabric

public void delete(ApplicationId id) {
 MDSKey mdsKey = new MDSKey.Builder().add(id.getNamespace()).add(id.getApplication()).build();
 Scanner scanner = table.scan(mdsKey.getKey(), Bytes.stopKeyForPrefix(mdsKey.getKey()));
 Row row;
 try {
  while ((row = scanner.next()) != null) {
   table.delete(row.getRow());
  }
 } finally {
  scanner.close();
 }
}

相关文章