dremio arrow flight 协议实现——简单说明

dremio是一直在推广arrow flight 的,很早dremio 就已经直接支持了,以下是简单的说明下具体的参考实现

arrow flight 协议实现要求

  • dremio 参考集成

(此图属于客户端的rpc 访问关系)

 

 

 

  • 代码结构

dremio 对于arrow flight 的实现是开发了一个标准的service (dremio 自己定义的一个服务生命周期模式,包含了start,close)
代码位置: services/arrow-flight 实际上dremio 还包含一个实现是在services/sysflight (主要包含系统表信息)

 

 

 


arrow-flight 服务实现的依赖是基于guice 管理的,所以基本都可以看到代码是基于provider 定义的,包含了用户,认证,上下文,配置管理(后续会介绍)
主要代码是DremioFlightService,继承了Service(进行服务管理),核心是start 入口进行服务管理 (直接使用了标准的FlightServer)
DremioFlightService 类图

start 入口核心 (主要是FlightServer的创建)

 
FlightServer.Builder builder = FlightServer.builder()
      .location(location)
      .allocator(allocator)
      .producer(new DremioFlightProducer(location, dremioFlightSessionsManager, userWorkerProvider,
        optionManagerProvider, allocator, runQueryResponseHandlerFactory));
 
    builder.middleware(FlightServerMiddleware.Key.of(FLIGHT_CLIENT_PROPERTIES_MIDDLEWARE),
      new ServerHeaderMiddleware.Factory());
 
    final String authMode = config.getString(DremioConfig.FLIGHT_SERVICE_AUTHENTICATION_MODE);
    if (FLIGHT_LEGACY_AUTH_MODE.equals(authMode)) {
      builder.authHandler(new BasicServerAuthHandler(
        createBasicAuthValidator(userServiceProvider, tokenManagerProvider, dremioFlightSessionsManager)));
      logger.info("Using basic authentication with ServerAuthHandler.");
    } else if (FLIGHT_AUTH2_AUTH_MODE.equals(authMode)) {
      builder.headerAuthenticator(new DremioBearerTokenAuthenticator(userServiceProvider,
        tokenManagerProvider, dremioFlightSessionsManager));
      logger.info("Using bearer token authentication with CallHeaderAuthenticator.");
    } else {
      throw new RuntimeException(authMode
        + " is not a supported authentication mode for the Dremio FlightServer Endpoint.");
    }
 
    if (config.getBoolean(FLIGHT_SSL_ENABLED)) {
      final SSLConfig sslConfig = getSSLConfig(config, new SSLConfigurator(config, FLIGHT_SSL_PREFIX, "flight"));
      addTlsProperties(builder, sslConfig);
    }

此处DremioFlightProducer 是一个核心,参考类图

DremioFlightProducer 的实现,包含了dremio 自己的session 管理,userWorker 管理,option 管理,以及RunQueryResponseHandlerFactory RunQueryResponseHandlerFactory 还是一个比较重要的东西,dremio 使用了一个j接口的默认实现,包含了BackpressureHandlingResponseHandler支持背压策略的以及BasicResponseHandler 基本处理

 
public interface RunQueryResponseHandlerFactory {
  RunQueryResponseHandlerFactory DEFAULT = new RunQueryResponseHandlerFactory() {
  };
 
  default UserResponseHandler getHandler(UserBitShared.ExternalId runExternalId,
                                         UserSession userSession,
                                         Provider<UserWorker> workerProvider,
                                         Provider<OptionManager> optionManagerProvider,
                                         FlightProducer.ServerStreamListener clientListener,
                                         BufferAllocator allocator) {
 
    if (optionManagerProvider.get().getOption(DremioFlightServiceOptions.ENABLE_BACKPRESSURE_HANDLING)) {
      return new BackpressureHandlingResponseHandler(runExternalId, userSession, workerProvider, clientListener,
        allocator);
    } else {
      return new BasicResponseHandler(runExternalId, userSession, workerProvider, clientListener, allocator);
    }
  }
}

说明

以上是关于dremio arrow flight 的简单介绍,后边会从源码以及结合arrow flight分析下dremio 对于arrow flight 的实现
注意:dremio 版本的可能会和apache arrow 官方的有些差异,毕竟dremio 是自己fork 的一个apache arrorw 扩展,而且如果大家
基于maven 集成的话,会发现目前7.0 有一些maven 依赖没有直接发布中央仓库,还需要研究下

参考资料

https://arrow.apache.org/blog/2022/02/16/introducing-arrow-flight-sql/
https://github.com/apache/arrow/blob/master/java/flight/flight-sql/src/main/java/org/apache/arrow/flight/sql/example/FlightSqlClientDemoApp.java

posted on 2022-03-01 11:56  荣锋亮  阅读(445)  评论(0编辑  收藏  举报

导航