@@ -17,6 +17,7 @@ import TenantsManager, { Tenants } from '../grpc/tenantsManager.js';
1717import { DbVersionSupport , initDbVersionProvider } from '../utils/dbVersion.js' ;
1818
1919import { WeaviateGRPCUnavailableError , WeaviateUnsupportedFeatureError } from '../errors.js' ;
20+ import { Meta } from '../openapi/types.js' ;
2021
2122export interface GrpcConnectionParams extends InternalConnectionParams {
2223 grpcAddress : string ;
@@ -31,40 +32,62 @@ const MAX_GRPC_MESSAGE_LENGTH = 104858000; // 10mb, needs to be synchronized wit
3132// which are tightly coupled to ConnectionGQL
3233export default class ConnectionGRPC extends ConnectionGQL {
3334 private grpc : GrpcClient ;
34- private grpcAddress : string ;
3535
36- private constructor ( params : GrpcConnectionParams ) {
36+ private constructor ( params : GrpcConnectionParams & { grpcMaxMessageLength : number } ) {
3737 super ( params ) ;
3838 this . grpc = grpcClient ( params ) ;
39- this . grpcAddress = params . grpcAddress ;
4039 }
4140
42- static use = async ( params : GrpcConnectionParams ) => {
43- const connection = new ConnectionGRPC ( params ) ;
44- const dbVersionProvider = initDbVersionProvider ( connection ) ;
41+ static use = ( params : GrpcConnectionParams ) => {
42+ const rest = new ConnectionGQL ( params ) ;
43+ const dbVersionProvider = initDbVersionProvider ( rest ) ;
4544 const dbVersionSupport = new DbVersionSupport ( dbVersionProvider ) ;
4645 if ( params . skipInitChecks ) {
47- return { connection, dbVersionProvider, dbVersionSupport } ;
46+ return {
47+ connection : new ConnectionGRPC ( {
48+ ...params ,
49+ grpcMaxMessageLength : MAX_GRPC_MESSAGE_LENGTH ,
50+ } ) ,
51+ dbVersionProvider,
52+ dbVersionSupport,
53+ } ;
4854 }
49- await Promise . all ( [
55+ return Promise . all ( [
56+ ConnectionGRPC . connect (
57+ params ,
58+ ( rest . get ( 'v1/meta' , true ) as Promise < Meta > ) . then (
59+ ( res : Meta ) => res . grpcMaxMessageSize || MAX_GRPC_MESSAGE_LENGTH
60+ )
61+ ) ,
5062 dbVersionSupport . supportsCompatibleGrpcService ( ) . then ( ( check ) => {
5163 if ( ! check . supports ) {
5264 throw new WeaviateUnsupportedFeatureError (
5365 `Checking for gRPC compatibility failed with message: ${ check . message } `
5466 ) ;
5567 }
5668 } ) ,
57- connection . connect ( ) ,
58- ] ) ;
59- return { connection , dbVersionProvider , dbVersionSupport } ;
69+ ] ) . then ( ( [ connection ] ) => {
70+ return { connection , dbVersionProvider , dbVersionSupport } ;
71+ } ) ;
6072 } ;
6173
62- private async connect ( ) {
63- const isHealthy = await this . grpc . health ( ) ;
74+ private static async connect (
75+ params : GrpcConnectionParams ,
76+ grpcMaxLengthPromise : Promise < number >
77+ ) : Promise < ConnectionGRPC > {
78+ const connection = await grpcMaxLengthPromise . then (
79+ ( grpcMaxMessageLength ) =>
80+ new ConnectionGRPC ( {
81+ ...params ,
82+ grpcMaxMessageLength,
83+ } )
84+ ) ;
85+ const isHealthy = await connection . grpc . health ( ) ;
6486 if ( ! isHealthy ) {
65- await this . close ( ) ;
66- throw new WeaviateGRPCUnavailableError ( this . grpcAddress ) ;
87+ await connection . close ( ) ;
88+ throw new WeaviateGRPCUnavailableError ( params . grpcAddress ) ;
6789 }
90+ return connection ;
6891 }
6992
7093 search = ( collection : string , consistencyLevel ?: ConsistencyLevel , tenant ?: string ) => {
@@ -116,10 +139,10 @@ export interface GrpcClient {
116139 tenants : ( collection : string , bearerToken ?: string ) => Tenants ;
117140}
118141
119- export const grpcClient = ( config : GrpcConnectionParams ) : GrpcClient => {
142+ export const grpcClient = ( config : GrpcConnectionParams & { grpcMaxMessageLength : number } ) : GrpcClient => {
120143 const channelOptions : ChannelOptions = {
121- 'grpc.max_send_message_length' : MAX_GRPC_MESSAGE_LENGTH ,
122- 'grpc.max_receive_message_length' : MAX_GRPC_MESSAGE_LENGTH ,
144+ 'grpc.max_send_message_length' : config . grpcMaxMessageLength ,
145+ 'grpc.max_receive_message_length' : config . grpcMaxMessageLength ,
123146 } ;
124147 if ( config . grpcProxyUrl ) {
125148 // grpc.http_proxy is not used by grpc.js under-the-hood
0 commit comments