org.iq80.leveldb.ReadOptions Java Examples

The following examples show how to use org.iq80.leveldb.ReadOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LevelDbUtil.java    From mcg-helper with Apache License 2.0 6 votes vote down vote up
public static void print() throws IOException {
    //iterator,遍历,顺序读
    //读取当前snapshot,快照,读取期间数据的变更,不会反应出来       
    Snapshot snapshot = db.getSnapshot();
    //读选项        
    ReadOptions readOptions = new ReadOptions();
    readOptions.fillCache(false);//遍历中swap出来的数据,不应该保存在memtable中。        
    readOptions.snapshot(snapshot);//默认snapshot为当前。        
    DBIterator iterator = db.iterator(readOptions);
    while (iterator.hasNext()) {
        Map.Entry<byte[],byte[]> item = iterator.next();
        String key = new String(item.getKey(), Constants.CHARSET);
        String value = new String(item.getValue(), Constants.CHARSET);
        logger.debug("key:{},value:{}", key, value);
    }
    iterator.close();
}
 
Example #2
Source File: WarpDB.java    From warp10-platform with Apache License 2.0 6 votes vote down vote up
@Override
public DBIterator iterator(ReadOptions options) {
  if (null == options) {
    return iterator();
  }
  if (null != options.snapshot()) {
    throw new RuntimeException("Snapshots are unsupported.");
  }
  try {
    mutex.lockInterruptibly();
    pendingOps.incrementAndGet();
  } catch (InterruptedException ie) {
    throw new DBException("Interrupted while acquiring DB mutex.", ie);
  } finally {
    if (mutex.isHeldByCurrentThread()) {
      mutex.unlock();
    }
  }    
  return new WarpIterator(pendingOps, this.db.iterator(options));    
}
 
Example #3
Source File: LevelDB.java    From aion with MIT License 5 votes vote down vote up
@Override
public Iterator<byte[]> keys() {
    check();

    try {
        ReadOptions readOptions = new ReadOptions();
        readOptions.snapshot(db.getSnapshot());
        return new LevelDBIteratorWrapper(readOptions, db.iterator(readOptions), LOG);
    } catch (Exception e) {
        LOG.error("Unable to extract keys from database " + this.toString() + ".", e);
    }

    // empty when retrieval failed
    return Collections.emptyIterator();
}
 
Example #4
Source File: LevelDB.java    From aion with MIT License 5 votes vote down vote up
/**
 * @implNote Building two wrappers for the same {@link DBIterator} will lead to inconsistent
 *     behavior.
 */
LevelDBIteratorWrapper(final ReadOptions readOptions, final DBIterator iterator, final Logger log) {
    this.readOptions = readOptions;
    this.iterator = iterator;
    iterator.seekToFirst();
    closed = false;
    this.LOG = log;
}
 
Example #5
Source File: LeveldbIterator.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Create an iterator for the specified database
 */
public LeveldbIterator(DB db, ReadOptions options) {
  iter = db.iterator(options);
}
 
Example #6
Source File: LeveldbIterator.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Create an iterator for the specified database
 */
public LeveldbIterator(DB db, ReadOptions options) {
  iter = db.iterator(options);
}
 
Example #7
Source File: WarpDB.java    From warp10-platform with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] get(byte[] key, ReadOptions options) throws DBException {
  throw new RuntimeException("Unsupported operation get.");
  //return this.db.get(key, options);
}
 
Example #8
Source File: MockDB.java    From ethereumj with MIT License 4 votes vote down vote up
@Override
public byte[] get(byte[] arg0, ReadOptions arg1) throws DBException {
    // TODO Auto-generated method stub
    return null;
}
 
Example #9
Source File: MockDB.java    From ethereumj with MIT License 4 votes vote down vote up
@Override
public DBIterator iterator(ReadOptions arg0) {
    // TODO Auto-generated method stub
    return null;
}