prevent opening of new files as that could be a cause for the latest

too-many-open-files exception. The old file is just truncated if the
table is cleaned.
pull/1/head
Michael Peter Christen 11 years ago
parent 8b44fcf0f4
commit 56710ecb26

@ -53,6 +53,11 @@ public final class BufferedRecords {
this.buffer = new TreeMap<Long, byte[]>();
}
public synchronized void clear() {
this.efs.clear();
this.buffer.clear();
}
/**
* flush the buffer: this shall be called before any file-based iterations
* on data structures on records are made

@ -117,6 +117,17 @@ public final class Records {
this.buffercount = 0;
}
public void clear() {
try {
this.raf.setLength(0);
int buffersize = Math.max(1, (maxWriteBuffer / recordsize)) * recordsize;
this.buffer = new byte[buffersize];
this.buffercount = 0;
} catch (IOException e) {
ConcurrentLog.logException(e);
}
}
/**
* @param tablefile
* @param recordsize

@ -876,24 +876,7 @@ public class Table implements Index, Iterable<Row.Entry> {
@Override
public synchronized void clear() throws IOException {
final File f = this.file.filename();
this.file.close();
this.file = null;
FileUtils.deletedelete(f);
tableTracker.remove(f.getName());
// make new file
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f);
} catch (final FileNotFoundException e) {
// should not happen
ConcurrentLog.severe("Table", "", e);
}
if (fos != null) try { fos.close(); } catch (final IOException e) {}
this.file = new BufferedRecords(new Records(f, this.rowdef.objectsize), this.buffersize);
this.file.clear();
// initialize index and copy table
this.table = (this.table == null) ? null : new RowSet(this.taildef);
this.index.clear();

Loading…
Cancel
Save