leveldb-api(1):DB.java
github地址:leveldb/leveldb-api/src/main/java/org/iq80/leveldb at master · dain/leveldb · GitHub
DB.java
DB类接口实现:继承了Closeable接口
public interface DB extends Iterable<Map.Entry<byte[], byte[]>>, Closeable
迭代器DBIterator:用于遍历
DBIterator iterator();
DBIterator iterator(ReadOptions options);
三种方法:put delete write
void put(byte[] key, byte[] value) throws DBException; void delete(byte[] key) throws DBException; void write(WriteBatch updates) throws DBException;
批量写数据:
WriteBatch createWriteBatch();
put操作后返回snapshot:
/** * @return null if options.isSnapshot()==false otherwise returns a snapshot * of the DB after this operation. */ Snapshot put(byte[] key, byte[] value, WriteOptions options) throws DBException;
delete操作后返回snapshot:
/** * @return null if options.isSnapshot()==false otherwise returns a snapshot * of the DB after this operation. */ Snapshot delete(byte[] key, WriteOptions options) throws DBException;
write操作后返回snapshot:
/** * @return null if options.isSnapshot()==false otherwise returns a snapshot * of the DB after this operation. */ Snapshot write(WriteBatch updates, WriteOptions options) throws DBException;
快照:
Snapshot getSnapshot();
getApproximateSize方法可以用于获取一个或多个key range占用的文件系统空间的近似大小:
long[] getApproximateSizes(Range... ranges);
getProperty方法获取系统属性
String getProperty(String name);
suspend 后台compaction:
/** * Suspends any background compaction threads. This methods * returns once the background compactions are suspended. */ void suspendCompactions() throws InterruptedException;
resume后台compaction:
/** * Resumes the background compaction threads. */ void resumeCompactions();
指定compaction的范围:
/** * Force a compaction of the specified key range. * * @param begin if null then compaction start from the first key * @param end if null then compaction ends at the last key */ void compactRange(byte[] begin, byte[] end) throws DBException;
浙公网安备 33010602011771号