-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Improved Connection Count server select strategy #15975
Merged
abhishekagarwal87
merged 9 commits into
apache:master
from
sreemanamala:err-cnt-server-select-strategy
Mar 4, 2024
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
058e33e
failure count server select strategy
sreemanamala a7e9502
unit test
sreemanamala d5ea354
updated connection count strategy
sreemanamala df7aaee
cleanup
sreemanamala 1511b63
Unit Test
sreemanamala d5117db
reformat
sreemanamala 8cea408
refactor
sreemanamala 57a68d4
decrement connection count on any exception
sreemanamala b6cef59
minor refactor
sreemanamala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
|
||
package org.apache.druid.client; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.util.concurrent.Futures; | ||
import com.google.common.util.concurrent.ListenableFuture; | ||
|
@@ -27,6 +29,7 @@ | |
import org.apache.druid.client.selector.HighestPriorityTierSelectorStrategy; | ||
import org.apache.druid.client.selector.QueryableDruidServer; | ||
import org.apache.druid.client.selector.ServerSelector; | ||
import org.apache.druid.common.config.NullHandling; | ||
import org.apache.druid.jackson.DefaultObjectMapper; | ||
import org.apache.druid.java.util.common.DateTimes; | ||
import org.apache.druid.java.util.common.Intervals; | ||
|
@@ -97,6 +100,7 @@ public class DirectDruidClientTest | |
@Before | ||
public void setup() | ||
{ | ||
NullHandling.initializeForTests(); | ||
httpClient = EasyMock.createMock(HttpClient.class); | ||
serverSelector = new ServerSelector( | ||
dataSegment, | ||
|
@@ -427,4 +431,47 @@ public void testQueryTimeoutFromFuture() | |
Assert.assertEquals(hostName, actualException.getHost()); | ||
EasyMock.verify(httpClient); | ||
} | ||
|
||
@Test | ||
public void testRuntimeException() throws JsonProcessingException | ||
{ | ||
ObjectMapper mockObjectMapper = EasyMock.createMock(ObjectMapper.class); | ||
EasyMock.expect(mockObjectMapper.writeValueAsBytes(EasyMock.anyObject())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets intercept this call only when an object of type query is being serialized. |
||
.andThrow(new JsonProcessingException("Error") | ||
{ | ||
}); | ||
|
||
DirectDruidClient client2 = new DirectDruidClient( | ||
new ReflectionQueryToolChestWarehouse(), | ||
QueryRunnerTestHelper.NOOP_QUERYWATCHER, | ||
mockObjectMapper, | ||
httpClient, | ||
"http", | ||
hostName, | ||
new NoopServiceEmitter(), | ||
queryCancellationExecutor | ||
); | ||
|
||
QueryableDruidServer queryableDruidServer2 = new QueryableDruidServer( | ||
new DruidServer( | ||
"test1", | ||
"localhost", | ||
null, | ||
0, | ||
ServerType.HISTORICAL, | ||
DruidServer.DEFAULT_TIER, | ||
0 | ||
), | ||
client2 | ||
); | ||
|
||
serverSelector.addServerAndUpdateSegment(queryableDruidServer2, serverSelector.getSegment()); | ||
|
||
TimeBoundaryQuery query = Druids.newTimeBoundaryQueryBuilder().dataSource("test").build(); | ||
query = query.withOverriddenContext(ImmutableMap.of(DirectDruidClient.QUERY_FAIL_TIME, Long.MAX_VALUE)); | ||
|
||
TimeBoundaryQuery finalQuery = query; | ||
Assert.assertThrows(RuntimeException.class, () -> client2.run(QueryPlus.wrap(finalQuery))); | ||
Assert.assertEquals(0, client2.getNumOpenConnections()); | ||
} | ||
} |
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.
This is too generic test name. I would suggest testConnectionCountAfterException