org.rocksdb.RocksDB.getLongProperty()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(160)

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

RocksDB.getLongProperty介绍

[英]Similar to GetProperty(), but only works for a subset of properties whose return value is a numerical value. Return the value as long.

Note: As the returned property is of type uint64_t on C++ side the returning value can be negative because Java supports in Java 7 only signed long values.

Java 7: To mitigate the problem of the non existent unsigned long tpye, values should be encapsulated using java.math.BigInteger to reflect the correct value. The correct behavior is guaranteed if 2^64 is added to negative values.

Java 8: In Java 8 the value should be treated as unsigned long using provided methods of type Long.
[中]与GetProperty()类似,但仅适用于返回值为数值的属性子集。尽可能长地返回值。
注意:由于返回属性是C++侧的UTIN 64类型,返回值可以是负的,因为java支持java 7只签名长值。
Java7:为了缓解不存在无符号长tpye的问题,应该使用Java封装值。数学BigInteger以反映正确的值。如果将2^64添加到负值,则保证行为正确。
Java 8:在Java 8中,应该使用提供的long类型的方法将该值视为无符号long。

代码示例

代码示例来源:origin: apache/flink

  1. /**
  2. * Updates the value of metricView if the reference is still valid.
  3. */
  4. private void setProperty(ColumnFamilyHandle handle, String property, RocksDBNativeMetricView metricView) {
  5. if (metricView.isClosed()) {
  6. return;
  7. }
  8. try {
  9. synchronized (lock) {
  10. if (rocksDB != null) {
  11. long value = rocksDB.getLongProperty(handle, property);
  12. metricView.setValue(value);
  13. }
  14. }
  15. } catch (RocksDBException e) {
  16. metricView.close();
  17. LOG.warn("Failed to read native metric %s from RocksDB", property, e);
  18. }
  19. }

代码示例来源:origin: opendedup/sdfs

  1. public long setUp() throws Exception {
  2. long sz = 0;
  3. // System.out.println("s="+i);
  4. sz += dbs.getLongProperty("rocksdb.estimate-num-keys");
  5. long size = sz;
  6. this.closed = false;
  7. return size;
  8. }

代码示例来源:origin: opendedup/sdfs

  1. /**
  2. * initializes the Object set of this hash table.
  3. *
  4. * @param initialCapacity
  5. * an <code>int</code> value
  6. * @return an <code>int</code> value
  7. * @throws HashtableFullException
  8. * @throws FileNotFoundException
  9. */
  10. public long setUp() throws Exception {
  11. long sz = 0;
  12. for (RocksDB db : dbs) {
  13. // System.out.println("s="+i);
  14. sz += db.getLongProperty("rocksdb.estimate-num-keys");
  15. }
  16. long size = sz;
  17. this.closed = false;
  18. return size;
  19. }

代码示例来源:origin: opendedup/sdfs

  1. /**
  2. * initializes the Object set of this hash table.
  3. *
  4. * @param initialCapacity
  5. * an <code>int</code> value
  6. * @return an <code>int</code> value
  7. * @throws HashtableFullException
  8. * @throws FileNotFoundException
  9. */
  10. public long setUp() throws Exception {
  11. long sz = 0;
  12. for (RocksDB db : dbs) {
  13. // System.out.println("s="+i);
  14. sz += db.getLongProperty("rocksdb.estimate-num-keys");
  15. }
  16. long size = sz;
  17. this.closed = false;
  18. return size;
  19. }

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

  1. @Override
  2. public long count() throws IOException {
  3. try {
  4. return db.getLongProperty("rocksdb.estimate-num-keys");
  5. } catch (RocksDBException e) {
  6. throw new IOException("Error in getting records count", e);
  7. }
  8. }

代码示例来源:origin: dremio/dremio-oss

  1. private void append(StringBuilder sb, String propName, String propDisplayName) throws RocksDBException {
  2. sb.append("* ");
  3. sb.append(propDisplayName);
  4. sb.append(": ");
  5. sb.append(db.getLongProperty(handle, propName));
  6. sb.append("\n");
  7. }

