-
Notifications
You must be signed in to change notification settings - Fork 615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ISPN-9469 Implement timeout for queries #8382
Closed
gustavocoding
wants to merge
1
commit into
infinispan:master
from
gustavocoding:ISPN-9469_query_timeout
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
query-core/src/main/java/org/infinispan/query/core/impl/TimedCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.infinispan.query.core.impl; | ||
|
||
import java.util.Set; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.BinaryOperator; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collector; | ||
|
||
import org.infinispan.commons.time.DefaultTimeService; | ||
import org.infinispan.commons.time.TimeService; | ||
import org.infinispan.query.SearchTimeoutException; | ||
|
||
/** | ||
* @since 11.0 | ||
*/ | ||
class TimedCollector<U, A, R> implements Collector<U, A, R> { | ||
private final Collector<U, A, R> collector; | ||
private final long timeout; | ||
|
||
private static final TimeService TIME_SERVICE = DefaultTimeService.INSTANCE; | ||
|
||
public TimedCollector(Collector<U, A, R> collector, long timeout) { | ||
this.collector = collector; | ||
this.timeout = timeout; | ||
} | ||
|
||
@Override | ||
public Supplier<A> supplier() { | ||
return collector.supplier(); | ||
} | ||
|
||
@Override | ||
public BiConsumer<A, U> accumulator() { | ||
BiConsumer<A, U> accumulator = collector.accumulator(); | ||
|
||
if (timeout < 0) return accumulator; | ||
|
||
return new BiConsumer<A, U>() { | ||
int index = 0; | ||
long limit = TIME_SERVICE.time() + timeout; | ||
|
||
boolean divBy32(int i) { | ||
return (i & ((1 << 5) - 1)) == 0; | ||
} | ||
|
||
@Override | ||
public void accept(A a, U u) { | ||
if (divBy32(index++) && TIME_SERVICE.isTimeExpired(limit)) { | ||
throw new SearchTimeoutException(); | ||
} | ||
accumulator.accept(a, u); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public BinaryOperator<A> combiner() { | ||
return collector.combiner(); | ||
} | ||
|
||
@Override | ||
public Function<A, R> finisher() { | ||
return collector.finisher(); | ||
} | ||
|
||
@Override | ||
public Set<Characteristics> characteristics() { | ||
return collector.characteristics(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
query-dsl/src/main/java/org/infinispan/query/SearchTimeoutException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.infinispan.query; | ||
|
||
/** | ||
* Thrown when a query timeout occurs. | ||
* | ||
* @since 11.0 | ||
*/ | ||
public class SearchTimeoutException extends RuntimeException { | ||
|
||
public SearchTimeoutException() { | ||
} | ||
|
||
public SearchTimeoutException(String msg) { | ||
super(msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the timeout is detected when collecting. But what if the splitterator blocks indefinitely when trying to fetch next?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will probably timeout after the RpcTimeout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could also set the timeout in the stream itself, but only distributed streams support timeout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed