orbiter 16 years ago
parent 0c3ab291c4
commit d99ff745aa

@ -58,7 +58,6 @@ public class Balancer {
private final File cacheStacksPath;
private final String stackname;
private boolean top; // to alternate between top and bottom of the file stack
private final boolean fullram;
private long minimumLocalDelta;
private long minimumGlobalDelta;
@ -71,13 +70,13 @@ public class Balancer {
this.domainStacks = new ConcurrentHashMap<String, LinkedList<String>>();
this.urlRAMStack = new ArrayList<String>();
this.top = true;
this.fullram = fullram;
this.minimumLocalDelta = minimumLocalDelta;
this.minimumGlobalDelta = minimumGlobalDelta;
// create a stack for newly entered entries
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)) {
// 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)" ));
@ -130,24 +129,14 @@ public class Balancer {
}
public synchronized void clear() {
try {
urlFileIndex.clear();
} catch (IOException e) {
e.printStackTrace();
}
urlFileStack.clear();
domainStacks.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 {

@ -73,10 +73,12 @@ public class IntegerHandleIndex {
InputStream is = new BufferedInputStream(new FileInputStream(file), 1024 * 1024);
byte[] a = new byte[keylength + 4];
int c;
Row.Entry entry;
while (true) {
c = is.read(a);
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();
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) {
assert (entry != null);
if (entry == null) return;
finishInitialization();
// if the new entry is within the initialization part, just overwrite it
assert index0.isSorted();
@ -122,8 +123,9 @@ public class ObjectIndexCache implements ObjectIndex {
while (i.hasNext()) put(i.next());
}
public synchronized void addUnique(final Row.Entry entry) {
public synchronized void addUnique(final Row.Entry entry) {
assert (entry != null);
if (entry == null) return;
if (index1 == null) {
// we are in the initialization phase
index0.addUnique(entry);

Loading…
Cancel
Save