Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b0ca917
Reactor Netty Milestone release changes
kushagraThapar Aug 30, 2019
5b4d442
Updated Milestone version to RC version
kushagraThapar Sep 4, 2019
93d9a91
Code review comments:
kushagraThapar Sep 5, 2019
c474f75
Updated reactor release and reactor netty release
kushagraThapar Sep 30, 2019
d6087c4
Setting default connections to 1000, and fixed Exception handling by …
kushagraThapar Oct 1, 2019
13fb2a0
Merge branch 'master' into reactor_netty_milestone_release
kushagraThapar Oct 1, 2019
fc123c3
Unwrapping exception
kushagraThapar Oct 1, 2019
4d38f26
Merge branch 'master' into reactor_netty_milestone_release
kushagraThapar Oct 1, 2019
3d672fb
Fixed validate failure by unwrapping exception
kushagraThapar Oct 1, 2019
098365b
Merge branch 'master' into reactor_netty_milestone_release
kushagraThapar Oct 2, 2019
d2e2569
Fixed multi-master conflict resolution test
kushagraThapar Oct 2, 2019
a201fea
Unwrapping exceptions wherever possible to make sure we check on inne…
kushagraThapar Oct 2, 2019
f6dfd06
Fixed compilation errors
kushagraThapar Oct 3, 2019
35530b4
Merge branch 'master' into reactor_netty_milestone_release
kushagraThapar Oct 3, 2019
0a3e149
Merge branch 'master' into reactor_netty_milestone_release
kushagraThapar Oct 3, 2019
4e54cc3
Fixed doOnError in Store Client and Consistency Writer to handle unwr…
kushagraThapar Oct 3, 2019
9533896
Handling empty response from backend
kushagraThapar Oct 4, 2019
3ffcb75
Updating number of documents and collection throughput size
kushagraThapar Oct 12, 2019
fcbc679
Updated Feed Response Validator for query metrics
kushagraThapar Oct 12, 2019
e3c0920
Fixed query documents with aggregate test
kushagraThapar Oct 14, 2019
4f01fd2
Updated retrieved documents count
kushagraThapar Oct 14, 2019
7641a2d
Updated getLogicalPlanBuildTime for query metrics validation
kushagraThapar Oct 15, 2019
5973dfe
Unused imports
kushagraThapar Oct 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Configuration {
private int documentDataFieldSize = 20;

@Parameter(names = "-maxConnectionPoolSize", description = "Max Connection Pool Size")
private Integer maxConnectionPoolSize = 1000;
private Integer maxConnectionPoolSize = 500;
Comment thread
kushagraThapar marked this conversation as resolved.

@Parameter(names = "-consistencyLevel", description = "Consistency Level", converter = ConsistencyLevelConverter.class)
private ConsistencyLevel consistencyLevel = ConsistencyLevel.SESSION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class ConnectionPolicy {
private static final int DEFAULT_MEDIA_REQUEST_TIMEOUT_IN_MILLIS = 300 * 1000;
private static final int DEFAULT_IDLE_CONNECTION_TIMEOUT_IN_MILLIS = 60 * 1000;

private static final int DEFAULT_MAX_POOL_SIZE = 1000;
private static final int DEFAULT_MAX_POOL_SIZE = 500;
Comment thread
kushagraThapar marked this conversation as resolved.
Outdated

private static ConnectionPolicy default_policy = null;
private int requestTimeoutInMillis;
Expand All @@ -38,7 +38,7 @@ public final class ConnectionPolicy {
* Constructor.
*/
public ConnectionPolicy() {
this.connectionMode = ConnectionMode.GATEWAY;
this.connectionMode = ConnectionMode.DIRECT;
this.enableReadRequestsFallback = null;
this.idleConnectionTimeoutInMillis = DEFAULT_IDLE_CONNECTION_TIMEOUT_IN_MILLIS;
this.maxPoolSize = DEFAULT_MAX_POOL_SIZE;
Expand All @@ -62,7 +62,7 @@ public static ConnectionPolicy defaultPolicy() {

/**
* Gets the request timeout (time to wait for response from network peer) in
* milliseconds.
* milliseconds.
*
* @return the request timeout in milliseconds.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
Expand All @@ -43,7 +42,6 @@
*/
class RxGatewayStoreModel implements RxStoreModel {

private final static int INITIAL_RESPONSE_BUFFER_SIZE = 1024;
private final Logger logger = LoggerFactory.getLogger(RxGatewayStoreModel.class);
private final Map<String, String> defaultHeaders;
private final HttpClient httpClient;
Expand Down Expand Up @@ -229,22 +227,6 @@ private String ensureSlashPrefixed(String path) {
return "/" + path;
}

private Mono<String> toString(Flux<ByteBuf> contentObservable) {
return contentObservable
.reduce(
new ByteArrayOutputStream(INITIAL_RESPONSE_BUFFER_SIZE),
(out, bb) -> {
try {
bb.readBytes(out, bb.readableBytes());
return out;
}
catch (IOException e) {
throw new RuntimeException(e);
}
})
.map(out -> new String(out.toByteArray(), StandardCharsets.UTF_8));
}

/**
* Transforms the reactor netty's client response Observable to RxDocumentServiceResponse Observable.
*
Expand Down Expand Up @@ -272,11 +254,7 @@ private Flux<RxDocumentServiceResponse> toDocumentServiceResponse(Mono<HttpRespo
// for delete we don't expect any body
inputStreamObservable = Flux.just(IOUtils.toInputStream("", StandardCharsets.UTF_8));
} else {
// transforms the ByteBufFlux to Flux<InputStream>
inputStreamObservable = httpResponse
.body()
.flatMap(byteBuf ->
Flux.just(IOUtils.toInputStream(byteBuf.toString(StandardCharsets.UTF_8), StandardCharsets.UTF_8)));
inputStreamObservable = httpResponse.bodyAsInputStream();
}

return inputStreamObservable
Expand Down Expand Up @@ -315,7 +293,7 @@ private Flux<RxDocumentServiceResponse> toDocumentServiceResponse(Mono<HttpRespo
contentObservable = Flux.just(StringUtils.EMPTY);
} else {
// transforms the ByteBufFlux to Flux<String>
contentObservable = toString(httpResponse.body()).flux();
contentObservable = httpResponse.bodyAsString().flux();
}

return contentObservable
Expand Down Expand Up @@ -498,4 +476,4 @@ private void applySessionToken(RxDocumentServiceRequest request) {
headers.put(HttpConstants.HttpHeaders.SESSION_TOKEN, sessionToken);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ErrorUtils {
private static final Logger logger = LoggerFactory.getLogger(ErrorUtils.class);

static Mono<String> getErrorResponseAsync(HttpResponse responseMessage, HttpRequest request) {
Mono<String> responseAsString = ResponseUtils.toString(responseMessage.body());
Mono<String> responseAsString = responseMessage.bodyAsString();
if (request.httpMethod() == HttpMethod.DELETE) {
return Mono.just(StringUtils.EMPTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static Mono<RxDocumentServiceResponse> parseResponseAsync(Mono<HttpResponse> htt
}

private static Mono<CosmosClientException> createDocumentClientException(HttpResponse httpResponse) {
Mono<String> readStream = ResponseUtils.toString(httpResponse.body());
Mono<String> readStream = httpResponse.bodyAsString();

return readStream.map(body -> {
CosmosError cosmosError = BridgeInternal.createCosmosError(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,11 @@
import com.azure.data.cosmos.internal.http.HttpHeaders;
import com.azure.data.cosmos.internal.http.HttpRequest;
import com.azure.data.cosmos.internal.http.HttpResponse;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.HttpMethod;
import org.apache.commons.lang3.StringUtils;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

class ResponseUtils {
private final static int INITIAL_RESPONSE_BUFFER_SIZE = 1024;

public static Mono<String> toString(Flux<ByteBuf> contentObservable) {
return contentObservable
.reduce(
new ByteArrayOutputStream(INITIAL_RESPONSE_BUFFER_SIZE),
(out, bb) -> {
try {
bb.readBytes(out, bb.readableBytes());
return out;
} catch (IOException e) {
throw new RuntimeException(e);
}
})
.map(out -> new String(out.toByteArray(), StandardCharsets.UTF_8));
}

static Mono<StoreResponse> toStoreResponse(HttpResponse httpClientResponse, HttpRequest httpRequest) {

Expand All @@ -44,7 +22,7 @@ static Mono<StoreResponse> toStoreResponse(HttpResponse httpClientResponse, Http
// for delete we don't expect any body
contentObservable = Mono.just(StringUtils.EMPTY);
} else {
contentObservable = toString(httpClientResponse.body());
contentObservable = httpClientResponse.bodyAsString();
}

return contentObservable.flatMap(content -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

Expand Down Expand Up @@ -53,6 +55,11 @@ public Flux<ByteBuf> body() {
return bodyAsByteArray().flatMapMany(bytes -> Flux.just(Unpooled.wrappedBuffer(bytes)));
}

@Override
public Flux<InputStream> bodyAsInputStream() {
return bodyAsByteArray().flatMapMany(bytes -> Flux.just(new ByteArrayInputStream(bytes)));
Comment thread
kushagraThapar marked this conversation as resolved.
Outdated
}

@Override
public Mono<String> bodyAsString() {
return bodyAsByteArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import reactor.core.publisher.Mono;
import reactor.netty.resources.ConnectionProvider;

import java.time.Duration;

/**
* A generic interface for sending HTTP requests and getting responses.
*/
Expand All @@ -19,7 +21,7 @@ public interface HttpClient {
Mono<HttpResponse> send(HttpRequest request);

/**
* Create fixed HttpClient with {@link HttpClientConfig}
* Create HttpClient with FixedChannelPool {@link HttpClientConfig}
*
* @return the HttpClient
*/
Expand All @@ -28,12 +30,40 @@ static HttpClient createFixed(HttpClientConfig httpClientConfig) {
throw new IllegalArgumentException("HttpClientConfig is null");
}

if (httpClientConfig.getMaxPoolSize() == null) {
return new ReactorNettyClient(ConnectionProvider.fixed(httpClientConfig.getConfigs().getReactorNettyConnectionPoolName()), httpClientConfig);
Integer maxIdleConnectionTimeoutInMillis = 60 * 1000;
Comment thread
kushagraThapar marked this conversation as resolved.
Outdated
if (httpClientConfig.getMaxIdleConnectionTimeoutInMillis() != null) {
maxIdleConnectionTimeoutInMillis = httpClientConfig.getMaxIdleConnectionTimeoutInMillis();
}

// Default pool size
Integer maxPoolSize = 500;
Comment thread
kushagraThapar marked this conversation as resolved.
Outdated
if (httpClientConfig.getMaxPoolSize() != null) {
maxPoolSize = httpClientConfig.getMaxPoolSize();
}
return new ReactorNettyClient(ConnectionProvider.fixed(httpClientConfig.getConfigs().getReactorNettyConnectionPoolName(), httpClientConfig.getMaxPoolSize()), httpClientConfig);

int connectionAcquireTimeoutInMillis = 45 * 1000;
Comment thread
kushagraThapar marked this conversation as resolved.
Outdated

ConnectionProvider fixedConnectionProvider =
ConnectionProvider.fixed(httpClientConfig.getConfigs().getReactorNettyConnectionPoolName(),
maxPoolSize, connectionAcquireTimeoutInMillis, Duration.ofMillis(maxIdleConnectionTimeoutInMillis));

return ReactorNettyClient.createWithConnectionProvider(fixedConnectionProvider, httpClientConfig);
}

/**
* Create HttpClient with un-pooled connection {@link HttpClientConfig}
*
* @return the HttpClient
*/
static HttpClient create(HttpClientConfig httpClientConfig) {
if (httpClientConfig.getConfigs() == null) {
throw new IllegalArgumentException("HttpClientConfig is null");
}

return ReactorNettyClient.create(httpClientConfig);
}


/**
* Shutdown the Http Client and clean up resources
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class HttpClientConfig {
private Integer maxIdleConnectionTimeoutInMillis;
private Integer requestTimeoutInMillis;
private InetSocketAddress proxy;
private boolean connectionKeepAlive = true;

public HttpClientConfig(Configs configs) {
this.configs = configs;
Expand All @@ -43,6 +44,11 @@ public HttpClientConfig withRequestTimeoutInMillis(int requestTimeoutInMillis) {
return this;
}

public HttpClientConfig withConnectionKeepAlive(boolean connectionKeepAlive) {
this.connectionKeepAlive = connectionKeepAlive;
return this;
}

public Configs getConfigs() {
return configs;
}
Expand All @@ -62,4 +68,8 @@ public Integer getRequestTimeoutInMillis() {
public InetSocketAddress getProxy() {
return proxy;
}

public boolean isConnectionKeepAlive() {
return connectionKeepAlive;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import reactor.core.publisher.Mono;
import reactor.netty.Connection;

import java.io.InputStream;
import java.nio.charset.Charset;

/**
Expand Down Expand Up @@ -68,6 +69,13 @@ public abstract class HttpResponse implements AutoCloseable {
*/
public abstract Flux<ByteBuf> body();

/**
* Get the response content as InputStream.
*
* @return this response content as InputStream
*/
public abstract Flux<InputStream> bodyAsInputStream();
Comment thread
kushagraThapar marked this conversation as resolved.
Outdated

/**
* Get the response content as a byte[].
*
Expand Down
Loading