1313import com .clickhouse .client .api .data_formats .internal .SerializerUtils ;
1414import com .clickhouse .client .api .enums .ProxyType ;
1515import com .clickhouse .client .api .http .ClickHouseHttpProto ;
16+ import net .jpountz .lz4 .LZ4Factory ;
1617import org .apache .hc .client5 .http .ConnectTimeoutException ;
1718import org .apache .hc .client5 .http .classic .methods .HttpPost ;
1819import org .apache .hc .client5 .http .config .ConnectionConfig ;
@@ -377,7 +378,7 @@ public Exception readError(ClassicHttpResponse httpResponse) {
377378 private static final long POOL_VENT_TIMEOUT = 10000L ;
378379 private AtomicLong timeToPoolVent = new AtomicLong (0 );
379380
380- public ClassicHttpResponse executeRequest (ClickHouseNode server , Map <String , Object > requestConfig ,
381+ public ClassicHttpResponse executeRequest (ClickHouseNode server , Map <String , Object > requestConfig , LZ4Factory lz4Factory ,
381382 IOCallback <OutputStream > writeCallback ) throws IOException {
382383 if (timeToPoolVent .get () < System .currentTimeMillis ()) {
383384 timeToPoolVent .set (System .currentTimeMillis () + POOL_VENT_TIMEOUT );
@@ -406,14 +407,14 @@ public ClassicHttpResponse executeRequest(ClickHouseNode server, Map<String, Obj
406407 req .setConfig (baseRequestConfig );
407408 // setting entity. wrapping if compression is enabled
408409 req .setEntity (wrapRequestEntity (new EntityTemplate (-1 , CONTENT_TYPE , null , writeCallback ),
409- clientCompression , useHttpCompression , appCompressedData ));
410+ clientCompression , useHttpCompression , appCompressedData , lz4Factory ));
410411
411412 HttpClientContext context = HttpClientContext .create ();
412413
413414 try {
414415 ClassicHttpResponse httpResponse = httpClient .executeOpen (null , req , context );
415416 boolean serverCompression = MapUtils .getFlag (requestConfig , chConfiguration , ClientConfigProperties .COMPRESS_SERVER_RESPONSE .getKey ());
416- httpResponse .setEntity (wrapResponseEntity (httpResponse .getEntity (), httpResponse .getCode (), serverCompression , useHttpCompression ));
417+ httpResponse .setEntity (wrapResponseEntity (httpResponse .getEntity (), httpResponse .getCode (), serverCompression , useHttpCompression , lz4Factory ));
417418
418419 if (httpResponse .getCode () == HttpStatus .SC_PROXY_AUTHENTICATION_REQUIRED ) {
419420 throw new ClientMisconfigurationException ("Proxy authentication required. Please check your proxy settings." );
@@ -570,18 +571,18 @@ private void addQueryParams(URIBuilder req, Map<String, String> chConfig, Map<St
570571 }
571572
572573 private HttpEntity wrapRequestEntity (HttpEntity httpEntity , boolean clientCompression , boolean useHttpCompression ,
573- boolean appControlledCompression ) {
574+ boolean appControlledCompression , LZ4Factory lz4Factory ) {
574575 LOG .debug ("client compression: {}, http compression: {}" , clientCompression , useHttpCompression );
575576
576577 if (clientCompression && !appControlledCompression ) {
577578 return new LZ4Entity (httpEntity , useHttpCompression , false , true ,
578- MapUtils .getInt (chConfiguration , "compression.lz4.uncompressed_buffer_size" ), false );
579+ MapUtils .getInt (chConfiguration , "compression.lz4.uncompressed_buffer_size" ), false , lz4Factory );
579580 } else {
580581 return httpEntity ;
581582 }
582583 }
583584
584- private HttpEntity wrapResponseEntity (HttpEntity httpEntity , int httpStatus , boolean serverCompression , boolean useHttpCompression ) {
585+ private HttpEntity wrapResponseEntity (HttpEntity httpEntity , int httpStatus , boolean serverCompression , boolean useHttpCompression , LZ4Factory lz4Factory ) {
585586 LOG .debug ("server compression: {}, http compression: {}" , serverCompression , useHttpCompression );
586587
587588 if (serverCompression ) {
@@ -598,7 +599,7 @@ private HttpEntity wrapResponseEntity(HttpEntity httpEntity, int httpStatus, boo
598599 case HttpStatus .SC_INTERNAL_SERVER_ERROR :
599600 case HttpStatus .SC_NOT_FOUND :
600601 return new LZ4Entity (httpEntity , useHttpCompression , true , false ,
601- MapUtils .getInt (chConfiguration , "compression.lz4.uncompressed_buffer_size" ), true );
602+ MapUtils .getInt (chConfiguration , "compression.lz4.uncompressed_buffer_size" ), true , lz4Factory );
602603 }
603604 }
604605
0 commit comments