代码示例来源:origin: org.rocksdb/rocksdbjni

  1. /**
  2. * <p> Similar to GetProperty(), but only works for a subset of properties
  3. * whose return value is a numerical value. Return the value as long.</p>
  4. *
  5. * <p><strong>Note</strong>: As the returned property is of type
  6. * {@code uint64_t} on C++ side the returning value can be negative
  7. * because Java supports in Java 7 only signed long values.</p>
  8. *
  9. * <p><strong>Java 7</strong>: To mitigate the problem of the non
  10. * existent unsigned long tpye, values should be encapsulated using
  11. * {@link java.math.BigInteger} to reflect the correct value. The correct
  12. * behavior is guaranteed if {@code 2^64} is added to negative values.</p>
  13. *
  14. * <p><strong>Java 8</strong>: In Java 8 the value should be treated as
  15. * unsigned long using provided methods of type {@link Long}.</p>
  16. *
  17. * @param property to be fetched.
  18. *
  19. * @return numerical property value.
  20. *
  21. * @throws RocksDBException if an error happens in the underlying native code.
  22. */
  23. public long getLongProperty(final String property) throws RocksDBException {
  24. return getLongProperty(nativeHandle_, property, property.length());
  25. }

代码示例来源:origin: org.rocksdb/rocksdbjni

  1. /**
  2. * <p> Similar to GetProperty(), but only works for a subset of properties
  3. * whose return value is a numerical value. Return the value as long.</p>
  4. *
  5. * <p><strong>Note</strong>: As the returned property is of type
  6. * {@code uint64_t} on C++ side the returning value can be negative
  7. * because Java supports in Java 7 only signed long values.</p>
  8. *
  9. * <p><strong>Java 7</strong>: To mitigate the problem of the non
  10. * existent unsigned long tpye, values should be encapsulated using
  11. * {@link java.math.BigInteger} to reflect the correct value. The correct
  12. * behavior is guaranteed if {@code 2^64} is added to negative values.</p>
  13. *
  14. * <p><strong>Java 8</strong>: In Java 8 the value should be treated as
  15. * unsigned long using provided methods of type {@link Long}.</p>
  16. *
  17. * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
  18. * instance
  19. * @param property to be fetched.
  20. *
  21. * @return numerical property value
  22. *
  23. * @throws RocksDBException if an error happens in the underlying native code.
  24. */
  25. public long getLongProperty(final ColumnFamilyHandle columnFamilyHandle,
  26. final String property) throws RocksDBException {
  27. return getLongProperty(nativeHandle_, columnFamilyHandle.nativeHandle_,
  28. property, property.length());
  29. }

代码示例来源:origin: opendedup/sdfs

  1. public long getSize() {
  2. try {
  3. long sz = 0;
  4. sz = dbs.getLongProperty("rocksdb.estimate-num-keys");
  5. return sz;
  6. } catch (RocksDBException e) {
  7. SDFSLogger.getLog().error("unable to get lenght for rocksdb", e);
  8. return 0;
  9. }
  10. }

代码示例来源:origin: opendedup/sdfs

  1. @Override
  2. public long getSize() {
  3. try {
  4. long sz = 0;
  5. for (RocksDB db : dbs) {
  6. sz += db.getLongProperty("rocksdb.estimate-num-keys");
  7. }
  8. return sz;
  9. } catch (RocksDBException e) {
  10. SDFSLogger.getLog().error("unable to get lenght for rocksdb", e);
  11. return 0;
  12. }
  13. }

代码示例来源:origin: opendedup/sdfs

  1. @Override
  2. public long getUsedSize() {
  3. try {
  4. long sz = 0;
  5. for (RocksDB db : dbs) {
  6. sz += db.getLongProperty("rocksdb.estimate-num-keys");
  7. }
  8. return sz * Main.CHUNK_LENGTH;
  9. } catch (RocksDBException e) {
  10. SDFSLogger.getLog().error("unable to get lenght for rocksdb", e);
  11. return 0;
  12. }
  13. }

