This commit is contained in:
Andrea Cavalli 2021-05-03 02:57:08 +02:00
parent 4aa18fcd60
commit 04df5f4a36

View File

@ -1005,11 +1005,18 @@ public class LLLocalDictionary implements LLDictionary {
.<Void>fromCallable(() -> {
if (!USE_WRITE_BATCHES_IN_SET_RANGE) {
var opts = new ReadOptions(EMPTY_READ_OPTIONS);
ReleasableSlice minBound;
if (range.hasMin()) {
setIterateBound(opts, IterateBound.LOWER, range.getMin().retain());
minBound = setIterateBound(opts, IterateBound.LOWER, range.getMin().retain());
} else {
minBound = emptyReleasableSlice();
}
try {
ReleasableSlice maxBound;
if (range.hasMax()) {
setIterateBound(opts, IterateBound.UPPER, range.getMax().retain());
maxBound = setIterateBound(opts, IterateBound.UPPER, range.getMax().retain());
} else {
maxBound = emptyReleasableSlice();
}
try (RocksIterator it = db.newIterator(cfh, opts)) {
if (!PREFER_SEEK_TO_FIRST && range.hasMin()) {
@ -1021,6 +1028,11 @@ public class LLLocalDictionary implements LLDictionary {
db.delete(cfh, it.key());
it.next();
}
} finally {
maxBound.release();
}
} finally {
minBound.release();
}
} else if (USE_CAPPED_WRITE_BATCH_IN_SET_RANGE) {
try (var batch = new CappedWriteBatch(db,
@ -1146,6 +1158,7 @@ public class LLLocalDictionary implements LLDictionary {
private void deleteSmallRangeWriteBatch(CappedWriteBatch writeBatch, LLRange range)
throws RocksDBException {
try {
var readOpts = getReadOptions(null);
readOpts.setFillCache(false);
ReleasableSlice minBound;
@ -1154,6 +1167,7 @@ public class LLLocalDictionary implements LLDictionary {
} else {
minBound = emptyReleasableSlice();
}
try {
ReleasableSlice maxBound;
if (range.hasMax()) {
maxBound = setIterateBound(readOpts, IterateBound.UPPER, range.getMax().retain());
@ -1171,14 +1185,19 @@ public class LLLocalDictionary implements LLDictionary {
rocksIterator.next();
}
} finally {
minBound.release();
maxBound.release();
}
} finally {
minBound.release();
}
} finally {
range.release();
}
}
private void deleteSmallRangeWriteBatch(WriteBatch writeBatch, LLRange range)
throws RocksDBException {
try {
var readOpts = getReadOptions(null);
readOpts.setFillCache(false);
ReleasableSlice minBound;
@ -1190,6 +1209,7 @@ public class LLLocalDictionary implements LLDictionary {
} else {
minBound = emptyReleasableSlice();
}
try {
ReleasableSlice maxBound;
if (range.hasMax()) {
var arr = LLUtils.toArray(range.getMax());
@ -1210,8 +1230,12 @@ public class LLLocalDictionary implements LLDictionary {
rocksIterator.next();
}
} finally {
minBound.release();
maxBound.release();
}
} finally {
minBound.release();
}
} finally {
range.release();
}
}
@ -1350,6 +1374,7 @@ public class LLLocalDictionary implements LLDictionary {
} else {
minBound = emptyReleasableSlice();
}
try {
ReleasableSlice maxBound;
if (range.hasMax()) {
maxBound = setIterateBound(readOpts, IterateBound.UPPER, range.getMax().retain());
@ -1375,9 +1400,11 @@ public class LLLocalDictionary implements LLDictionary {
return i;
}
} finally {
minBound.release();
maxBound.release();
}
} finally {
minBound.release();
}
})
.onErrorMap(cause -> new IOException("Failed to get size of range "
+ range.toString(), cause))
@ -1397,6 +1424,7 @@ public class LLLocalDictionary implements LLDictionary {
} else {
minBound = emptyReleasableSlice();
}
try {
ReleasableSlice maxBound;
if (range.hasMax()) {
maxBound = setIterateBound(readOpts, IterateBound.UPPER, range.getMax().retain());
@ -1425,9 +1453,11 @@ public class LLLocalDictionary implements LLDictionary {
return null;
}
} finally {
minBound.release();
maxBound.release();
}
} finally {
minBound.release();
}
})
.subscribeOn(dbScheduler)
.doFinally(s -> range.release());
@ -1444,6 +1474,7 @@ public class LLLocalDictionary implements LLDictionary {
} else {
minBound = emptyReleasableSlice();
}
try {
ReleasableSlice maxBound;
if (range.hasMax()) {
maxBound = setIterateBound(readOpts, IterateBound.UPPER, range.getMax().retain());
@ -1464,9 +1495,11 @@ public class LLLocalDictionary implements LLDictionary {
return null;
}
} finally {
minBound.release();
maxBound.release();
}
} finally {
minBound.release();
}
})
.subscribeOn(dbScheduler)
.doFinally(s -> range.release());
@ -1584,6 +1617,7 @@ public class LLLocalDictionary implements LLDictionary {
} else {
minBound = emptyReleasableSlice();
}
try {
ReleasableSlice maxBound;
if (range.hasMax()) {
maxBound = setIterateBound(readOpts, IterateBound.UPPER, range.getMax().retain());
@ -1604,9 +1638,11 @@ public class LLLocalDictionary implements LLDictionary {
dbDelete(cfh, null, key);
return Map.entry(key, value);
} finally {
minBound.release();
maxBound.release();
}
} finally {
minBound.release();
}
})
.onErrorMap(cause -> new IOException("Failed to delete " + range.toString(), cause))
.subscribeOn(dbScheduler)