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


Java RocksDB类代码示例

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


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

示例1: RocksDBStore

import org.rocksdb.RocksDB; //导入依赖的package包/类
public RocksDBStore(String name, ColumnFamilyDescriptor family, ColumnFamilyHandle handle, RocksDB db, int stripes) {
  super();
  this.family = family;
  this.name = name;
  this.db = db;
  this.parallel = stripes;
  this.handle = handle;
  this.sharedLocks = new AutoCloseableLock[stripes];
  this.exclusiveLocks = new AutoCloseableLock[stripes];

  for (int i = 0; i < stripes; i++) {
    ReadWriteLock core = new ReentrantReadWriteLock();
    sharedLocks[i] = new AutoCloseableLock(core.readLock());
    exclusiveLocks[i] = new AutoCloseableLock(core.writeLock());
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:RocksDBStore.java

示例2: FindByRangeIterator

import org.rocksdb.RocksDB; //导入依赖的package包/类
public FindByRangeIterator(RocksDB db, ColumnFamilyHandle handle, FindByRange<byte[]> range) {
  this.iter = db.newIterator(handle);
  this.end = range == null ? null : range.getEnd();
  this.endInclusive = range == null ? false : range.isEndInclusive();

  // position at beginning of cursor.
  if (range != null && range.getStart() != null) {
    iter.seek(range.getStart());
    if (!range.isStartInclusive() && Arrays.equals(iter.key(), range.getStart())) {
      iter.next();
    }
  } else {
    iter.seekToFirst();
  }

  populateNext();

}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:19,代码来源:RocksDBStore.java

示例3: main

import org.rocksdb.RocksDB; //导入依赖的package包/类
public static void main(String[] args) {
    RocksDB.loadLibrary();
    Options rockopts = new Options().setCreateIfMissing(false);
    RocksDB db = null;

    try {
        db = RocksDB.open(rockopts, args[0]);
        RocksIterator iter = db.newIterator();
        iter.seekToFirst();
        while (iter.isValid()) {
            String key = new String(iter.key(), StandardCharsets.UTF_8);
            String val = new String(iter.value(), StandardCharsets.UTF_8);
            System.out.println(key + " -> " + val);
            iter.next();
        }

        db.close();
    } catch (RocksDBException rdbe) {
        rdbe.printStackTrace(System.err);
    }
}
 
开发者ID:isoboroff,项目名称:basekb-search,代码行数:22,代码来源:DumpLabelDb.java

示例4: main

import org.rocksdb.RocksDB; //导入依赖的package包/类
public static void main(String[] args) {
    RocksDB.loadLibrary();
    Options rockopts = new Options().setCreateIfMissing(false);
    RocksDB db = null;

    try {
        db = RocksDB.open(rockopts, args[0]);
        String query = args[1];
        byte[] val = db.get(query.getBytes(StandardCharsets.UTF_8));
        if (val != null) {
            System.out.println(new String(val, StandardCharsets.UTF_8));
        }
        db.close();
    } catch (RocksDBException rdbe) {
        rdbe.printStackTrace(System.err);
    }
}
 
开发者ID:isoboroff,项目名称:basekb-search,代码行数:18,代码来源:QueryLabelDb.java

示例5: StreamStore

import org.rocksdb.RocksDB; //导入依赖的package包/类
public StreamStore(String bootstrapServer, String kafkaTopic, int nodeID, int[] partitionToNode) {
    RocksDB.loadLibrary();

    if (bootstrapServer == null) bootstrapServer = DEFAULT_BOOTSTRAP_SERVER;
    Properties consumerConfig = PartitionHandler.consumerConfig();
    Properties producerConfig = PartitionHandler.producerConfig();
    consumerConfig.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServer);
    producerConfig.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServer);

    producer = new KafkaProducer<>(producerConfig);

    if (kafkaTopic == null) kafkaTopic = DEFAULT_KAFKA_TOPIC;
    if (partitionToNode.length != NUM_PARTITIONS) {
        throw new IllegalArgumentException("Expected " + NUM_PARTITIONS + " partitions, got " +
                    partitionToNode.length);
    }

    this.handlers = new PartitionHandler[NUM_PARTITIONS];
    for (int i = 0; i < NUM_PARTITIONS; i++) {
        if (partitionToNode[i] == nodeID) {
            TopicPartition topicPartition = new TopicPartition(kafkaTopic, i);
            this.handlers[i] = new PartitionHandler(topicPartition, consumerConfig, producer);
        } else {
            throw new UnsupportedOperationException("TODO multi-node support");
        }
    }
}
 
开发者ID:trvedata,项目名称:trvedb,代码行数:28,代码来源:StreamStore.java

示例6: close

