org.iq80.leveldb.Snapshot Java Examples

The following examples show how to use org.iq80.leveldb.Snapshot. 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 Snapshot delete(byte[] key, WriteOptions options) throws DBException {
  if (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();
    }
  }
  try {
    return this.db.delete(key, options);
  } finally {
    this.pendingOps.decrementAndGet();
  }
}
 
Example #3
Source File: WarpDB.java    From warp10-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Snapshot put(byte[] key, byte[] value, WriteOptions options) throws DBException {
  if (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();
    }
  }
  try {
    return this.db.put(key, value, options);
  } finally {
    this.pendingOps.decrementAndGet();
  }
}
 
Example #4
Source File: WarpDB.java    From warp10-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Snapshot write(WriteBatch updates, WriteOptions options) throws DBException {
  if (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();
    }
  }
  try {
    return this.db.write(updates, options);
  } finally {
    this.pendingOps.decrementAndGet();
  }    
}
 
Example #5
Source File: WarpDB.java    From warp10-platform with Apache License 2.0 4 votes vote down vote up
@Override
public Snapshot getSnapshot() {
  throw new RuntimeException("Snapshots are unsupported.");
  //return this.db.getSnapshot();
}
 
Example #6
Source File: MockDB.java    From ethereumj with MIT License 4 votes vote down vote up
@Override
public Snapshot delete(byte[] arg0, WriteOptions arg1)
        throws DBException {
    // TODO Auto-generated method stub
    return null;
}
 
Example #7
Source File: MockDB.java    From ethereumj with MIT License 4 votes vote down vote up
@Override
public Snapshot getSnapshot() {
    // TODO Auto-generated method stub
    return null;
}
 
Example #8
Source File: MockDB.java    From ethereumj with MIT License 4 votes vote down vote up
@Override
public Snapshot put(byte[] arg0, byte[] arg1, WriteOptions arg2)
        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 Snapshot write(WriteBatch arg0, WriteOptions arg1)
        throws DBException {
    // TODO Auto-generated method stub
    return null;
}