infinity timeout bug protection patch

pull/1/head
Michael Peter Christen 12 years ago
parent 1b102d98d8
commit bb4bf3d8fd

@ -235,7 +235,7 @@ public class WeakPriorityBlockingQueue<E> implements Serializable {
*/ */
public Element<E> element(final int position, long time) throws InterruptedException { public Element<E> element(final int position, long time) throws InterruptedException {
if (this.drained == null) return null; if (this.drained == null) return null;
long timeout = System.currentTimeMillis() + time; long timeout = time == Long.MAX_VALUE ? Long.MAX_VALUE : System.currentTimeMillis() + time;
if (position < this.drained.size()) { if (position < this.drained.size()) {
return this.drained.get(position); return this.drained.get(position);
} }

@ -175,7 +175,7 @@ public class Balancer {
// first find a list of url hashes that shall be deleted // first find a list of url hashes that shall be deleted
final HandleSet urlHashes = new RowHandleSet(this.urlFileIndex.row().primaryKeyLength, Base64Order.enhancedCoder, 100); final HandleSet urlHashes = new RowHandleSet(this.urlFileIndex.row().primaryKeyLength, Base64Order.enhancedCoder, 100);
final long terminate = (timeout > 0) ? System.currentTimeMillis() + timeout : Long.MAX_VALUE; final long terminate = timeout == Long.MAX_VALUE ? Long.MAX_VALUE : (timeout > 0) ? System.currentTimeMillis() + timeout : Long.MAX_VALUE;
synchronized (this) { synchronized (this) {
final Iterator<Row.Entry> i = this.urlFileIndex.rows(); final Iterator<Row.Entry> i = this.urlFileIndex.rows();
Row.Entry rowEntry; Row.Entry rowEntry;
@ -351,7 +351,7 @@ public class Balancer {
if (domainList.isEmpty()) return new ArrayList<Request>(0); if (domainList.isEmpty()) return new ArrayList<Request>(0);
maxcount = Math.min(maxcount, domainList.size()); maxcount = Math.min(maxcount, domainList.size());
final ArrayList<Request> cel = new ArrayList<Request>(maxcount); final ArrayList<Request> cel = new ArrayList<Request>(maxcount);
long timeout = System.currentTimeMillis() + maxtime; long timeout = maxtime == Long.MAX_VALUE ? Long.MAX_VALUE : System.currentTimeMillis() + maxtime;
for (int i = 0; i < maxcount; i++) { for (int i = 0; i < maxcount; i++) {
final byte[] urlhash = domainList.getOne(i); final byte[] urlhash = domainList.getOne(i);
if (urlhash == null) continue; if (urlhash == null) continue;

@ -74,7 +74,7 @@ public class WordReferenceFactory implements ReferenceFactory<WordReference>, Se
*/ */
public static final <ReferenceType extends WordReference> ByteBuffer compressIndex(final ReferenceContainer<WordReference> inputContainer, final ReferenceContainer<WordReference> excludeContainer, final long maxtime) { public static final <ReferenceType extends WordReference> ByteBuffer compressIndex(final ReferenceContainer<WordReference> inputContainer, final ReferenceContainer<WordReference> excludeContainer, final long maxtime) {
// collect references according to domains // collect references according to domains
final long timeout = (maxtime < 0) ? Long.MAX_VALUE : System.currentTimeMillis() + maxtime; final long timeout = maxtime == Long.MAX_VALUE ? Long.MAX_VALUE : (maxtime < 0) ? Long.MAX_VALUE : System.currentTimeMillis() + maxtime;
final TreeMap<String, StringBuilder> doms = new TreeMap<String, StringBuilder>(); final TreeMap<String, StringBuilder> doms = new TreeMap<String, StringBuilder>();
synchronized (inputContainer) { synchronized (inputContainer) {
final Iterator<WordReference> i = inputContainer.entries(); final Iterator<WordReference> i = inputContainer.entries();

@ -500,7 +500,7 @@ public class WordReferenceVars extends AbstractReference implements WordReferenc
worker[i] = new TransformWorker(this.out, this.maxtime, this.local); worker[i] = new TransformWorker(this.out, this.maxtime, this.local);
worker[i].start(); worker[i].start();
} }
long timeout = System.currentTimeMillis() + this.maxtime; long timeout = this.maxtime == Long.MAX_VALUE ? Long.MAX_VALUE : System.currentTimeMillis() + this.maxtime;
// fill the queue // fill the queue
int p = this.container.size(); int p = this.container.size();
@ -554,7 +554,7 @@ public class WordReferenceVars extends AbstractReference implements WordReferenc
@Override @Override
public void run() { public void run() {
Row.Entry entry; Row.Entry entry;
long timeout = System.currentTimeMillis() + this.maxtime; long timeout = this.maxtime == Long.MAX_VALUE ? Long.MAX_VALUE : System.currentTimeMillis() + this.maxtime;
try { try {
while ((entry = this.in.take()) != WordReferenceRow.poisonRowEntry) { while ((entry = this.in.take()) != WordReferenceRow.poisonRowEntry) {
this.out.put(new WordReferenceVars(new WordReferenceRow(entry), local)); this.out.put(new WordReferenceVars(new WordReferenceRow(entry), local));

@ -174,7 +174,7 @@ public class Dispatcher {
int refcount = 0; int refcount = 0;
// first select the container // first select the container
final long timeout = (maxtime < 0) ? Long.MAX_VALUE : System.currentTimeMillis() + maxtime; final long timeout = maxtime == Long.MAX_VALUE ? Long.MAX_VALUE : (maxtime < 0) ? Long.MAX_VALUE : System.currentTimeMillis() + maxtime;
while ( while (
(containers.size() < maxContainerCount) && (containers.size() < maxContainerCount) &&
(refcount < maxReferenceCount) && (refcount < maxReferenceCount) &&

@ -487,7 +487,7 @@ public class WebStructureGraph {
final long time) { final long time) {
// we iterate over all structure entries. // we iterate over all structure entries.
// one structure entry has information that a specific host links to a list of other hosts // one structure entry has information that a specific host links to a list of other hosts
final long timeout = System.currentTimeMillis() + time; final long timeout = time == Long.MAX_VALUE ? Long.MAX_VALUE : System.currentTimeMillis() + time;
byte[] term; byte[] term;
HostReference hr; HostReference hr;
WebStructureGraph.StructureEntry sentry; WebStructureGraph.StructureEntry sentry;

@ -479,7 +479,7 @@ public final class SearchEvent {
timer = System.currentTimeMillis(); timer = System.currentTimeMillis();
// apply all constraints // apply all constraints
long timeout = System.currentTimeMillis() + maxtime; long timeout = maxtime == Long.MAX_VALUE ? Long.MAX_VALUE : System.currentTimeMillis() + maxtime;
try { try {
WordReferenceVars iEntry; WordReferenceVars iEntry;
long remaining; long remaining;
@ -1280,7 +1280,7 @@ public final class SearchEvent {
public ResultEntry oneResult(final int item, final long timeout) { public ResultEntry oneResult(final int item, final long timeout) {
// check if we already retrieved this item // check if we already retrieved this item
// (happens if a search pages is accessed a second time) // (happens if a search pages is accessed a second time)
final long finishTime = System.currentTimeMillis() + timeout; final long finishTime = timeout == Long.MAX_VALUE ? Long.MAX_VALUE : System.currentTimeMillis() + timeout;
EventTracker.update(EventTracker.EClass.SEARCH, new ProfilingGraph.EventSearch(this.query.id(true), SearchEventType.ONERESULT, "started, item = " + item + ", available = " + this.getResultCount(), 0, 0), false); EventTracker.update(EventTracker.EClass.SEARCH, new ProfilingGraph.EventSearch(this.query.id(true), SearchEventType.ONERESULT, "started, item = " + item + ", available = " + this.getResultCount(), 0, 0), false);
// wait until a local solr is finished, we must do that to be able to check if we need more // wait until a local solr is finished, we must do that to be able to check if we need more
@ -1325,7 +1325,7 @@ public final class SearchEvent {
} }
public ArrayList<WeakPriorityBlockingQueue.Element<ResultEntry>> completeResults(final long waitingtime) { public ArrayList<WeakPriorityBlockingQueue.Element<ResultEntry>> completeResults(final long waitingtime) {
final long timeout = System.currentTimeMillis() + waitingtime; final long timeout = waitingtime == Long.MAX_VALUE ? Long.MAX_VALUE : System.currentTimeMillis() + waitingtime;
int i = 0; int i = 0;
while (this.resultList.sizeAvailable() < this.query.neededResults() && System.currentTimeMillis() < timeout) { while (this.resultList.sizeAvailable() < this.query.neededResults() && System.currentTimeMillis() < timeout) {
oneResult(i++, timeout - System.currentTimeMillis()); oneResult(i++, timeout - System.currentTimeMillis());
@ -1451,7 +1451,7 @@ public final class SearchEvent {
int c; int c;
float q, min = Float.MAX_VALUE, max = Float.MIN_VALUE; float q, min = Float.MAX_VALUE, max = Float.MIN_VALUE;
int ic = maxcount; int ic = maxcount;
long timeout = System.currentTimeMillis() + maxtime; long timeout = maxtime == Long.MAX_VALUE ? Long.MAX_VALUE : System.currentTimeMillis() + maxtime;
while ( ic-- > 0 && i.hasNext() ) { while ( ic-- > 0 && i.hasNext() ) {
word = i.next(); word = i.next();
if ( word == null ) { if ( word == null ) {

@ -109,7 +109,7 @@ public class ReferenceOrder {
// fill the queue // fill the queue
WordReferenceVars iEntry; WordReferenceVars iEntry;
int p = 0; int p = 0;
long timeout = System.currentTimeMillis() + this.maxtime; long timeout = this.maxtime == Long.MAX_VALUE ? Long.MAX_VALUE : System.currentTimeMillis() + this.maxtime;
try { try {
while ((iEntry = vars.take()) != WordReferenceVars.poison) { while ((iEntry = vars.take()) != WordReferenceVars.poison) {
worker[p % this.threads].add(iEntry); worker[p % this.threads].add(iEntry);
@ -163,7 +163,7 @@ public class ReferenceOrder {
String dom; String dom;
Integer count; Integer count;
final Integer int1 = 1; final Integer int1 = 1;
long timeout = System.currentTimeMillis() + this.maxtime; long timeout = this.maxtime == Long.MAX_VALUE ? Long.MAX_VALUE : System.currentTimeMillis() + this.maxtime;
while ((iEntry = this.decodedEntries.take()) != WordReferenceVars.poison) { while ((iEntry = this.decodedEntries.take()) != WordReferenceVars.poison) {
// find min/max // find min/max
if (ReferenceOrder.this.min == null) ReferenceOrder.this.min = iEntry.clone(); else ReferenceOrder.this.min.min(iEntry); if (ReferenceOrder.this.min == null) ReferenceOrder.this.min = iEntry.clone(); else ReferenceOrder.this.min.min(iEntry);

Loading…
Cancel
Save