dremio 的InformationSchemaCatalog 服务三

以前简单写过一些关于dremio 的InformationSchemaCatalog ,也说过dremio 为了方便提供标准的INFORMATION_SCHEMA
自己开发了存储扩展,以下是关于存储扩展的创建以及刷新说明

创建

创建是在CatalogService 中处理的,具体的实现是CatalogServiceImpl

  • 参考处理
if(roles.contains(Role.MASTER) || isDistributedCoordinator) {
      final CountDownLatch wasRun = new CountDownLatch(1);
      final String taskName = optionManager.get().getOption(ExecConstants.CATALOG_SERVICE_LOCAL_TASK_LEADER_NAME);
      final Cancellable task = scheduler.get().schedule(Schedule.SingleShotBuilder
        .now()
        .asClusteredSingleton(taskName)
        .inLockStep()
        .build(), () -> {
          try {
           // 创建InfoSchemaConf source,名称为INFORMATION_SCHEMA,这样dremio 也的jdbc 也就能看到INFORMATION_SCHEMA 这个schema了
            if (createSourceIfMissing(new SourceConfig()
              .setConfig(new InfoSchemaConf().toBytesString())
              .setName("INFORMATION_SCHEMA")
              .setType("INFORMATION_SCHEMA")
              .setMetadataPolicy(CatalogService.NEVER_REFRESH_POLICY))) {
              logger.debug("Refreshing 'INFORMATION_SCHEMA' source");
              try {
               // source 信息刷新处理
                refreshSource(new NamespaceKey("INFORMATION_SCHEMA"), CatalogService.NEVER_REFRESH_POLICY, UpdateType.FULL);
              } catch (NamespaceException e) {
                throw new RuntimeException(e);
              }
            }

刷新

对于开发过source 插件的应该了解会有定时任务刷新,实际上以上也说明了,对于元数据不用刷新(因为这个元数据信息是固定的)
更新方式是全量的

  • 参考处理
 public boolean refreshSource(NamespaceKey source, MetadataPolicy metadataPolicy, UpdateType updateType) throws NamespaceException {
  // 通过root 找到插件  
  ManagedStoragePlugin plugin = getPlugins().get(source.getRoot());
    if (plugin == null){
      throw UserException.validationError().message("Unknown source %s", source.getRoot()).build(logger);
    } else if (MissingPluginConf.TYPE.equals(plugin.getConfig().getType())) {
      return false;
    }
   // 使用了ManagedStoragePlugin 提供了refresh 方法
    return plugin.refresh(updateType, metadataPolicy);
  }
 // SourceMetadataManager 的refresh 方法
  boolean refresh(UpdateType updateType, MetadataPolicy policy) throws NamespaceException {
    checkState();
    return metadataManager.refresh(updateType, policy, true);
  }

说明

以上是一个简单的介绍,实际上核心就是INFORMATION_SCHEMA 就是一个dremio 的标准source,里边实现了一些能力,其他source 应该有的一些能力INFORMATION_SCHEMA source 插件也是拥有的,只是少有一些区别,以下链接中包含了一些我以前写的可以参考

参考资料

sabot/kernel/src/main/java/com/dremio/exec/catalog/CatalogServiceImpl.java
sabot/kernel/src/main/java/com/dremio/exec/store/CatalogService.java
sabot/kernel/src/main/java/com/dremio/exec/catalog/SourceMetadataManager.java
sabot/kernel/src/main/java/com/dremio/exec/catalog/ManagedStoragePlugin.java
https://www.cnblogs.com/rongfengliang/p/16486252.html
https://www.cnblogs.com/rongfengliang/p/16488204.html

posted on 2024-02-10 08:00  荣锋亮  阅读(4)  评论(0编辑  收藏  举报

导航