代码示例来源:origin: opendedup/sdfs

  1. @Override
  2. public long getUsedSize() {
  3. try {
  4. long sz = 0;
  5. for (RocksDB db : dbs) {
  6. sz += db.getLongProperty("rocksdb.estimate-num-keys");
  7. }
  8. return sz * Main.CHUNK_LENGTH;
  9. } catch (RocksDBException e) {
  10. SDFSLogger.getLog().error("unable to get lenght for rocksdb", e);
  11. return 0;
  12. }
  13. }

代码示例来源:origin: opendedup/sdfs

  1. @Override
  2. public long getSize() {
  3. try {
  4. long sz = 0;
  5. for (RocksDB db : dbs) {
  6. sz += db.getLongProperty("rocksdb.estimate-num-keys");
  7. }
  8. return sz;
  9. } catch (RocksDBException e) {
  10. SDFSLogger.getLog().error("unable to get lenght for rocksdb", e);
  11. return 0;
  12. }
  13. }

代码示例来源:origin: org.apache.flink/flink-statebackend-rocksdb_2.11

  1. /**
  2. * Updates the value of metricView if the reference is still valid.
  3. */
  4. private void setProperty(ColumnFamilyHandle handle, String property, RocksDBNativeMetricView metricView) {
  5. if (metricView.isClosed()) {
  6. return;
  7. }
  8. try {
  9. synchronized (lock) {
  10. if (rocksDB != null) {
  11. long value = rocksDB.getLongProperty(handle, property);
  12. metricView.setValue(value);
  13. }
  14. }
  15. } catch (RocksDBException e) {
  16. metricView.close();
  17. LOG.warn("Failed to read native metric %s from RocksDB", property, e);
  18. }
  19. }

代码示例来源:origin: org.apache.flink/flink-statebackend-rocksdb

  1. /**
  2. * Updates the value of metricView if the reference is still valid.
  3. */
  4. private void setProperty(ColumnFamilyHandle handle, String property, RocksDBNativeMetricView metricView) {
  5. if (metricView.isClosed()) {
  6. return;
  7. }
  8. try {
  9. synchronized (lock) {
  10. if (rocksDB != null) {
  11. long value = rocksDB.getLongProperty(handle, property);
  12. metricView.setValue(value);
  13. }
  14. }
  15. } catch (RocksDBException e) {
  16. metricView.close();
  17. LOG.warn("Failed to read native metric %s from RocksDB", property, e);
  18. }
  19. }

代码示例来源:origin: dremio/dremio-oss

  1. private void registerMetrics() {
  2. final MetricSetBuilder builder = new MetricSetBuilder(MetricRegistry.name(METRICS_PREFIX, name));
  3. for (String property : METRIC_PROPERTIES) {
  4. builder.gauge(property, () -> {
  5. try {
  6. return db.getLongProperty(handle, property);
  7. } catch (RocksDBException e) {
  8. // throwing an exception would cause Dropwizard's metrics reporter to not report the remaining metrics
  9. logger.warn("failed to retrieve property '{}", property, e);
  10. return null;
  11. }
  12. });
  13. }
  14. Metrics.getInstance().registerAll(builder.build());
  15. }

代码示例来源:origin: org.apache.kafka/kafka-streams

  1. /**
  2. * Return an approximate count of key-value mappings in this store.
  3. *
  4. * <code>RocksDB</code> cannot return an exact entry count without doing a
  5. * full scan, so this method relies on the <code>rocksdb.estimate-num-keys</code>
  6. * property to get an approximate count. The returned size also includes
  7. * a count of dirty keys in the store's in-memory cache, which may lead to some
  8. * double-counting of entries and inflate the estimate.
  9. *
  10. * @return an approximate count of key-value mappings in the store.
  11. */
  12. @Override
  13. public long approximateNumEntries() {
  14. validateStoreOpen();
  15. final long value;
  16. try {
  17. value = db.getLongProperty("rocksdb.estimate-num-keys");
  18. } catch (final RocksDBException e) {
  19. throw new ProcessorStateException("Error fetching property from store " + name, e);
  20. }
  21. if (isOverflowing(value)) {
  22. return Long.MAX_VALUE;
  23. }
  24. return value;
  25. }

相关文章