本文整理汇总了Java中org.iq80.leveldb.WriteOptions.sync方法的典型用法代码示例。如果您正苦于以下问题:Java WriteOptions.sync方法的具体用法?Java WriteOptions.sync怎么用?Java WriteOptions.sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.iq80.leveldb.WriteOptions
的用法示例。
在下文中一共展示了WriteOptions.sync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkStartTimeInDb
import org.iq80.leveldb.WriteOptions; //导入方法依赖的package包/类
/**
* Checks db for start time and returns it if it exists. If it doesn't
* exist, writes the suggested start time (if it is not null). This is
* only called when the start time is not found in the cache,
* so it adds it back into the cache if it is found. Should only be called
* when a lock has been obtained on the entity.
*/
private StartAndInsertTime checkStartTimeInDb(EntityIdentifier entity,
Long suggestedStartTime) throws IOException {
StartAndInsertTime startAndInsertTime = null;
// create lookup key for start time
byte[] b = createStartTimeLookupKey(entity.getId(), entity.getType());
// retrieve value for key
byte[] v = db.get(b);
if (v == null) {
// start time doesn't exist in db
if (suggestedStartTime == null) {
return null;
}
startAndInsertTime = new StartAndInsertTime(suggestedStartTime,
System.currentTimeMillis());
// write suggested start time
v = new byte[16];
writeReverseOrderedLong(suggestedStartTime, v, 0);
writeReverseOrderedLong(startAndInsertTime.insertTime, v, 8);
WriteOptions writeOptions = new WriteOptions();
writeOptions.sync(true);
db.put(b, v, writeOptions);
} else {
// found start time in db, so ignore suggested start time
startAndInsertTime = new StartAndInsertTime(readReverseOrderedLong(v, 0),
readReverseOrderedLong(v, 8));
}
startTimeWriteCache.put(entity, startAndInsertTime);
startTimeReadCache.put(entity, startAndInsertTime.startTime);
return startAndInsertTime;
}
示例2: deleteSpentTxOutputs
import org.iq80.leveldb.WriteOptions; //导入方法依赖的package包/类
/**
* Deletes spent transaction outputs that are older than the maximum transaction age
*
* @throws BlockStoreException Unable to delete spent transaction outputs
*/
@Override
public void deleteSpentTxOutputs() throws BlockStoreException {
long ageLimit = chainTime - MAX_TX_AGE;
int txPurged = 0;
List<byte[]> purgeList = new LinkedList<>();
synchronized(lock) {
try {
//
// Delete spent transaction outputs
//
log.info("Deleting spent transaction outputs");
try (DBIterator it = dbTxSpent.iterator()) {
it.seekToFirst();
while (it.hasNext()) {
Entry<byte[], byte[]> dbEntry = it.next();
long timeSpent = getLong(dbEntry.getValue());
if (timeSpent < ageLimit) {
purgeList.add(dbEntry.getKey());
txPurged++;
}
}
}
WriteOptions options = new WriteOptions();
options.sync(false);
for (int i=0; i<purgeList.size(); i++) {
dbTxSpent.delete(purgeList.get(i), options);
dbTxOutputs.delete(purgeList.get(i), options);
}
log.info(String.format("%,d spent transaction outputs deleted", txPurged));
} catch (DBException | IOException exc) {
log.error("Unable to remove spent transactions", exc);
throw new BlockStoreException("Unable to remove spent transactions");
}
}
}
示例3: getWriteOptions
import org.iq80.leveldb.WriteOptions; //导入方法依赖的package包/类
public WriteOptions getWriteOptions() {
WriteOptions options = new WriteOptions();
options.sync(sync);
return options;
}