Skip to content

Commit 7a61bd0

Browse files
authored
Merge pull request #498 from weaviate/v6-fix-grpc-max-message-size
v6: gRPC max message size
2 parents b4af659 + 504ca92 commit 7a61bd0

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/it/java/io/weaviate/containers/Weaviate.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ public Builder withApiKeys(String... apiKeys) {
197197
return this;
198198
}
199199

200+
public Builder withGrpcMaxMessageSize(int bytes) {
201+
environment.put("GRPC_MAX_MESSAGE_SIZE", String.valueOf(bytes));
202+
return this;
203+
}
204+
200205
public Builder enableTelemetry(boolean enable) {
201206
environment.put("DISABLE_TELEMETRY", Boolean.toString(!enable));
202207
return this;

src/it/java/io/weaviate/integration/SearchITest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.assertj.core.api.InstanceOfAssertFactories;
1414
import org.junit.BeforeClass;
1515
import org.junit.ClassRule;
16+
import org.junit.Ignore;
1617
import org.junit.Test;
1718
import org.junit.rules.TestRule;
1819

@@ -673,4 +674,32 @@ public void testGenerative_bm25_groupBy() throws IOException {
673674
.extracting(TaskOutput::text, InstanceOfAssertFactories.STRING)
674675
.isNotBlank();
675676
}
677+
678+
/**
679+
* Ensure the client respects server's configuration for max gRPC size:
680+
* we create a server with 1-byte message size and try to send a large payload
681+
* there. If the channel is configured correctly, it will refuse to send it.
682+
*/
683+
@Test
684+
@Ignore("Exception thrown by gRPC transport causes a deadlock")
685+
public void test_maxGrpcMessageSize() throws Exception {
686+
var w = Weaviate.custom().withGrpcMaxMessageSize(1).build();
687+
var nsHugeVectors = ns("HugeVectors");
688+
689+
try (final var _client = w.getClient()) {
690+
var huge = _client.collections.create(nsHugeVectors, c -> c
691+
.vectorConfig(VectorConfig.selfProvided()));
692+
693+
final var vector = randomVector(5000, -.01f, .01f);
694+
final WeaviateObject<Map<String, Object>, Reference, ObjectMetadata> hugeObject = WeaviateObject.of(obj -> obj
695+
.metadata(ObjectMetadata.of(m -> m
696+
.vectors(Vectors.of(vector)))));
697+
698+
Assertions.assertThatThrownBy(() -> {
699+
// insertMany to route this request through gRPC.
700+
huge.data.insertMany(hugeObject);
701+
}).isInstanceOf(io.grpc.StatusRuntimeException.class);
702+
}
703+
System.out.println("here?");
704+
}
676705
}

src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public final CompletableFuture<InsertManyResponse> insertMany(PropertiesT... obj
6666
return insertMany(InsertManyRequest.of(objects));
6767
}
6868

69+
@SafeVarargs
70+
public final CompletableFuture<InsertManyResponse> insertMany(
71+
WeaviateObject<PropertiesT, Reference, ObjectMetadata>... objects) {
72+
return insertMany(Arrays.asList(objects));
73+
}
74+
6975
public CompletableFuture<InsertManyResponse> insertMany(
7076
List<WeaviateObject<PropertiesT, Reference, ObjectMetadata>> objects) {
7177
return insertMany(new InsertManyRequest<>(objects));

src/main/java/io/weaviate/client6/v1/internal/grpc/DefaultGrpcTransport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public DefaultGrpcTransport(GrpcChannelOptions transportOptions) {
4343

4444
if (transportOptions.maxMessageSize() != null) {
4545
var max = transportOptions.maxMessageSize();
46-
blockingStub.withMaxInboundMessageSize(max).withMaxOutboundMessageSize(max);
47-
futureStub.withMaxInboundMessageSize(max).withMaxOutboundMessageSize(max);
46+
blockingStub = blockingStub.withMaxInboundMessageSize(max).withMaxOutboundMessageSize(max);
47+
futureStub = futureStub.withMaxInboundMessageSize(max).withMaxOutboundMessageSize(max);
4848
}
4949

5050
if (transportOptions.tokenProvider() != null) {

0 commit comments

Comments
 (0)