import org.rocksdb.RocksDB; //导入依赖的package包/类
@Override
public void close() {
    if (this.closed.compareAndSet(false, true)) {
        RocksDB db = this.database.get();
        if (db != null) {
            db.close();
            this.database.set(null);
        }

        if (this.writeOptions != null) {
            this.writeOptions.close();
        }

        if (this.databaseOptions != null) {
            this.databaseOptions.close();
        }

        clear(false);
        log.info("{}: Closed.", this.logId);

        Consumer<String> callback = this.closeCallback;
        if (callback != null) {
            Callbacks.invokeSafely(callback, this.id, null);
        }
    }
}
 
开发者ID:pravega,项目名称:pravega,代码行数:27,代码来源:RocksDBCache.java

示例7: openSuffixDataStore

import org.rocksdb.RocksDB; //导入依赖的package包/类
@Override
public SuffixDataStore openSuffixDataStore(int id) {
  RocksDB.loadLibrary();
  try {
    LOGGER.info("Opening TnT suffix model: {}", id);
    RocksDB rocksDB = RocksDB.openReadOnly(dbPath.resolve(getSuffixesName(id)).toString());
    RocksDbSuffixDataStore rocksDbSuffixDataStore = new RocksDbSuffixDataStore(rocksDB);
    if (inMemory) {
      LOGGER.info("Loading TnT suffix model into memory: {}", id);
      InMemorySuffixDataStore inMemorySuffixDataStore = rocksDbSuffixDataStore.inMemory();
      LOGGER.info("Done loading TnT suffix model into memory: {}", id);
      rocksDB.close();
      return inMemorySuffixDataStore;
    }
    rocksDBS.add(rocksDB);
    return rocksDbSuffixDataStore;
  } catch (RocksDBException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:21,代码来源:RocksDbDataStoreFactory.java

示例8: openKnownWordDataStore

import org.rocksdb.RocksDB; //导入依赖的package包/类
@Override
public KnownWordsDataStore openKnownWordDataStore(int id) {
  RocksDB.loadLibrary();
  try {
    LOGGER.info("Opening TnT model known word model: {}", id);
    RocksDB rocksDB = RocksDB.openReadOnly(dbPath.resolve(getWordsName(id)).toString());
    RocksDB candidatesDB = RocksDB.openReadOnly(dbPath.resolve(getCandidatesName(id)).toString());

    RocksDbKnownWordsDataStore rocksDbKnownWordsDataStore = new RocksDbKnownWordsDataStore(
        rocksDB, candidatesDB);
    if (inMemory) {
      LOGGER.info("Loading TnT known word model into memory: {}", id);
      InMemoryKnownWordDataStore inMemoryKnownWordDataStore = rocksDbKnownWordsDataStore
          .inMemory();
      LOGGER.info("Done loading TnT known word model into memory: {}", id);
      rocksDB.close();
      candidatesDB.close();
      return inMemoryKnownWordDataStore;
    }
    rocksDBS.add(rocksDB);
    rocksDBS.add(candidatesDB);
    return rocksDbKnownWordsDataStore;
  } catch (RocksDBException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:27,代码来源:RocksDbDataStoreFactory.java

示例9: verifyRocksObjectsReleased

import org.rocksdb.RocksDB; //导入依赖的package包/类
private void verifyRocksObjectsReleased() {
	//Ensure every RocksObject was closed exactly once
	for (RocksObject rocksCloseable : allCreatedCloseables) {
		verify(rocksCloseable, times(1)).close();
	}

	assertNotNull(null, keyedStateBackend.db);
	RocksDB spyDB = keyedStateBackend.db;

	if (!enableIncrementalCheckpointing) {
		verify(spyDB, times(1)).getSnapshot();
		verify(spyDB, times(1)).releaseSnapshot(any(Snapshot.class));
	}

	keyedStateBackend.dispose();
	verify(spyDB, times(1)).close();
	assertEquals(null, keyedStateBackend.db);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:19,代码来源:RocksDBStateBackendTest.java

示例10: RocksDbKeyValueReader

import org.rocksdb.RocksDB; //导入依赖的package包/类
/**
 * Construct the <code>RocksDbKeyValueReader</code> with store's name,
 * database's path and Samza's config
 *
 * @param storeName name of the RocksDb defined in the config file
 * @param dbPath path to the db directory
 * @param config Samza's config
 */
public RocksDbKeyValueReader(String storeName, String dbPath, Config config) {
  // get the key serde and value serde from the config
  JavaStorageConfig storageConfig = new JavaStorageConfig(config);
  JavaSerializerConfig serializerConfig = new JavaSerializerConfig(config);

  keySerde = getSerdeFromName(storageConfig.getStorageKeySerde(storeName), serializerConfig);
  valueSerde = getSerdeFromName(storageConfig.getStorageMsgSerde(storeName), serializerConfig);

  // get db options
  ArrayList<TaskName> taskNameList = new ArrayList<TaskName>();
  taskNameList.add(new TaskName("read-rocks-db"));
  SamzaContainerContext samzaContainerContext =
      new SamzaContainerContext("0",  config, taskNameList, new MetricsRegistryMap());
  Options options = RocksDbOptionsHelper.options(config, samzaContainerContext);

  // open the db
  RocksDB.loadLibrary();
  try {
    db = RocksDB.openReadOnly(options, dbPath);
  } catch (RocksDBException e) {
    throw new SamzaException("can not open the rocksDb in " + dbPath, e);
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:32,代码来源:RocksDbKeyValueReader.java

示例11: AccessControl

import org.rocksdb.RocksDB; //导入依赖的package包/类
public AccessControl(RocksDB db, ColumnFamilyHandle ruleCf, ColumnFamilyHandle policyCf) throws RocksDBException {
    this.db = db;
    this.ruleCf = ruleCf;
    this.policyCf = policyCf;

    rules = loadRules(db, ruleCf);
    policies = loadPolicies(db, policyCf);

    rulesBySurt = new RulesBySsurt(rules.values());

    nextRuleId = new AtomicLong(calculateNextId(db, ruleCf));
    nextPolicyId = new AtomicLong(calculateNextId(db, policyCf));

    if (policies.isEmpty()) {
        // create some default policies
        put(new AccessPolicy("Public", "public", "staff"));
        put(new AccessPolicy("Staff Only", "staff"));
        put(new AccessPolicy("No Access"));
    }
}
 
开发者ID:nla,项目名称:outbackcdx,代码行数:21,代码来源:AccessControl.java

示例12: prepareColumnFamilyDescriptors

import org.rocksdb.RocksDB; //导入依赖的package包/类
private void prepareColumnFamilyDescriptors() throws RocksDBException {
    if (columnFamilies == null || columnFamilies.size() == 0) {
        if (columnFamilies == null) {
            columnFamilies = new HashSet<>();
        }
        String[] cfList = RocksDbUtils.getColumnFamilyList(directory.getAbsolutePath());
        for (String cf : cfList) {
            columnFamilies.add(RocksDbUtils.buildColumnFamilyDescriptor(cf));
        }
    }

    boolean hasDefaultCf = false;
    for (ColumnFamilyDescriptor cfd : columnFamilies) {
        if (Arrays.equals(cfd.columnFamilyName(), RocksDB.DEFAULT_COLUMN_FAMILY)) {
            hasDefaultCf = true;
            break;
        }
    }
    if (!hasDefaultCf) {
        columnFamilies.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
    }
}
 
开发者ID:DDTH,项目名称:ddth-queue,代码行数:23,代码来源:RocksDbWrapper.java

示例13: executeWrite

import org.rocksdb.RocksDB; //导入依赖的package包/类
private void executeWrite(Query q)
{
  MyConnection conn = null;
  try
  {
    byte[] key = q.getKey().getBytes();
    conn = _connPool.getConnection(q.getDbName());
    _log.debug(Thread.currentThread().getName() + ": Got conn");
    ((RocksDB) conn.getConn()).put(key, q.getValue());
    _log.debug(Thread.currentThread().getName() + ": Performed put");

    q.setResult(QueryResult.OK);
  }
  catch(Exception e)
  {
    _log.error(Thread.currentThread().getName() + ": Write query failed", e);
    q.setResult(QueryResult.FAIL);
  }
  finally
  {
    if(conn != null)
      tryRelease(conn);
    _log.debug(Thread.currentThread().getName() + ": Released conn");
  }
}
 
开发者ID:linkedin,项目名称:MTBT,代码行数:26,代码来源:RocksdbQueryHandler.java

示例14: executeDelete

import org.rocksdb.RocksDB; //导入依赖的package包/类
private void executeDelete(Query q)
{
  MyConnection conn = null;
  try
  {
    byte[] key = q.getKey().getBytes();
    conn = _connPool.getConnection(q.getDbName());
    _log.debug(Thread.currentThread().getName() + ": Got conn");
    ((RocksDB) conn.getConn()).remove(key);
    _log.debug(Thread.currentThread().getName() + ": Performed remove");

    q.setResult(QueryResult.OK);
  }
  catch(Exception e)
  {
    _log.error(Thread.currentThread().getName() + ": Delete query failed", e);
    q.setResult(QueryResult.FAIL);
  }
  finally
  {
    if(conn != null)
      tryRelease(conn);
    _log.debug(Thread.currentThread().getName() + ": Released conn");
  }
}
 
开发者ID:linkedin,项目名称:MTBT,代码行数:26,代码来源:RocksdbQueryHandler.java

示例15: TupleIndexR

import org.rocksdb.RocksDB; //导入依赖的package包/类
protected TupleIndexR(RocksDB db, int N, TupleMap indexMapping, String name) {
    super(N, indexMapping, name) ;
    this.rdb = db;
    NodeId n[] = new NodeId[N] ;
    Arrays.fill(n, NodeId.NodeIdAny);
    allPattern = TupleFactory.create(n);
}
 
开发者ID:afs,项目名称:tdb3,代码行数:8,代码来源:TupleIndexR.java


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