orbiter 16 years ago
parent 0c3ab291c4
commit d99ff745aa

@ -58,7 +58,6 @@ public class Balancer {
private final File cacheStacksPath; private final File cacheStacksPath;
private final String stackname; private final String stackname;
private boolean top; // to alternate between top and bottom of the file stack private boolean top; // to alternate between top and bottom of the file stack
private final boolean fullram;
private long minimumLocalDelta; private long minimumLocalDelta;
private long minimumGlobalDelta; private long minimumGlobalDelta;
@ -71,13 +70,13 @@ public class Balancer {
this.domainStacks = new ConcurrentHashMap<String, LinkedList<String>>(); this.domainStacks = new ConcurrentHashMap<String, LinkedList<String>>();
this.urlRAMStack = new ArrayList<String>(); this.urlRAMStack = new ArrayList<String>();
this.top = true; this.top = true;
this.fullram = fullram;
this.minimumLocalDelta = minimumLocalDelta; this.minimumLocalDelta = minimumLocalDelta;
this.minimumGlobalDelta = minimumGlobalDelta; this.minimumGlobalDelta = minimumGlobalDelta;
// create a stack for newly entered entries // create a stack for newly entered entries
if (!(cachePath.exists())) cachePath.mkdir(); // make the path if (!(cachePath.exists())) cachePath.mkdir(); // make the path
openFileIndex(); cacheStacksPath.mkdirs();
urlFileIndex = new EcoTable(new File(cacheStacksPath, stackname + indexSuffix), CrawlEntry.rowdef, (fullram) ? EcoTable.tailCacheUsageAuto : EcoTable.tailCacheDenyUsage, EcoFSBufferSize, 0);
if (urlFileStack.size() != urlFileIndex.size() || (urlFileIndex.size() < 10000 && urlFileIndex.size() > 0)) { if (urlFileStack.size() != urlFileIndex.size() || (urlFileIndex.size() < 10000 && urlFileIndex.size() > 0)) {
// fix the file stack // fix the file stack
Log.logInfo("Balancer", "re-creating the " + stackname + " balancer stack, size = " + urlFileIndex.size() + ((urlFileStack.size() == urlFileIndex.size()) ? "" : " (the old stack size was wrong)" )); Log.logInfo("Balancer", "re-creating the " + stackname + " balancer stack, size = " + urlFileIndex.size() + ((urlFileStack.size() == urlFileIndex.size()) ? "" : " (the old stack size was wrong)" ));
@ -130,24 +129,14 @@ public class Balancer {
} }
public synchronized void clear() { public synchronized void clear() {
try {
urlFileIndex.clear();
} catch (IOException e) {
e.printStackTrace();
}
urlFileStack.clear(); urlFileStack.clear();
domainStacks.clear(); domainStacks.clear();
urlRAMStack.clear(); urlRAMStack.clear();
resetFileIndex();
}
private void openFileIndex() {
cacheStacksPath.mkdirs();
urlFileIndex = new EcoTable(new File(cacheStacksPath, stackname + indexSuffix), CrawlEntry.rowdef, (fullram) ? EcoTable.tailCacheUsageAuto : EcoTable.tailCacheDenyUsage, EcoFSBufferSize, 0);
}
private void resetFileIndex() {
if (urlFileIndex != null) {
urlFileIndex.close();
urlFileIndex = null;
new File(cacheStacksPath, stackname + indexSuffix).delete();
}
openFileIndex();
} }
public synchronized CrawlEntry get(final String urlhash) throws IOException { public synchronized CrawlEntry get(final String urlhash) throws IOException {

@ -73,10 +73,12 @@ public class IntegerHandleIndex {
InputStream is = new BufferedInputStream(new FileInputStream(file), 1024 * 1024); InputStream is = new BufferedInputStream(new FileInputStream(file), 1024 * 1024);
byte[] a = new byte[keylength + 4]; byte[] a = new byte[keylength + 4];
int c; int c;
Row.Entry entry;
while (true) { while (true) {
c = is.read(a); c = is.read(a);
if (c <= 0) break; if (c <= 0) break;
this.index.addUnique(this.rowdef.newEntry(a)); entry = this.rowdef.newEntry(a); // may be null if a is not well-formed
if (entry != null) this.index.addUnique(entry);
} }
is.close(); is.close();
assert this.index.size() == file.length() / (keylength + 4); assert this.index.size() == file.length() / (keylength + 4);

@ -105,6 +105,7 @@ public class ObjectIndexCache implements ObjectIndex {
public synchronized void put(final Row.Entry entry) { public synchronized void put(final Row.Entry entry) {
assert (entry != null); assert (entry != null);
if (entry == null) return;
finishInitialization(); finishInitialization();
// if the new entry is within the initialization part, just overwrite it // if the new entry is within the initialization part, just overwrite it
assert index0.isSorted(); assert index0.isSorted();
@ -124,6 +125,7 @@ public class ObjectIndexCache implements ObjectIndex {
public synchronized void addUnique(final Row.Entry entry) { public synchronized void addUnique(final Row.Entry entry) {
assert (entry != null); assert (entry != null);
if (entry == null) return;
if (index1 == null) { if (index1 == null) {
// we are in the initialization phase // we are in the initialization phase
index0.addUnique(entry); index0.addUnique(entry);

Loading…
Cancel
Save