Trino源码解析(一)——源码阅读环境准备

工具准备

  • 操作系统:Mac OS X or Linux
  • JDK版本要求比较高,目前我下载的JDK版本要求最低是21.0.1
  • Maven,但是Maven版本并不重要,因为编译的时候会通过./mvnw来使用脚本里的版本,避免差异化。
  • 最好再准备下Docker环境
  • IDE:idea

本地编译

从github上下载:

bash 复制代码
git clone https://github.com/trinodb/trino.git

导入到idea,进入到项目根目录,执行Maven编译:

bash 复制代码
./mvnw clean install -DskipTests

但是,这样执行会比较慢。同时还会使用 docker (前面有要求环境中安装 docker)。可以使用下面的快速构建命令 1:

bash 复制代码
./mvnw -pl '!:trino-server-rpm,!:trino-docs,!:trino-proxy,!:trino-verifier,!:trino-benchto-benchmarks' clean install -T1C -nsu -DskipTests -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Dair.check.skip-all=true -Dskip.npm -Dskip.yarn

同时,修改下Maven的Config下的配置文件,老配方了:

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<settings
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"
    xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <localRepository>/Users/victorchu/.m2/repository</localRepository>
    <mirrors>
        <mirror>
            <id>aliyunmaven</id>
            <mirrorOf>*,!confluent,!jcenter</mirrorOf>
            <name>阿里云公共仓库</name>
            <url>https://maven.aliyun.com/repository/public</url>
          </mirror>
    </mirrors>
</settings>

同时,在项目根目录的pom.xml上添加 repo 配置,解决阿里云中找不到包的问题,要在mirrorOf中忽略该仓库。

xml 复制代码
<repositories>
  <repository>
    <releases>
      <enabled>true</enabled>
    </releases>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
    <id>confluent</id>
    <url>http://packages.confluent.io/maven/</url>
  </repository>
  <repository>
    <releases>
      <enabled>true</enabled>
    </releases>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
    <id>jcenter</id>
    <url>https://maven.aliyun.com/repository/jcenter</url>
  </repository>
</repositories>

调试

首先启动下服务端。

服务端

Trino附带了开箱即用的示例配置,可以用于开发。

但是要运行需要一些参数:

  • Main Class: io.trino.server.DevelopmentServer
  • VM Options: -ea -Dconfig=etc/config.properties -Dlog.levels-file=etc/log.properties -Djdk.attach.allowAttachSelf=true
  • Working directory: $MODULE_DIR$
  • Use classpath of module: trino-server-dev

工作目录应该是子目录 trino-server-dev, 在 idea 中可以使用 $MODULE_DIR$ 自动定位。

接着run一把,需要等待一些时间,因为Trino服务端会把n多plugins加载进来。

到最后显示这个,就说明服务端启好了。

接下来我们来启动一个客户端。

客户端

主要是在trino-client目录下:

bash 复制代码
cd client/trino-cli/target/ & java -jar trino-cli-*-executable.jar

会显示trino>提示符,输入一些系统表进行查询:

sql 复制代码
SELECT * FROM system.runtime.nodes;

返回结果:

再输入TPCH数据集的查询语句看看:

sql 复制代码
SELECT * FROM tpch.tiny.region;

WebUI

访问 localhost:8080 端口可以看到 webUI, 默认是无用户 (即随意输入 username) 都可以登录。

至此,源码阅读环境搭建完毕。

源码结构

为下面的阅读做铺垫,给出源码结构及说明。

源码结构及说明

python 复制代码
$ tree -d -L 2
.
├── client # 客户端相关模块
│   ├── trino-cli 
│   ├── trino-client
│   └── trino-jdbc # Jdbc方式客户端
├── core  # 服务端核心模块 
│   ├── docker
│   ├── trino-main # 最重要的核心模块
│   ├── trino-parser
│   ├── trino-server # trino.xml中定义打包的所有子模块
│   ├── trino-server-main
│   ├── trino-server-rpm
│   └── trino-spi
├── docs # 文档
├── lib # lib库
│   ├── trino-array
│   ├── trino-collect
│   ├── trino-filesystem
│   ├── trino-geospatial-toolkit
│   ├── trino-hadoop-toolkit
│   ├── trino-hdfs
│   ├── trino-matching
│   ├── trino-memory-context
│   ├── trino-orc
│   ├── trino-parquet
│   ├── trino-phoenix5-patched
│   ├── trino-plugin-toolkit
│   ├── trino-rcfile
│   └── trino-record-decoder
├── plugin # 插件体系
│   ├── trino-accumulo
│   ├── trino-accumulo-iterators
│   ├── trino-atop
│   ├── trino-base-jdbc # Jdbc方式Connector的通用父模块
│   ├── trino-bigquery
│   ├── trino-blackhole
│   ├── trino-cassandra
│   ├── trino-clickhouse
│   ├── trino-delta-lake
│   ├── trino-druid
│   ├── trino-elasticsearch
│   ├── trino-example-http # connector开发的样例模块
│   ├── trino-exchange-filesystem
│   ├── trino-geospatial
│   ├── trino-google-sheets
│   ├── trino-hive
│   ├── trino-hive-hadoop2
│   ├── trino-http-event-listener
│   ├── trino-hudi
│   ├── trino-iceberg
│   ├── trino-jmx
│   ├── trino-kafka
│   ├── trino-kinesis
│   ├── trino-kudu
│   ├── trino-local-file
│   ├── trino-mariadb
│   ├── trino-memory
│   ├── trino-ml
│   ├── trino-mongodb
│   ├── trino-mysql
│   ├── trino-oracle
│   ├── trino-password-authenticators
│   ├── trino-phoenix5
│   ├── trino-pinot
│   ├── trino-postgresql
│   ├── trino-prometheus
│   ├── trino-raptor-legacy
│   ├── trino-redis
│   ├── trino-redshift
│   ├── trino-resource-group-managers
│   ├── trino-session-property-managers
│   ├── trino-singlestore
│   ├── trino-sqlserver
│   ├── trino-teradata-functions
│   ├── trino-thrift
│   ├── trino-thrift-api
│   ├── trino-thrift-testing-server
│   ├── trino-tpcds
│   └── trino-tpch
├── service # 其他服务
│   ├── trino-proxy # 代理服务
│   └── trino-verifier # 验证服务
└── testing # 测试相关模块
    ├── bin
    ├── trino-benchmark
    ├── trino-benchmark-queries
    ├── trino-benchto-benchmarks
    ├── trino-faulttolerant-tests
    ├── trino-plugin-reader
    ├── trino-product-tests
    ├── trino-product-tests-launcher
    ├── trino-server-dev
    ├── trino-testing
    ├── trino-testing-containers
    ├── trino-testing-kafka
    ├── trino-testing-resources
    ├── trino-testing-services
    ├── trino-test-jdbc-compatibility-old-driver
    ├── trino-test-jdbc-compatibility-old-server
    └── trino-tests

