* @throws
*/
public synchronized List<RowCollection> removeDoubles() throws IOException, RowSpaceExceededException {
assert this.file.size() == this.index.size() : "file.size() = " + this.file.size() + ", index.size() = " + this.index.size();
final List<RowCollection> report = new ArrayList<RowCollection>();
RowSet rows;
final TreeSet<Long> d = new TreeSet<Long>();
final byte[] b = new byte[this.rowdef.objectsize];
Row.Entry inconsistentEntry;
// iterate over all entries that have inconsistent index references
long lastlog = System.currentTimeMillis();
List<long[]> doubles;
try {
doubles = this.index.removeDoubles();
} catch (final RowSpaceExceededException e) {
if (this.table == null) throw e;
this.table = null;
doubles = this.index.removeDoubles();
}
for (final long[] is: doubles) {
// 'is' is the set of all indexes, that have the same reference
// we collect that entries now here
rows = new RowSet(this.rowdef, is.length);
for (final long L : is) {
assert (int) L < this.file.size() : "L.intValue() = " + (int) L + ", file.size = " + this.file.size(); // prevent ooBounds Exception
d.add(L);
if ((int) L >= this.file.size()) continue; // prevent IndexOutOfBoundsException
this.file.get((int) L, b, 0); // TODO: fix IndexOutOfBoundsException here
inconsistentEntry = this.rowdef.newEntry(b);
try {
rows.addUnique(inconsistentEntry);
} catch (final RowSpaceExceededException e) {
if (this.table == null) throw e;
this.table = null;
rows.addUnique(inconsistentEntry);
}
}
report.add(rows);
}
// finally delete the affected rows, but start with largest id first, otherwise we overwrite wrong entries