Iterator<byte[]> rows = toDelete.iterator();
byte[] currentRow = rows.next();
byte[] startKey = createStartKey(currentRow);
DB db = getDB();
DBIterator iterator = db.iterator();
WriteBatch batch = db.createWriteBatch();
try {
iterator.seek(startKey);
if (!iterator.hasNext()) {
return; // nothing in the db to delete
}
Map.Entry<byte[], byte[]> entry = iterator.next();
// iterate over the database and the rows to delete, collecting (raw) keys to delete
while (entry != null && currentRow != null) {
KeyValue kv = KeyValue.fromKey(entry.getKey());
int comp = Bytes.compareTo(kv.getRow(), currentRow);
if (comp == 0) {
// same row -> delete
batch.delete(entry.getKey());
entry = iterator.hasNext() ? iterator.next() : null;
} else if (comp > 0) {
// read past current row -> move to next row
currentRow = rows.hasNext() ? rows.next() : null;
} else if (comp < 0) {