Trino安装包及说明

python 复制代码
.
├── bin
│   ├── launcher
│   ├── launcher.properties
│   ├── launcher.py
│   └── procname
├── lib # trino jar lib 库
│   ├── accessors-smart-2.4.7.jar
│   ├── aircompressor-0.21.jar
│   ├── antlr4-runtime-4.11.1.jar
│   ├── aopalliance-1.0.jar
│   ├── asm-9.3.jar
│   ├── asm-analysis-9.2.jar
│   ├── ...
│   └── validation-api-2.0.1.Final.jar
├── NOTICE
├── plugin # 插件目录
│   ├── accumulo # 插件 jar lib
│   ├── atop
│   ├── bigquery
│   ├── ...
│   └── tpch
└── README.txt

多点配置参数

ini 复制代码
# coordinator
node.id=ffffffff-ffff-ffff-ffff-ffffffffffff
coordinator=true
node-scheduler.include-coordinator=false
http-server.http.port=8080
discovery.uri=http:/localhost:8080

# worker
node.id=ffffffff-ffff-ffff-ffff-fffffffffff1
coordinator=false
http-server.http.port=8081
discovery.uri=http:/localhost:8080

远程Debug

如果需要进行远程Debug的话,可以参考下面设置。

ini 复制代码
cd ~/projects/trino/testing/trino-server-dev;
cpath=`echo ~/projects/trino/testing/trino-server-dev/target/dependency/*.jar| tr ' ' ':'`
/home/victorchu/.sdkman/candidates/java/17.0.5-oracle/bin/java -ea -Dconfig=etc/config.properties -Dlog.levels-file=etc/log.properties -Djdk.attach.allowAttachSelf=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 -classpath ~/projects/trino/testing/trino-server-dev/target/trino-server-dev-424.jar:${cpath} io.trino.server.DevelopmentServer;

注意:要在trino-server-devpom.xml中增加如下内容:

xml 复制代码
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>3.6.0</version>
  <executions>
    <execution>
      <id>copy-dependencies</id>
      <goals>
        <goal>copy-dependencies</goal>
      </goals>
      <phase>package</phase>
      <configuration>
        <!-- configure the plugin here -->
      </configuration>
    </execution>
  </executions>
</plugin>
相关推荐
飞瓜智投1 小时前
付费流量如何有效撬动自然流?
大数据·新媒体运营·直播电商
Parallel23331 小时前
Doris相关记录
大数据
Data 3172 小时前
经典sql题(二)求连续登录最多天数用户
大数据·数据库·数据仓库·sql·mysql
青云交3 小时前
大数据新视界 --大数据大厂之Kafka消息队列实战:实现高吞吐量数据传输
大数据·kafka·消息队列·高吞吐量·大数据新视界·技术奥秘·应用场景、新兴技术
成都古河云3 小时前
智慧园区:解析集成运维的未来之路
大数据·运维·人工智能·科技·5g·安全
深科信项目申报助手3 小时前
2024年国家高新申报,警惕被退回的情况
大数据·经验分享·科技·其他
lynn-fish3 小时前
蓝卓标杆客户镇洋发展,荣获IDC中国未来企业大奖
大数据·制造·智能制造·数字化·数字化转型·智能工厂·智能化
Gauss松鼠会3 小时前
GaussDB关键技术原理:高弹性(四)
java·大数据·网络·数据库·分布式·gaussdb
字节跳动数据平台4 小时前
火山引擎数智平台:高性能ChatBI的技术解读和落地实践
大数据·大模型·数据可视化·bi
samFuB5 小时前
【更新】上市公司-供应链金融水平数据(2000-2023年)
大数据·金融