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>
相关推荐
只因只因爆15 分钟前
spark小任务
大数据·分布式·spark
cainiao08060522 分钟前
Java 大视界——Java 大数据在智慧交通智能停车诱导系统中的数据融合与实时更新
java·大数据·开发语言
End9283 小时前
Spark之搭建Yarn模式
大数据·分布式·spark
我爱写代码?3 小时前
Spark 集群配置、启动与监控指南
大数据·开发语言·jvm·spark·mapreduce
TDengine (老段)3 小时前
什么是物联网 IoT 平台?
大数据·数据库·物联网·时序数据库·tdengine·涛思数据
青云交4 小时前
Java 大视界 -- 基于 Java 的大数据分布式存储在工业互联网海量设备数据长期存储中的应用优化(248)
java·大数据·工业互联网·分布式存储·冷热数据管理·hbase 优化·kudu 应用
艾醒(AiXing-w)4 小时前
探索大语言模型(LLM):国产大模型DeepSeek vs Qwen,谁才是AI模型的未来?
大数据·人工智能·语言模型
£菜鸟也有梦5 小时前
从0到1上手Kafka:开启分布式消息处理之旅
大数据·kafka·消息队列
Elastic 中国社区官方博客5 小时前
在 Elasticsearch 中删除文档中的某个字段
大数据·数据库·elasticsearch·搜索引擎
时序数据说5 小时前
时序数据库IoTDB分布式系统监控基础概述
大数据·数据库·database·时序数据库·iotdb