├── .gitignore ├── 01_基础概念与全面了解 ├── Presto类型系统浅入.md ├── vx.json ├── vx_images │ ├── 105628459685315.png │ ├── 1059179002819.png │ ├── 1269335877304.png │ ├── 1317497817230.png │ ├── 2091148002886.png │ ├── 226360128042687.png │ ├── 2926684777693.png │ ├── 2957207687416.png │ ├── 343904706519.png │ ├── 3875607524811.png │ ├── 4024148821362.png │ ├── 4137139781556.png │ ├── 41557301535957.png │ ├── 437568052647907.png │ ├── 4397241250861.png │ ├── 447948456408.png │ ├── 46219157909.png │ ├── 4658839148518.png │ ├── 4731341243096.png │ ├── 485282891372733.png │ ├── 5177841138996.png │ ├── 5330414769766.png │ ├── 5800024495611.png │ └── 5971561748547.png ├── 源码分布.md ├── 源码开发与阅读环境搭建.md └── 论文阅读:Presto_SQL_on_Everything.md ├── 02_基础实践 ├── vx.json ├── vx_images │ ├── 133464413615087.png │ ├── 139295961548949.png │ ├── 165333854147997.png │ ├── 208524403522573.png │ ├── 238815728122362.png │ ├── 254164575806893.png │ ├── 255863286002299.png │ ├── 271274925157389.png │ ├── 322355476936706.png │ ├── 355493694777171.png │ ├── 398605714648409.png │ ├── 425302048242576.png │ ├── 45496649751351.png │ ├── 471522511114541.png │ ├── 485012067938534.png │ ├── 515491583356115.png │ ├── 568503556733984.png │ ├── 577266600889242.png │ ├── 63155029575884.png │ └── 63653761654079.png └── 如何配置访问控制.md ├── 03_通信流程 ├── vx.json ├── vx_images │ ├── 1034546555706.png │ ├── 162249199277.png │ ├── 2122828756614.png │ └── 3183894766800.png └── 服务发现-主要流程介绍篇.md ├── 05_内存管理 ├── Presto内存池使用调整.md ├── vx.json └── vx_images │ ├── 125223250132825.png │ ├── 162264749038547.png │ ├── 167824133273668.png │ ├── 201333515098794.png │ ├── 349954958637476.png │ ├── 377375185970357.png │ ├── 473093398985098.png │ ├── 569313700652337.png │ ├── 575212586114716.png │ └── 96253836776405.png ├── 07_插件思想 ├── Connector开发实例 │ ├── Connector开发实例_引.md │ ├── MySQL_Connector │ │ ├── Presto查询Doris问题.md │ │ ├── vx.json │ │ └── vx_images │ │ │ ├── 112696284700215.png │ │ │ ├── 142851698664281.png │ │ │ ├── 28334435254105.png │ │ │ ├── 299964170707723.png │ │ │ ├── 346753032407151.png │ │ │ ├── 450269133345092.png │ │ │ ├── 472563957777770.png │ │ │ ├── 540439154554415.png │ │ │ ├── 588512825411602.png │ │ │ └── 7373226141508.png │ ├── Presto从零开始实现一个Connector_实现流程简述与测试.md │ ├── Presto如何实现查询下推_初探.md │ ├── vx.json │ └── vx_images │ │ ├── 103812835133576.png │ │ ├── 113044116688597.png │ │ ├── 150445588440189.png │ │ ├── 165077840121458.png │ │ ├── 17993029250787.png │ │ ├── 189124992113409.png │ │ ├── 233241964004846.png │ │ ├── 233611925225585.png │ │ ├── 243215420747870.png │ │ ├── 323934992254238.png │ │ ├── 338441007492207.png │ │ ├── 338715229328626.png │ │ ├── 400115072668379.png │ │ ├── 416574004462281.png │ │ ├── 485238248503811.png │ │ ├── 528542034279598.png │ │ ├── 570733136434351.png │ │ ├── 577035145173827.png │ │ ├── 585734692142966.png │ │ └── 63885543587549.png └── vx.json ├── 08_运维与监控 ├── Presto排查Worker宕机问题_缓存与内存问题排查_上.md ├── Presto的Worker为什么会挂掉.md ├── vx.json ├── vx_images │ ├── 103156965946975.png │ ├── 107021056234868.png │ ├── 108107182762118.png │ ├── 108925001924772.png │ ├── 114214185463339.png │ ├── 122008214091069.png │ ├── 123434855955931.png │ ├── 127646103991186.png │ ├── 131613531841143.png │ ├── 132884285437333.png │ ├── 149367346986962.png │ ├── 149647423690409.png │ ├── 162124739907155.png │ ├── 181821876458722.png │ ├── 182562213493958.png │ ├── 204803381711407.png │ ├── 211956587286804.png │ ├── 232686877056302.png │ ├── 233173933066205.png │ ├── 243334853068317.png │ ├── 25258813594877.png │ ├── 266777817527765.png │ ├── 271025808856344.png │ ├── 299226147098254.png │ ├── 331359308530647.png │ ├── 33156198733529.png │ ├── 347412885938973.png │ ├── 347579676878651.png │ ├── 351806920328416.png │ ├── 359324008851148.png │ ├── 360794580221242.png │ ├── 396797673041505.png │ ├── 412992369101981.png │ ├── 417203007575711.png │ ├── 421473603187620.png │ ├── 432332157473058.png │ ├── 446733109044162.png │ ├── 448300047956477.png │ ├── 45993249790558.png │ ├── 464116987726505.png │ ├── 4956932695016.png │ ├── 497221277511829.png │ ├── 521364207707988.png │ ├── 526897444981667.png │ ├── 534043554063705.png │ ├── 577944467481899.png │ ├── 588129864498952.png │ ├── 595751986981801.png │ ├── 599290714988590.png │ ├── 6184102006630.png │ ├── 78021950615480.png │ └── 84806968147010.png ├── 基础监控接口.md ├── 如何发现当前Presto集群的性能瓶颈_IO瓶颈.md ├── 如何发现当前Presto集群的性能瓶颈_初探.md ├── 对接Prometheus生态.md └── 执行计划Stage颜色介绍.md ├── 10_问题总结 ├── Presto中文问题.md ├── Presto单元测试错误NoClassDefFoundError_QueryAnalyzer_引发的版本使用思考.md ├── Presto格式错误造成的分区问题.md ├── hive元数据连接超时.md ├── jdbc错误.md ├── mongodb连接异常MongoTimeoutException.md ├── vx.json ├── vx_images │ ├── 107263619547778.png │ ├── 1078300593177.png │ ├── 115512475986257.png │ ├── 1215551671874.png │ ├── 14549361614771.png │ ├── 146363469472.png │ ├── 148752363847808.png │ ├── 160963098844181.png │ ├── 1800144444812.png │ ├── 191142718090892.png │ ├── 191177125652406.png │ ├── 19577298602209.png │ ├── 2005299574600.png │ ├── 203137896913893.png │ ├── 2045562163097.png │ ├── 214481170862.png │ ├── 2196298922820.png │ ├── 223964892608728.png │ ├── 225804850777017.png │ ├── 244771758758785.png │ ├── 246882090600868.png │ ├── 2566103443096.png │ ├── 257604956063267.png │ ├── 262958444662955.png │ ├── 285775110754955.png │ ├── 291885947698598.png │ ├── 301638517892509.png │ ├── 3033819718538.png │ ├── 305716597429480.png │ ├── 3204584276638.png │ ├── 322604660699775.png │ ├── 327754023446618.png │ ├── 332297616282127.png │ ├── 3335472797305.png │ ├── 3349053077910.png │ ├── 339875002621059.png │ ├── 343346196443217.png │ ├── 352834390551619.png │ ├── 355356834802337.png │ ├── 35842945923969.png │ ├── 362755068519.png │ ├── 363187092916256.png │ ├── 36536341488404.png │ ├── 369126348320646.png │ ├── 3705692654505.png │ ├── 39516826390430.png │ ├── 422414765160088.png │ ├── 427880250882555.png │ ├── 428523785782088.png │ ├── 436624884811282.png │ ├── 4384372556512.png │ ├── 4395812035064.png │ ├── 443322569735556.png │ ├── 4492481668548.png │ ├── 454212582145133.png │ ├── 459560430293491.png │ ├── 463896361320.png │ ├── 478280093084983.png │ ├── 483733314612566.png │ ├── 494364772493207.png │ ├── 4965414017353.png │ ├── 497897334675262.png │ ├── 4998514568932.png │ ├── 503626100864430.png │ ├── 503742361791927.png │ ├── 5071939567072.png │ ├── 513823458707232.png │ ├── 515567381056820.png │ ├── 523448288271116.png │ ├── 537397430428683.png │ ├── 540757777357895.png │ ├── 541762556517475.png │ ├── 5545322874819.png │ ├── 557284614693796.png │ ├── 561473734062577.png │ ├── 561675572246622.png │ ├── 567996697694.png │ ├── 58245429538637.png │ ├── 585550282763108.png │ ├── 587220763239901.png │ ├── 594527359238562.png │ ├── 597193917531306.png │ ├── 63053974823146.png │ ├── 69182329661.png │ ├── 72005586214681.png │ ├── 75323991899565.png │ ├── 76116832182834.png │ ├── 838803859055.png │ ├── 93255085597983.png │ ├── 96412428061650.png │ ├── 98241323900472.png │ └── 98447957403437.png ├── where子句中在对char类型进行判断时需要手动补齐空格.md ├── worker资源问题.md ├── 时区问题.md ├── 最大查询内存问题.md ├── 调试代码的超时限制.md └── 资源文件加载错误.md ├── 11_性能优化 ├── vx.json └── 缓存 │ ├── Presto元数据缓存解析.md │ ├── vx.json │ └── vx_images │ ├── 100939754061905.png │ ├── 17954520582677.png │ ├── 212100674524636.png │ ├── 297740417912970.png │ ├── 325815305841061.png │ ├── 336684490332220.png │ ├── 366423190978457.png │ ├── 392895254306009.png │ ├── 434936491765866.png │ ├── 478543642802921.png │ ├── 520234001625595.png │ ├── 576649737314553.png │ └── 58955495676124.png ├── 12_二次开发 ├── vx.json ├── vx_images │ ├── 488675907516955.png │ ├── 502266107324545.png │ └── 52748047793528.png └── 二次开发工程体系介绍.md ├── README.md ├── vx.json ├── vx_notebook ├── notebook.db └── vx_notebook.json └── 注意事项.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.log 3 | _v_recycle_bin 4 | *.vswp 5 | *.swp 6 | *.DS_Store 7 | *.~vsd 8 | vx_recycle_bin 9 | -------------------------------------------------------------------------------- /01_基础概念与全面了解/Presto类型系统浅入.md: -------------------------------------------------------------------------------- 1 | # Presto类型系统浅入 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | ## 类型分类 8 | 9 | 这里我们可以先了解一下[Presto类型系统初探](https://zhuanlan.zhihu.com/p/55299409)中的类型分布。 10 | 11 | > 下面的关系图已经过时,不过现在大体的设计还是遵循了这个路线,不影响我们学习。 12 | 13 | ![](vx_images/226360128042687.png) 14 | 15 | ### 基本类型 16 | 17 | * BooleanType:表示布尔值,通常用于条件和逻辑运算。 18 | * IntegerType:表示整数值,对应于 Java 的 `int`。 19 | * BigintType:表示更大范围的整数,对应于 Java 的 `long`。 20 | * SmallintType:表示较小范围的整数,对应于 Java 的 `short`。 21 | * TinyintType:表示最小范围的整数,通常用于节省空间的场景。 22 | * DoubleType:表示双精度浮点数,对应于 Java 的 `double`。 23 | * RealType:表示单精度浮点数,对应于 Java 的 `float`。 24 | 25 | ### 字符串和二进制类型 26 | 27 | * VarcharType:表示可变长度的字符串。 28 | * CharType:表示固定长度的字符串。 29 | * VarbinaryType:用于存储二进制数据,类似于 Java 的 `byte[]`。 30 | 31 | ### 日期和时间类型 32 | 33 | * DateType:表示日期。 34 | * TimeType:表示时间。 35 | * TimestampType:表示时间戳,即日期和时间的组合。 36 | * TimestampWithTimeZoneType:表示带有时区信息的时间戳。 37 | 38 | ### 复杂类型 39 | 40 | * ArrayType:表示数组类型,可以包含一系列同类型的元素。 41 | * MapType:表示映射类型,包含键值对。 42 | * RowType:表示结构体或行类型,可以包含多个不同类型的字段。 43 | 44 | ### 特殊类型 45 | 46 | * JsonType:用于处理 JSON 数据。 47 | * IPaddressType:专门用于存储 IP 地址。 48 | * UUIDType:用于处理 UUID。 49 | 50 | ## 其他关键概念 Slice Block Type 51 | 52 | 在开始学习这些类型前,我们需要知道 Presto 一些特殊的设计,以及他们之间的关系。 53 | 54 | ### 底层类型 Slice 55 | 56 | Slice 是 Presto 自定义的一种数据结构,主要用于高效的处理二进制数据或原始字节序列。它是 Presto 中处理字符串、二进制数据和其他原始字节序列的关键组件。 57 | 58 | 片面的理解,可以认为在 Presto 中处理字符串类型时,一般会用到 Slice。 59 | 60 | 但是为什么要搞一个 Slice 类型呢?深入一点的理解,主要区别如下: 61 | 62 | Slice 是一个更底层的数据结构,用于字节级操作,而 Type 类型是更高层次的抽象,代表 SQL 数据类型及其在 Presto 中的行为。在某些 Type 类型的内部实现中,如 VarcharType,Slice 被用作存储实际数据的底层机制。但是 Type 类型还包括了与该数据类型相关的其他逻辑和操作,如数据比较、哈希计算等。 63 | 64 | 65 | ### 数据的载体 Block 66 | 67 | 我们知道 Presto 是一个 OLAP 引擎,是可以对数据进行列式操作的,这里引用以下某本书里的一张图片。 68 | 69 | Page 是 Presto 中处理的最小数据单元。一个 Page 对象包含多个 Block 对象,而每个 Block 对象是一个字节数组,存储一个字段的若干行。多个 Block 横切的一行是真实的一行数据。 70 | 71 | ![](vx_images/485282891372733.png) 72 | 73 | 74 | Block 可以按照另一种更高一层的数据抽象来理解,里面同样有获取数据、数据大小和结构、数据状态,为了我们方便构建数据,还定义了一个 BlockBuilder。 75 | 76 | 注意,这里有一个接口叫 UncheckedBlock 是 Block 的一个变体,提供了一些无边界检查的数据访问方法。这意味着这些方法不会检查索引的有效性,因此它们比标准的 Block 方法更快,但使用时需要更小心。 77 | 78 | 这里有个疑问,为什么要设计 Block 呢? 79 | 80 | 1. 第一点,这个我们都知道,为了方便列式操作 81 | 2. 第二点,是方便内存管理,通过 Block 和 BlockBuilder,Presto 能够有效地管理内存,特别是在处理大量数据时。 82 | 3. 第三点,是性能优化,Block 结构允许 Presto 对数据访问和处理进行优化,特别是通过 UncheckedBlock 提供了一种更快的数据访问方式 83 | 84 | 注意,这里介绍的 Block 与 UncheckedBlock,可以理解为基础接口,还有其他类型比如 Array、Map、Row 等等与类型对应的 Block,这块我们在介绍了类型之后再来介绍它们。 85 | 86 | ![](vx_images/437568052647907.png) 87 | 88 | ### Slice 与 Block 的关系 89 | 90 | 可能我这个词语不太对,我是这么理解的,Slice 是类型,Block 是载体。 91 | 92 | 比如 Block 中,可能有 int,bool,以及 slice 等类型的数据,再比如一个 Block 可能包含多个字符串数据,这些字符串数据是以 Slice 的形式存储的。 93 | 94 | ### Type 与 Block 的关系 95 | 96 | 在 Presto 中,Block 和各种 Type(如 IntegerType、VarcharType、JsonType 等)之间的关系是数据存储和表示的核心。这些 Type 和 Block 结构共同构成了 Presto 处理数据的基础。 97 | 98 | 简单的理解就是,Type 代表数据类型,Block 代表如何存储、访问以及处理数据。 99 | 100 | ## Presto 为什么要重新定义一套类型 101 | 102 | 首先,Java 原生数据类型在 SQL 建模场景下存在功能限制。这主要体现在以下几个方面: 103 | 104 | SQL 类型系统对数值范围和精度有严格要求。例如 DECIMAL 类型需要支持高精度的定点数运算,这超出了 Java 原生类型的表达能力。同样,SQL 中的时间日期类型(如 `DATE`、`TIME`、`TIMESTAMP`)以及 NULL 值的语义处理,都与 Java 原生类型有明显差异。直接使用 Java 类型难以满足 SQL 标准规范,因此需要专门设计封装。 105 | 106 | 其次,SQL 系统需要丰富的元数据(metadata)支持。Presto 通过元数据定义了类型的多种属性和操作语义,包括排序性(sortable)、可比较性(comparable)、边界性(bounded)等特性。这些语义属性需要在类型系统层面进行统一管理。 107 | 108 | 第三,作为 OLAP 引擎,Presto 采用列式存储架构,通过 Block 结构组织数据。自定义类型系统可以更好地适配 Block 的数据访问模式,提升查询性能。 109 | 110 | 基于以上考虑,Presto 实现了完整的类型系统架构。其核心是 `Type` 接口,该接口定义了类型系统的基础语义和操作规范。下面我们将详细分析这个接口的设计思想。 111 | 112 | ## Type 接口 113 | 114 | 接下来开始正经介绍: 115 | 116 | Presto 的类型基本都基于这个接口,在这个接口中设计了很多重要的方法。 117 | 118 | 源码位置: com.facebook.presto.common.type.Type 119 | 120 | ### 类型识别 121 | 122 | 以下这 2 个方法主要实现一个是对 Presto 系统自身逻辑使用所需的类型识别,另一个则是对外比如写 SQL 时,显示的 Varchar,Boolean 等等。 123 | 124 | - `getTypeSignature()` 方法:获取类型名称,不区分大小写,全局唯一,通常叫内部签名。 125 | 126 | 1. 类型的唯一标识:返回一个 `TypeSignature` 对象,这个对象代表了类型的唯一标识。在 Presto 中都用这个标识来进行操作。 127 | 2. 类型系统的内部工作:这个签名用于 Presto 的类型系统内部,如类型推断、类型匹配和函数重载解析等。 128 | 3. 杂类型的支持:Presto 支持复杂的数据类型,如结构体、地图和数组。`getTypeSignature()` 方法允许这些复杂类型以结构化的方式表示,包括其参数和嵌套类型。 129 | 130 | - `getDisplayName()` 方法:最终显示的名称,也就是最终用户看到的。 131 | 132 | 1. 用户友好的类型名称:提供了一个更易于理解和阅读的类型名称,主要是方便用户理解。 133 | 2. SQL 标准和兼容性:在 SQL 查询和结果中,显示的类型名称通常遵循 SQL 标准或者是用户更熟悉的格式。例如,尽管内部可能使用不同的表示方法,但对于用户来说,整数类型可能仅显示为 int,以及我们常见的 Varchar Timestamp等等。 134 | 3. 区分相似类型:在某些情况下,不同的内部类型可能对用户来说是相同的。`getDisplayName()` 允许这些类型有区分性的展示,即使它们的内部表示可能不同。 135 | 136 | ### Java 类型映射 137 | 138 | 主要是提供了一种 Presto 数据类型映射到 Java 类型的机制。 139 | 140 | - `getJavaType()` 141 | 142 | 1. 内部表示:Presto 需要在内部处理各种数据类型,如整数、浮点数、字符串等。`getJavaType()` 方法指定了在 Java 中执行表达式时,这些 Presto 数据类型应该如何在内存中表示。例如,Presto 中的整数可能在 Java 中表示为 `long` 类型,而字符串可能表示为 `Slice` 类型。 143 | 2. 性能优化:Presto 是一个高性能的分布式 SQL 查询引擎,因此在内部处理数据时需要高效地管理内存和计算。通过将 Presto 类型映射到合适的 Java 类型,可以优化数据处理的性能,例如,使用原生类型(如 `int`, `long`, `double`)可以减少对象创建的开销,提高处理速度。 144 | 3. 类型安全:Java 是一种静态类型语言,这意味着在编译时就确定了变量的类型。`getJavaType()` 方法允许 Presto 在编译时期就确保类型的正确性,从而减少运行时的类型错误。 145 | 4. 与 Java 生态系统的集成:Presto 需要与 Java 生态系统中的其他库和工具集成。通过明确指定每个 Presto 类型在 Java 中的表示,可以更容易地与 Java 代码和库交互。 146 | 5. 通用性和扩展性:这种映射机制使得 Presto 能够支持多种数据类型,并且可以轻松地扩展以支持新的数据类型。开发者可以为新的数据类型定义 Java 表示,从而扩展 Presto 的功能。 147 | 148 | 149 | ### 类型参数 150 | 151 | 在 Java 和许多其他编程语言中,参数化类型是一种允许在定义类、接口或方法时指定一个或多个类型参数的机制。这种机制在 Java 中通常与泛型(Generics)相关联。参数化类型使得代码可以对不同的数据类型进行操作,同时保持类型安全和可重用性。 152 | 153 | - `getTypeParameters()` 返回类型参数的列表。主要是用于处理一些复杂类型。 154 | 155 | 1. 支持复杂类型:Presto 支持多种复杂的数据类型,如数组、地图和结构体。这些类型通常是参数化的,意味着它们基于其他类型构建。例如,一个数组类型可能是基于整数类型的数组,或者是基于字符串类型的数组。 156 | 2. 类型的灵活性:`getTypeParameters()` 允许 Presto 灵活地处理这些复杂类型。通过知道一个类型的参数,Presto 可以正确地处理和操作这些类型的数据。 157 | 3. 代码的泛化和重用:在 Presto 的内部实现中,参数化类型的支持允许代码更加泛化和可重用。例如,相同的逻辑可以用来处理不同类型的数组或地图,而无需为每种数据类型编写特定的代码。 158 | 159 | 举例说明: 160 | 161 | 假设有一个数组类型 `ArrayType(IntegerType)`,这表示一个整数数组。在这里,IntegerType 是 ArrayType 的类型参数。 162 | 163 | 一般获取类型的参数列表主要用于以下几个场景 164 | 165 | 1.类型检查和转换:在执行查询时,Presto 需要确保数据类型的正确性。例如,当处理数组或地图类型时,Presto 需要知道其元素或键值的类型。 166 | 2.函数和操作符的重载解析:在 SQL 查询中使用函数或操作符时,Presto 需要根据参数类型来解析和选择正确的函数实现。 167 | 3.序列化和反序列化:在数据交换和存储过程中,了解复杂类型的具体参数有助于正确地序列化和反序列化数据。 168 | 169 | ### 块 Block 构建器 170 | 171 | 块 Block 是 Presto 处理和存储数据的基本机制之一。 172 | 173 | 简单介绍一下块 `Block` 的概念:`Page` 是 Presto 中处理的最小数据单元。一个 `Page` 对象包含多个 `Block` 对象,而每个 `Block` 对象是一个字节数组,存储一个字段的若干行。多个 `Block` 横切的一行则对应一行实际的数据。 174 | 175 | - `createBlockBuilder(BlockBuilderStatus blockBuilderStatus, int expectedEntries, int expectedBytesPerEntry)` 方法用于创建此类型的首选块构建器,这是用于在查询中存储表达式投影后的值的构建器。 176 | 177 | 该方法有重载,区别在于是否含有 `expectedBytesPerEntry` 参数。重载的目的在于应对那些不需要精确控制每个条目字节大小的场景。 178 | 179 | 参数解释: 180 | 181 | 1. BlockBuilderStatus 提供当前 builder 的状态信息 182 | 2. expectedEntries 预期的条目数 183 | 3. expectedBytesPerEntry 预提条目的字节数,主要方便进行预先分配足够的内存空间 184 | 185 | 186 | ### 值获取和写入和无边界操作 187 | 188 | 从块 Block 中获取值,和写入值。 189 | 190 | 获取值: 191 | 192 | - `getObjectValue(SqlFunctionProperties properties, Block block, int position)`,从 Block 中指定的位置 Position 获取值,这个方法主要是将原始数据转换为 Java 对象,就是说无论什么类型,都会转换成一个 Java 可以处理的对象。 193 | 194 | 同时这个方法还有个很关键的点,就是返回的对象必须是 JSON 可序列化的,同时也方便用于将数据转换为可以通过 REST API 等方式传输的格式。 195 | 196 | - `boolean getBoolean(Block block, int position)`,有无边界获取 197 | - `long getLong(Block block, int position)`,有无边界获取 198 | - `double getDouble(Block block, int position)`,有无边界获取 199 | - `Slice getSlice(Block block, int position)`,有无边界获取 200 | - `Object getObject(Block block, int position)`, 有无边界获取 201 | 202 | 写入值: 203 | 204 | - `void writeBoolean(BlockBuilder blockBuilder, boolean value)` 205 | - `void writeLong(BlockBuilder blockBuilder, long value)` 206 | - `void writeDouble(BlockBuilder blockBuilder, double value)` 207 | - `void writeSlice(BlockBuilder blockBuilder, Slice value)` 208 | - `void writeObject(BlockBuilder blockBuilder, Object value)`,有重载,区别在于 slice 的 offset 与 length 209 | 210 | 这里有个关键的概念的 `无边界的操作`,比如 `getBoolean` 有个对应的 `getBooleanUnchecked`,主要目的是不进行边界检查的情况下,操作 Block 中的值。那么为什么要设计这个无边界的操作呢?根据相关资料了解,主要是出于性能优化的考虑,这种设计允许在特定情况下提高数据处理的效率。 211 | 212 | 因为有边界的检查方法中,会有各种边界检查,比如防止数组越界等错误等等,这些检查可以提高代码的健壮性和安全性,同时也会有性能衰减。所以设计了无边界的操作,这些是为了在一些特定场景中,性能敏感的地方使用。 213 | 214 | 这里举个简单的例子,比如已经确定数据在 Block 的有效范围内了。可以使用 getDoubleUnchecked 来加速获取值。 215 | 216 | ```java 217 | // 假设已知 startIndex 和 endIndex 在 block 的有效范围内 218 | for (int position = startIndex; position < endIndex; position++) { 219 | double value =*Type.getDoubleUnchecked(block, position); 220 | // 对 value 进行一些计算或操作 221 | } 222 | ``` 223 | 224 | ### 可比较性和可排序性 225 | 226 | 类型的操作性,比如我们在写 SQL 时, WHERE 子句中字段比较等操作,ORDER BY 子句等等操作。 227 | 228 | - `boolean isComparable()` 可比较 229 | - `boolean isOrderable()` 可排序 230 | 231 | 注意这 2 个方法,的返回值是 boolean,所以这里只是代表类型是否具备可比较和可排序,具体的比较逻辑可以按照 Java 在设计一个实体类一样,Presto 中也是去实现 `equalTo` 和 `hash` 方法来实现比较的功能。 232 | 233 | 同时实现 `compareTo` 方法,来实现排序的功能。 234 | 235 | 236 | ### 值比较、哈希、追加 237 | 238 | 根据前面的可排序,可比较介绍,这里我们就可以按照设计一个 Java 实体来理解了。 239 | 240 | - `equalTo()` 比较块中的值 241 | - `hash()` 计算哈希 242 | - `appendTo()` 将值追加到块构建器中 243 | 244 | ### Type 扩展:定长和变长接口 245 | 246 | #### FixedWidthType 247 | 248 | 接口用于那些在内存中占用固定字节大小的数据类型。这意味着每个数据元素的大小是恒定的,不会根据实际值的不同而改变。 249 | 250 | * 特点: 251 | * 内存效率:由于大小固定,这些类型的数据可以更高效地在内存中存储和访问。 252 | * 应用场景:典型的固定宽度类型包括整数(如 `INTEGER`, `BIGINT`)、浮点数(如 `DOUBLE`, `REAL`)和日期时间类型(如 `DATE`, `TIMESTAMP`)。 253 | 254 | 1. getFixedSize** 255 | 256 | * 功能:获取此类型的值的固定大小(以字节为单位)。对于实现 `FixedWidthType` 的所有类型,其值的大小是恒定的。 257 | * 返回值:返回一个整数,表示类型值的固定字节大小。 258 | 2. createFixedSizeBlockBuilder** 259 | 260 | * 功能:创建一个 `BlockBuilder`,用于构建此类型的数据块。这个 `BlockBuilder` 被初始化为能够容纳指定数量的位置(`positionCount`),每个位置的大小是固定的。 261 | * 参数:`positionCount` - 预期要存储的元素数量。 262 | * 返回值:返回一个 `BlockBuilder` 实例,用于构建和存储此类型的数据。 263 | 264 | 265 | `getFixedSize` 方法允许 Presto 精确地知道每个元素占用多少内存,这对于内存管理和性能优化非常重要。而 `createFixedSizeBlockBuilder` 方法则提供了一种高效创建和管理固定大小数据的方式。这些特性使得 `FixedWidthType` 在处理如整数、浮点数等固定大小数据时非常高效。 266 | 267 | #### VariableWidthType 268 | 269 | 接口用于那些在内存中占用可变字节大小的数据类型。这些类型的数据元素根据实际值的不同,占用的字节大小也不同。 270 | 271 | * 特点: 272 | * 灵活性:可以根据数据的实际内容动态调整所占用的空间。 273 | * 应用场景:典型的可变宽度类型包括字符串(如 `VARCHAR`)和二进制数据(如 `VARBINARY`)。 274 | 275 | #### 设计理解 276 | 277 | 我们在源码中是可以看到 FixedWidthType 和 VariableWidthType 都 extends Type。 278 | 279 | 思考一下,为什么要这样设计呢?为什么不都统一在 Type 接口里设计好呢? 280 | 281 | 我们知道,定长类型与变长类型有些处理逻辑是相悖的,这是一种面向对象设计的 `契约` 概念。 282 | 283 | * 首先肯定是避免实现类必须实现它们不需要的方法 284 | * 方便了以后定长类型与变长类型的扩展 285 | * VariableWidthType和FixedWidthType代表了两种不同的"契约" 286 | * 实现FixedWidthType的类型承诺:我的每个值都是固定大小的 287 | * 实现VariableWidthType的类型承诺:我的值可能是变长的 288 | * 这种契约让使用这些类型的代码可以做出相应的优化假设 289 | 290 | **类型安全设计** 291 | 292 | 遵守了这种契约,后续的开发与编译时是能保证类型安全的。 293 | 294 | ``` 295 | // 假设我们需要一个只处理固定长度类型的方法 296 | public void processFixedWidthType(FixedWidthType type) { 297 | int size = type.getFixedSize(); // 编译时就能确保这个调用是安全的 298 | // ... 299 | } 300 | ``` 301 | 302 | > 这种设计体现了 "组合优于继承" 的原则,通过接口组合而不是把所有功能都放在一个大接口中,使得系统更加灵活和可维护。这也是为什么现代编程语言和框架倾向于使用小接口而不是大接口的原因。 303 | 304 | 305 | ## Type 后续的抽象类 306 | 307 | Type 算是所有类型的基础接口设计,而以下两个抽象类,算是 Presto 对类型的两层抽象。 308 | 309 | 这两层抽象都处理了特定的关注点,避免的每个具体类型都要实现所有 Type 接口方法 310 | 311 | ### AbstractType 312 | 313 | AbstractType 是作为所有类型的基础抽象类,提供了一些通用的实现和工具方法,它是其他更具体类型类的基础。 314 | 315 | 设计此抽象类,presto的主要是为所有的类型设计一个统一的基准行为,比如我们可以看到里面的大部分方法都返回了统一的异常,这样就相当于给接口方法一个默认的实现,保证所有的子类在默认的情况下,具有一致的效果。 316 | 317 | ``` 318 | @Override 319 | public boolean equalTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition) 320 | { 321 | throw new UnsupportedOperationException(getTypeSignature() + " type is not comparable"); 322 | } 323 | @Override 324 | public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition) 325 | { 326 | throw new UnsupportedOperationException(getTypeSignature() + " type is not orderable"); 327 | } 328 | @Override 329 | ``` 330 | 331 | 后续我们可以看到基本常用的子类都继承了它,所以该抽象类,也是起到了 强制子类提供具体实现,方便扩展,同时接口的通用实现放在下一层的抽象类中,也有助于代码的维护,和结构的清晰性和可读性。 332 | 333 | ![](vx_images/105628459685315.png) 334 | 335 | ### AbstractPrimitiveType AbstractVariableWidthType 336 | 337 | 338 | 继承自AbstractType,专门用于原始类型,避免每个具体类型都要实现所有Type接口方法,提供了默认的错误处理机制,统一管理通用属性(如javaType)。 339 | 340 | 341 | ### 带有类型的抽象类 Long Int Decimal DateTime 342 | 343 | 从 AbstractType,AbstractPrimitiveType 这些抽象类,往下走,我们可以看到会有很多具体类型的抽象类设计 344 | 345 | ![](vx_images/41557301535957.png) 346 | 347 | 比如 348 | 349 | * AbstractLongType 专门用于处理长整型数据(对应于 Java 中的 `long` 类型)。它提供了处理长整型数据的特定方法。 350 | * AbstractIntType 专门用于处理整型数据(对应于 Java 中的 `int` 类型)。它提供了处理整型数据的特定方法。 351 | * DecimalType 用于表示十进制数,支持固定和可变精度的十进制数。这个类提供了处理十进制数的特定方法。 352 | 353 | 这里我们先思考一下,已经有一个 AbstractType 了,为什么还要设置具体类型的抽象呢? 354 | 355 | 在 Presto 中设计了 AbstractLongType, AbstractIntType, DecimalType 具体类型抽象类,是为了提供针对特定数据类型的专属化实现和优化。这些抽象类继承自 AbstractType 并增加了一些新的功能和特性,以适应各自数据类型的特定需求。 356 | 357 | 这里我们可以分类的理解,分为整型(也包括时间类型)、长整型、大精度类型,那么这些3种类型里面,要设计哪些特殊处理呢? 358 | 359 | 这样的设计主要有以下 4 个关键点 360 | 361 | 1. 性能优化 362 | * 整型:使用专门的IntArrayBlockBuilder 363 | * 长整型:使用专门的LongArrayBlockBuilder 364 | * 大精度:根据精度自动选择最优实现 365 | 2. 类型安全 366 | * 整型:处理int到long的安全转换 367 | * 长整型:直接处理long值 368 | * 大精度:精度和标度的验证 369 | 3. 特殊运算 370 | * 整型:整数比较逻辑 371 | * 长整型:特殊的哈希计算 372 | * 大精度:精度相关的运算 373 | 4. 内存优化 374 | * 整型:固定4字节 375 | * 长整型:固定8字节 376 | * 大精度:根据精度选择最优存储方式 377 | 378 | 这种设计体现了"专门化"的思想,通过为不同数据类型提供专门的实现,既保证了类型安全,又实现了性能优化。每种类型的抽象类都关注于解决该类型特有的问题,使得具体类型的实现更加简单和高效。 379 | 380 | 381 | ## Block 接口 382 | 383 | 根据前面的介绍,我们知道 Block 在 Presto 中是数据的载体,是 Presto 中最基础的数据存储和处理单元,主要有以下几个作用 384 | 385 | 1. 数据存储容器 386 | - Block 作为一个列式存储的容器,用于存储同一类型的多个值 387 | - 支持不同数据类型(如 int、long、string 等)的存储 388 | - 提供内存高效的数据存储方式 389 | 2. 设计了数据访问接口,比如 Block 里有如下方法 390 | - getPositionCount 获取Block中的位置数 391 | - isNull 获取指定位置的值是否为null 392 | - getSizeInBytes 获取Block在内存中的大小 393 | - getLogicalSizeInBytes 获取Block的逻辑大小 394 | 3. Block 与 Type 类型接口的关系 395 | - Type 定义了数据类型的行为和操作,Block 提供了实际的数据存储容器 396 | - Type 负责对 Block 中的数据进行读写操作,例如: 397 | - 从 Block 中读取 long 类型的值 long getLong(Block block, int position); 398 | - 向 BlockBuilder 中写入 boolean 值 void writeBoolean(BlockBuilder blockBuilder, boolean value); 399 | 400 | Type 与 Block 设计的目的在于实现了数据存储和数据操作的解耦。 401 | 402 | ## 总结 403 | 404 | 我们详细了解了 Presto 类型系统的设计理念和实现细节。从基本的类型分类,到底层的 Slice 结构,从 Block 的数据载体设计,到 Type 接口的丰富功能,再到抽象类的层次化实现,我们可以看到 Presto 在类型系统设计上的深思熟虑。 405 | 406 | 这种设计既保证了类型系统的完整性和扩展性,又通过精心的性能优化确保了高效的数据处理能力。特别是在 Type 接口与 Block 的配合中,展现了优秀的解耦设计思想。 407 | 408 | 让我们系统地总结一下 Presto 类型系统的核心要点: 409 | 410 | ### 1. 核心组件 411 | 412 | - **Type**: 定义了类型的基本行为和属性 413 | - **Block**: 作为数据的载体,提供高效的列式存储 414 | - **Slice**: 作为底层数据结构,用于高效处理二进制数据 415 | 416 | ### 2. 类型体系的分层设计 417 | 418 | - **基础接口层**: Type 接口定义基本契约 419 | - **抽象实现层**: AbstractType 提供通用实现 420 | - **类型特化层**: 如 AbstractLongType 等针对具体类型的抽象类 421 | - **具体实现层**: 最终的具体类型实现 422 | 423 | ### 3. 关键设计特点 424 | 425 | - **类型安全**: 通过接口契约和类型检查确保类型安全 426 | - **性能优化**: 427 | - 通过 Block 的列式存储提升性能 428 | - 提供无边界检查的操作方法 429 | - 针对不同类型提供专门的优化实现 430 | - **扩展性**: 通过接口和抽象类的设计,支持新类型的扩展 431 | 432 | ### 4. 实际应用价值 433 | 434 | - 支持 SQL 标准的类型系统 435 | - 提供高效的数据处理能力 436 | - 良好的可维护性和扩展性 437 | - 与 Java 生态系统的良好集成 438 | 439 | 这种设计不仅满足了 Presto 作为分布式 SQL 查询引擎的需求,也为类型系统的设计提供了很好的参考。 440 | -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2021-08-16T01:44:18Z", 3 | "files": [ 4 | { 5 | "attachment_folder": "", 6 | "created_time": "2021-08-16T01:44:18Z", 7 | "id": "3", 8 | "modified_time": "2021-08-16T01:44:18Z", 9 | "name": "源码分布.md", 10 | "signature": "3824421211952191583", 11 | "tags": [ 12 | ] 13 | }, 14 | { 15 | "attachment_folder": "", 16 | "created_time": "2021-08-16T01:44:18Z", 17 | "id": "4", 18 | "modified_time": "2021-10-06T02:14:49Z", 19 | "name": "源码开发与阅读环境搭建.md", 20 | "signature": "2845011193488283743", 21 | "tags": [ 22 | ] 23 | }, 24 | { 25 | "attachment_folder": "", 26 | "created_time": "2021-08-16T01:44:18Z", 27 | "id": "5", 28 | "modified_time": "2021-08-16T01:44:18Z", 29 | "name": "论文阅读:Presto_SQL_on_Everything.md", 30 | "signature": "4749048823771371615", 31 | "tags": [ 32 | ] 33 | }, 34 | { 35 | "attachment_folder": "", 36 | "created_time": "2024-01-11T14:36:06Z", 37 | "id": "44", 38 | "modified_time": "2025-01-19T03:03:42Z", 39 | "name": "Presto类型系统浅入.md", 40 | "signature": "505481291251793490", 41 | "tags": [ 42 | ] 43 | } 44 | ], 45 | "folders": [ 46 | ], 47 | "id": "20", 48 | "modified_time": "2021-08-16T01:44:18Z", 49 | "signature": "3647195760214218847", 50 | "version": 3 51 | } 52 | -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/105628459685315.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/105628459685315.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/1059179002819.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/1059179002819.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/1269335877304.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/1269335877304.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/1317497817230.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/1317497817230.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/2091148002886.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/2091148002886.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/226360128042687.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/226360128042687.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/2926684777693.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/2926684777693.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/2957207687416.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/2957207687416.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/343904706519.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/343904706519.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/3875607524811.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/3875607524811.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/4024148821362.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/4024148821362.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/4137139781556.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/4137139781556.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/41557301535957.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/41557301535957.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/437568052647907.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/437568052647907.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/4397241250861.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/4397241250861.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/447948456408.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/447948456408.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/46219157909.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/46219157909.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/4658839148518.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/4658839148518.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/4731341243096.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/4731341243096.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/485282891372733.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/485282891372733.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/5177841138996.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/5177841138996.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/5330414769766.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/5330414769766.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/5800024495611.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/5800024495611.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/vx_images/5971561748547.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/01_基础概念与全面了解/vx_images/5971561748547.png -------------------------------------------------------------------------------- /01_基础概念与全面了解/源码分布.md: -------------------------------------------------------------------------------- 1 | # 源码分布 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | presto的代码没有用文件夹分类,但是名字起得都挺不错的,稍微理解下就能分辨出来。trino这一块就做的很贴心了,已经帮我们做好了分类。 8 | 9 | 理解了presto的插件设计后,基本上除了Coordinator部分的代码,其他大部分都是以插件的形式存在。 10 | 11 | ## presto的源码分布 12 | 13 | ``` 14 | . 15 | ├── CONTRIBUTING.md 16 | ├── LICENSE 17 | ├── README.md 18 | ├── mvnw 19 | ├── pom.xml 20 | ├── presto-docs sphinx风格的文档。在python中比较常见。 21 | │ 22 | ├── presto-server 打包模块,定义了整个项目的打包信息。 23 | ├── presto-server-rpm RPM打包 24 | │ 25 | ├── presto-spi 核心接口设计模块 26 | │ 27 | ├── presto-main 核心主模块 28 | ├── presto-common 高版本抽离出了公共模块 29 | │ 30 | ├── presto-cli 客户端命令行方式 31 | ├── presto-client 客户端jar包调用方式 32 | ├── presto-jdbc jdbc的方式 33 | │ 34 | ├── presto-accumulo 35 | ├── presto-array 36 | ├── presto-atop 37 | ├── presto-base-jdbc 38 | ├── presto-benchmark 39 | ├── presto-benchmark-driver 40 | ├── presto-benchmark-runner 41 | ├── presto-benchto-benchmarks 42 | ├── presto-blackhole 43 | ├── presto-bytecode 44 | ├── presto-cache 45 | ├── presto-cassandra 46 | ├── presto-druid 47 | ├── presto-elasticsearch 48 | ├── presto-example-http 49 | ├── presto-expressions 50 | ├── presto-function-namespace-managers 51 | ├── presto-geospatial 52 | ├── presto-geospatial-toolkit 53 | ├── presto-hive 54 | ├── presto-hive-common 55 | ├── presto-hive-hadoop2 hive插件 56 | ├── presto-hive-metastore 57 | ├── presto-i18n-functions 58 | ├── presto-jmx 59 | ├── presto-kafka 60 | ├── presto-kudu 61 | ├── presto-local-file 62 | ├── presto-matching 63 | ├── presto-memory 64 | ├── presto-memory-context 65 | ├── presto-ml 66 | ├── presto-mongodb 67 | ├── presto-mysql 68 | ├── presto-oracle 69 | ├── presto-orc 70 | ├── presto-parquet 71 | ├── presto-parser 72 | ├── presto-password-authenticators 73 | ├── presto-pinot 74 | ├── presto-pinot-toolkit 75 | ├── presto-plugin-toolkit 76 | ├── presto-postgresql 77 | ├── presto-product-tests 78 | ├── presto-raptor 79 | ├── presto-rcfile 80 | ├── presto-record-decoder 81 | ├── presto-redis 82 | ├── presto-redshift 83 | ├── presto-resource-group-managers 84 | ├── presto-session-property-managers 85 | ├── presto-spark presto这边独有的presto on spark 86 | ├── presto-spark-base 87 | ├── presto-spark-classloader-interface 88 | ├── presto-spark-common 89 | ├── presto-spark-launcher 90 | ├── presto-spark-package 91 | ├── presto-spark-testing 92 | ├── presto-sqlserver 93 | ├── presto-teradata-functions 94 | ├── presto-testing-docker 95 | ├── presto-testing-server-launcher 96 | ├── presto-tests 97 | ├── presto-thrift-api 98 | ├── presto-thrift-connector 99 | ├── presto-thrift-connector-api 100 | ├── presto-thrift-testing-server 101 | ├── presto-thrift-testing-udf-server 102 | ├── presto-tpcds 103 | ├── presto-tpch 104 | │ 105 | ├── presto-proxy 106 | ├── presto-verifier 107 | │ 108 | ├── src 109 | └── target 110 | 111 | ``` 112 | 113 | ## trino的源码分布 114 | 115 | ``` 116 | trino 117 | ├── mvnw 编译打包脚本,Maven Wrapper的缩写它可以负责给这个特定的项目安装指定版本的Maven,而其他项目不受影响。 118 | ├── docs sphinx风格的文档。在python中比较常见。 119 | ├── pom.xml maven项目的pom文件 120 | │ 121 | ├── core presto 核心模块 122 | │ ├── docker docker 123 | │ ├── trino-main 核心主模块 124 | │ ├── trino-parser SQL解析 125 | │ ├── trino-server-main 主服务启动模块 126 | │ ├── trino-server 打包模块,定义了整个项目的打包信息。 127 | │ ├── trino-server-rpm RPM打包 128 | │ └── trino-spi 核心接口设计模块 129 | │ 130 | ├── client presto 客户端模块 131 | │ ├── trino-cli 客户端命令行方式 132 | │ ├── trino-client 客户端jar包调用方式 133 | │ └── trino-jdbc jdbc的方式 134 | │ 135 | ├── lib presto 运行所需基础类库 136 | │ ├── trino-array 137 | │ ├── trino-geospatial-toolkit 空间数据 138 | │ ├── trino-matching 模式匹配 139 | │ ├── trino-memory-context 内存上下文 140 | │ ├── trino-orc 支持orc格式 141 | │ ├── trino-parquet 支持parquet格式 142 | │ ├── trino-plugin-toolkit 插件 143 | │ ├── trino-rcfile 支持hadoop列存RCFile 144 | │ └── trino-record-decoder json、avro、csv、等等文件解码器 145 | │ 146 | ├── plugin presto 插件模块 147 | │ ├── trino-accumulo 148 | │ ├── trino-accumulo-iterators 149 | │ ├── trino-atop 150 | │ ├── trino-base-jdbc 151 | │ ├── trino-bigquery 152 | │ ├── trino-blackhole 153 | │ ├── trino-cassandra 154 | │ ├── trino-druid 155 | │ ├── trino-elasticsearch 156 | │ ├── trino-example-http http例子 157 | │ ├── trino-geospatial 158 | │ ├── trino-google-sheets 159 | │ ├── trino-hive 160 | │ ├── trino-hive-hadoop2 hive专属优化 161 | │ ├── trino-iceberg 162 | │ ├── trino-jmx 163 | │ ├── trino-kafka 164 | │ ├── trino-kinesis 165 | │ ├── trino-kudu 166 | │ ├── trino-local-file 读本地文件 167 | │ ├── trino-memory 168 | │ ├── trino-memsql 169 | │ ├── trino-ml 170 | │ ├── trino-mongodb 171 | │ ├── trino-mysql 172 | │ ├── trino-oracle 173 | │ ├── trino-password-authenticators 174 | │ ├── trino-phoenix 175 | │ ├── trino-pinot 176 | │ ├── trino-postgresql 177 | │ ├── trino-prometheus 178 | │ ├── trino-raptor-legacy 179 | │ ├── trino-redis 180 | │ ├── trino-redshift 181 | │ ├── trino-resource-group-managers 182 | │ ├── trino-session-property-managers 183 | │ ├── trino-sqlserver 184 | │ ├── trino-teradata-functions 185 | │ ├── trino-thrift 186 | │ ├── trino-thrift-api 187 | │ ├── trino-thrift-testing-server 188 | │ ├── trino-tpcds 189 | │ └── trino-tpch 190 | │ 191 | ├── service presto 代理模块 192 | │ ├── trino-proxy 193 | │ └── trino-verifier 194 | │ 195 | ├── testing presto 测试模块 196 | │ ├── trino-benchmark 197 | │ ├── trino-benchmark-driver 198 | │ ├── trino-benchto-benchmarks 199 | │ ├── trino-product-tests 200 | │ ├── trino-product-tests-launcher 201 | │ ├── trino-test-jdbc-compatibility-old-driver 202 | │ ├── trino-test-jdbc-compatibility-old-server 203 | │ ├── trino-testing 204 | │ ├── trino-testing-kafka 205 | │ ├── trino-testng-services 206 | │ └── trino-tests 207 | │ 208 | ├── target 代码检查 209 | │ ├── checkstyle-cachefile 210 | │ ├── checkstyle-checker.xml 211 | │ └── checkstyle-result.xml 212 | 213 | ``` -------------------------------------------------------------------------------- /02_基础实践/vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2022-02-01T04:48:42Z", 3 | "files": [ 4 | { 5 | "attachment_folder": "", 6 | "created_time": "2022-02-01T13:13:58Z", 7 | "id": "24", 8 | "modified_time": "2022-02-14T10:51:23Z", 9 | "name": "如何配置访问控制.md", 10 | "signature": "784285914933834262", 11 | "tags": [ 12 | ] 13 | } 14 | ], 15 | "folders": [ 16 | ], 17 | "id": "22", 18 | "modified_time": "2022-02-01T04:48:42Z", 19 | "signature": "207324010036138", 20 | "version": 3 21 | } 22 | -------------------------------------------------------------------------------- /02_基础实践/vx_images/133464413615087.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/133464413615087.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/139295961548949.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/139295961548949.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/165333854147997.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/165333854147997.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/208524403522573.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/208524403522573.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/238815728122362.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/238815728122362.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/254164575806893.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/254164575806893.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/255863286002299.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/255863286002299.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/271274925157389.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/271274925157389.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/322355476936706.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/322355476936706.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/355493694777171.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/355493694777171.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/398605714648409.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/398605714648409.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/425302048242576.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/425302048242576.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/45496649751351.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/45496649751351.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/471522511114541.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/471522511114541.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/485012067938534.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/485012067938534.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/515491583356115.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/515491583356115.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/568503556733984.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/568503556733984.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/577266600889242.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/577266600889242.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/63155029575884.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/63155029575884.png -------------------------------------------------------------------------------- /02_基础实践/vx_images/63653761654079.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/02_基础实践/vx_images/63653761654079.png -------------------------------------------------------------------------------- /02_基础实践/如何配置访问控制.md: -------------------------------------------------------------------------------- 1 | # 如何配置访问控制 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | ## 简述 8 | 9 | >这个功能 Presto 与 Trino 的配置方式差不多。所以会配置其中一个了,理论上也应该会配另一个了。 10 | > 11 | >目前大部分都是在 Trino 下做开发与运维,所以本文会主要以 Trino 来讲解。(这里也顺便吐槽一下,Presto 与 Trino 的文档确实说的太浅了)。 12 | 13 | 在阅读本文前我们先思考一个问题,`让用户登录一个系统,需要输入哪些条件是最简单的呢?`,按我多年运维的经验,最简单的就是 `账号、密码、网络地址`,其他的不能再多了。稍微多一个,就会难道 99% 的人。 14 | 15 | 曾经给公司使用了原始 Presto 的登录认证,用户登录的时候需要配置证书,就这一个小小的证书配置几乎难倒了 99.99% 的人,最难受的就是文档写得再详细,用户也看不懂。因为大部分用户的认知都停留在 `账号、密码、网络地址` 上。有时候真不能怪用户,多出来的任何一项都大概率超过用户的认知。 16 | 17 | 最后一句话描述就是:`如何只输入账号和密码、网络地址就可以访问 Presto、Trino` (注意!官方的默认情况是不支持这一点的) 18 | 19 | 所以,你如果有同样的痛点和需求,那么请接着往下读。 20 | 21 | >补充:这里说的证书是指,HTTPS 与 TLS 证书,一些参考 https://en.wikipedia.org/wiki/Transport_Layer_Security 22 | 23 | **注意:本文只讲解访问控制的登录认证,与账号密码和简单的证书配置,暂时不涉及 LDAP、OAuth、Kerberos、JWT 这些。** 24 | 25 | ## 官方文档指引 26 | 27 | - Presto 28 | - https://prestodb.io/docs/current/security/password-file.html 29 | - https://prestodb.io/docs/current/security/tls.html 30 | 31 | - Trino 32 | - https://trino.io/docs/current/security/overview.html 33 | - https://trino.io/docs/current/security/tls.html 34 | - https://trino.io/docs/current/security/authentication-types.html 35 | - https://trino.io/docs/current/security/password-file.html 36 | 37 | 38 | 这些文档综合下来,如果想实现一个简单的访问控制,大致流程为: 39 | 40 | 1. 如果要配置访问控制,就必须开启 SSL 加密的认证方式。 41 | 2. 账号密码验证方式可以选择本地密码文件验证或 LDAP 等其他认证服务。 42 | 3. 服务端默认的启动为无加密的 HTTP 方式,开启认证则为标准 HTTPS 加密方式,官方的建议如果开启了认证,最好是把 HTTP 方式隐藏或者不提供。 43 | 4. 开启 SSL 加密认证,需要证书才能登录,可以自行制作一个 Java Keystores and Truststores 证书,并且把这个证书导入到运行的 JDK 当中。 44 | 5. 最后用户在登录时需要连接 HTTPS 端口,且开启 SSL 然后添加证书指定的参数,用户才能正常登录。 45 | 46 | ## 官方推荐方式实践 47 | 48 | ### 服务端配置(密码文件的方式) 49 | 50 | >为了演示方便,使用本地密码文件的方式。后续上生产都还是建议使用 LDAP。 51 | 52 | `etc/config.properties` 中添加如下配置 53 | 54 | ``` 55 | http-server.authentication.type=PASSWORD 56 | 57 | http-server.https.enabled=true 58 | http-server.https.port=38081 59 | 60 | http-server.https.keystore.path=jks证书文件的位置 61 | http-server.https.keystore.key=jks证书的key 62 | ``` 63 | 64 | 新增 `password-authenticator.properties` 配置文件 65 | 66 | 添加如下内容 67 | 68 | ``` 69 | password-authenticator.name=file 70 | file.password-file=密码文件的路径 71 | ``` 72 | 73 | 设置账号密码 74 | 75 | ``` 76 | touch password.db 77 | 78 | htpasswd -B -C 10 password.db test 79 | ``` 80 | 81 | 密码文件设置后里面的内容如下 82 | 83 | ![](vx_images/133464413615087.png) 84 | 85 | 86 | 87 | ### 证书制作 88 | 89 | 这一步,主要是 `CN` 这一项的填写,填写了 `什么`,客户端在连接的时候就写 `什么`。 90 | 91 | 比如我填写了 `localhost`,客户端在连接时就需要用 `localhost` 的地址。这个地址就是你 `Coordinator` 的地址。需要注意的是,证书里用了域名那 Presto 的配置都建议使用域名,反之 IP 同理。 92 | 93 | 可以使用交互式命令操作 94 | 95 | ``` 96 | keytool -genkeypair -alias trino_2022 -keyalg RSA -validity 8888 -keystore trino_2022.jks 97 | ``` 98 | 99 | 此时会提示要输出口令,我们使用这个口令 100 | 101 | ``` 102 | trino_pass_2022 103 | ``` 104 | 105 | ``` 106 | 输入密钥库口令: 107 | 再次输入新口令: 108 | 您的名字与姓氏是什么? 109 | [Unknown]: localhost 110 | 您的组织单位名称是什么? 111 | [Unknown]: 112 | 您的组织名称是什么? 113 | [Unknown]: 114 | 您所在的城市或区域名称是什么? 115 | [Unknown]: 116 | 您所在的省/市/自治区名称是什么? 117 | [Unknown]: 118 | 该单位的双字母国家/地区代码是什么? 119 | [Unknown]: 120 | CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown是否正确? 121 | [否]: 是 122 | 123 | 输入 的密钥口令 124 | (如果和密钥库口令相同, 按回车): 125 | 126 | Warning: 127 | JKS 密钥库使用专用格式。建议使用 "keytool -importkeystore -srckeystore trino.jks -destkeystore trino.jks -deststoretype pkcs12" 迁移到行业标准格式 PKCS12。 128 | ``` 129 | 130 | 也可以使用便捷命令,一次性完成所有操作 131 | 132 | ``` 133 | keytool -genkeypair -alias trino_2022 -validity 8888 -keyalg RSA -dname \ 134 | "CN=localhost,O=Unknown,L=Unknown,S=Unknown,C=Unknown" -keypass trino_pass_2022 \ 135 | -keystore trino_2022.jks -storepass trino_pass_2022 -storetype JKS 136 | ``` 137 | 138 | ### 证书的导入与导出 139 | 140 | #### 导出 141 | 142 | 制作完证书后,需要把证书导入到 JDK 中。因为使用带有证书的 JDK 运行了 Presto 或 Trino 时,才具有认证效果。 143 | 144 | 默认证书是 JKS 格式的,必须先从 JKS 格式导出成 CRT 格式。才能导入。 145 | 146 | 导出命令,这里注意 JKS 的路径不能写错: 147 | 148 | ``` 149 | keytool -export -file ./trino_2022.crt -alias trino_2022 -keystore ./trino_2022.jks 150 | ``` 151 | 152 | #### 导入 153 | 154 | 155 | 导入前我们需要确定下 JAVA_HOME 的环境 156 | 157 | ``` 158 | $ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home 159 | $ export PATH=$JAVA_HOME/bin:$PATH 160 | 161 | $ java -version 162 | java version "11.0.13" 2021-10-19 LTS 163 | Java(TM) SE Runtime Environment 18.9 (build 11.0.13+10-LTS-370) 164 | Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.13+10-LTS-370, mixed mode) 165 | ``` 166 | 167 | 导入的时候为了减少出错的风险,建议写绝对路径。 168 | 169 | ``` 170 | keytool -import -alias trino_2022 -keystore /Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home/lib/security/cacerts -file /tmp/trino_2022.crt 171 | ``` 172 | 173 | 这里会提示需要输入密码,`注意` 这里不是刚才设置证书的密码,而是 `jdk cacerts 的密码` 默认为 `changeit`。 174 | 175 | 加深印象,导入证书的密码为 176 | 177 | ``` 178 | changeit 179 | changeit 180 | changeit 181 | ``` 182 | 183 | 成功导入后,会出现如下提示: 184 | 185 | ``` 186 | 警告: 使用 -cacerts 选项访问 cacerts 密钥库 187 | 输入密钥库口令: 188 | 所有者: CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown 189 | 发布者: CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown 190 | 序列号: 7d1dabcf 191 | 生效时间: Sat Nov 06 22:55:09 CST 2021, 失效时间: Tue Nov 04 22:55:09 CST 2031 192 | 证书指纹: 193 | SHA1: 85:DA:70:7B:1F:CF:B9:DC:1D:07:DA:7C:77:82:59:16:85:08:D5:24 194 | SHA256: B2:11:AC:30:F0:BD:D5:BB:BB:8B:F1:54:2B:44:B9:8D:8E:9C:65:59:F3:23:46:96:5B:BB:6F:6B:E3:3C:72:76 195 | 签名算法名称: SHA256withRSA 196 | 主体公共密钥算法: 2048 位 RSA 密钥 197 | 版本: 3 198 | 199 | 扩展: 200 | 201 | #1: ObjectId: 2.5.29.17 Criticality=false 202 | SubjectAlternativeName [ 203 | IPAddress: 192.168.3.202 204 | ] 205 | 206 | #2: ObjectId: 2.5.29.14 Criticality=false 207 | SubjectKeyIdentifier [ 208 | KeyIdentifier [ 209 | 0000: 9F AD 53 4D 79 15 EE 7D 77 5D E7 6B E9 57 B9 4B ..SMy...w].k.W.K 210 | 0010: 19 9E DB D1 .... 211 | ] 212 | ] 213 | 214 | 是否信任此证书? [否]: 是 215 | 证书已添加到密钥库中 216 | ``` 217 | 218 | 查看下证书是否正确导入 219 | 220 | ``` 221 | cd /Library/Java/JavaVirtualMachines/jdk-11.0.13.jdk/Contents/Home/lib/security 222 | 223 | 224 | $ keytool -list -keystore cacerts | grep trino_2022 225 | 警告: 使用 -cacerts 选项访问 cacerts 密钥库 226 | 输入密钥库口令: changeit 227 | trino_2022, 2022年2月2日, trustedCertEntry, 228 | 229 | ``` 230 | 231 | ### 客户端连接 232 | 233 | 有两种方式连接,使用原生 jar 包,或者使用 DataGrip,DBeaver 这类工具。 234 | 235 | **使用原生jar方式** 236 | 237 | ``` 238 | java -jar trino-cli-363-executable.jar --server="https://localhost:38081" --keystore-path="/tmp/trino_2022.jks" --keystore-password="trino_pass_2022" --user="test" --password 239 | ``` 240 | 241 | **使用客户端工具连接的方式** 242 | 243 | >使用工具连需要多配置 3 个参数 244 | 245 | | key | value | 246 | | ------------------- | ------------- | 247 | | SSL | true | 248 | | SSLKeyStorePassword | 制作证书的密码 | 249 | | SSLKeyStorePath | jks的位置 | 250 | 251 | 252 | ![](vx_images/254164575806893.png) 253 | 254 | 这个地方的 `SSLKeyStorePassword` 就是我们刚才设置的 `trino_pass_2022`。 255 | 256 | ![](vx_images/208524403522573.png) 257 | 258 | 259 | **需要注意的地方** 260 | 261 | Trino 的客户端,不像 MySQL 客户端设置了明显的错误提示。 262 | 263 | SSL 类的设置,属于客户端的提示,比如我想知道账号密码错误,目前的反馈是这样的。 264 | 265 | 密码错误: 266 | 267 | ![](vx_images/577266600889242.png) 268 | 269 | ![](vx_images/63155029575884.png) 270 | 271 | 只有使用原生 jar 包连接,才会出现明确一点的错误。 272 | 273 | ``` 274 | $ java -jar trino-cli-363-executable.jar --server="https://localhost:38081" --keystore-path="/tmp/trino_2022.jks" --keystore-password="trino_pass_2022" --user="test" --password 275 | Password: 276 | trino> show catalogs; 277 | Error running command: Authentication failed: Access Denied: Invalid credentials 278 | ``` 279 | 280 | 密码正确的连接: 281 | 282 | ![](vx_images/238815728122362.png) 283 | 284 | ![](vx_images/322355476936706.png) 285 | 286 | ``` 287 | $ java -jar trino-cli-363-executable.jar --server="https://localhost:38081" --keystore-path="/tmp/trino_2022.jks" --keystore-password="trino_pass_2022" --user="test" --password 288 | Password: 289 | trino> show catalogs; 290 | Catalog 291 | ----------- 292 | localfile 293 | mysql 294 | system 295 | (3 rows) 296 | 297 | Query 20220202_024044_00000_6e94r, FINISHED, 1 node 298 | Splits: 19 total, 19 done (100.00%) 299 | 1.03 [0 rows, 0B] [0 rows/s, 0B/s] 300 | 301 | ``` 302 | 303 | 这里也变相算是个小坑吧。没有明确告诉用户是哪里错了。从 JDBC 客户端的角度来看,是 `连接成功、认证失败`。只有使用原始客户端登录才能看到详细的错误。 304 | 305 | ## 便捷方式实践(需要少量二次开发) 306 | 307 | 看完前面的实践,可以说这一套流程下来,对用户的学习成本和心智成本是相当高了。 308 | 309 | 那么我们能不能实现 `只需要账号密码`,而不用证书,就能完成登录呢? 310 | 311 | 官方文档里是没有做任何介绍,我们只能走读源码来找找蛛丝马迹了。 312 | 313 | ### 客户端部分 314 | 315 | 使用官方 JDBC 客户端连接的时候,必须要设置 `SSL=true` 和 `证书`,才能配置账号密码连接,不然只输入账号密码的话就会出现如下错误。 316 | 317 | ![](vx_images/139295961548949.png) 318 | 319 | 而且只配 `SSL=true` 不配 `证书` 也不行,会出现如下错误。 320 | 321 | ![](vx_images/165333854147997.png) 322 | 323 | 我们跟一下源码,发现 JDBC 的部分有一个 `useSecureConnection`,它代表是否设置了 SSL。 324 | 325 | ![](vx_images/45496649751351.png) 326 | 327 | ![](vx_images/398605714648409.png) 328 | 329 | 所以使用账号密码连接,就必须配置 SSL,配置 SSL 就必须要有证书,这样就会陷入到那个麻烦的配置问题上。 330 | 331 | 其实在这个地方,把 JDBC 客户端的 SSL 验证逻辑取消掉,也是可行的。缺点就是用户不能使用官方的 JDBC jar 包,大量用户的 jar 包变更还是不太友好。 332 | 333 | ### 服务端部分 334 | 335 | 我们再看看服务端的代码。 336 | 337 | 这里调用栈比较深,我的习惯是从启动的时候开始看,因为 Presto、Trino 在启动的时候会按照功能分门别类加载。比如这个访问控制的账号密码相关的,我们就可以轻易的看出来是 `ServerSecurityModule` 这个模块加载的。 338 | 339 | ![](vx_images/471522511114541.png) 340 | 341 | 跟进去后,我们发现这个模块会加载我们前面在官方文档中看到的各种验证方式,比如 Kerberos、OAuth2、JWT 等等。而且发现第一个加载的就是一个 `AuthenticationFilter` 身份验证过滤器。 342 | 343 | ![](vx_images/355493694777171.png) 344 | 345 | 跟到 `身份验证过滤器` 里面,我们可以发现,使用了安全的连接方式会走 `authenticator` 里面去,比如我们前面设置的基于密码文件来进行身份验证。如果不使用安全连接的方式,则走 `InsecureAuthenticator` 我把它称为不安全的身份验证。 346 | 347 | 通过断点调试,我们在默认启动 presto 的时候,http 的访问方式确是走的 `不安全的身份验证`。 348 | 349 | 服务端的修改,我们只需要注释掉那个安全访问方式的判断,然后把 `不管用什么方式连接,都会走到 authenticator` 逻辑。 350 | 351 | ![](vx_images/515491583356115.png) 352 | 353 | 354 | 这里简单的理解就是,如果使用 `authenticator` 是会验证账号密码,具体逻辑可以参考 `io.trino.server.security.Authenticator` 接口里的 `authenticate` 实现。如下图: 355 | 356 | ![](vx_images/255863286002299.png) 357 | 358 | 如果使用 `InsecureAuthenticator` 则不会验证账号密码。查看代码里连密码字段都没去取,反而有逻辑检查如果你设置了密码,还会给你抛个异常。不允许使用不安全的身份验证逻辑中进行密码验证。 359 | 360 | ![](vx_images/425302048242576.png) 361 | 362 | 363 | ## 总结 364 | 365 | ### 想法 366 | 367 | 跟完以上代码。我们可以得到两个关键点。 368 | 369 | 1. 在不修改客户端的前提下(主要是要对用户无感知,分发 jar 也是一个麻烦事)。只有开启 SSL 认证并配置好证书才能进行账号密码验证。 370 | 2. 服务端也有强逻辑来判断,只有是在安全的访问方式下才会进行账号密码验证。 371 | 372 | 那么我们可以使用如下方式绕过这些: 373 | 374 | 1. 服务端只开启不安全的访问模式,只开启 HTTP 默认的访问方式。 375 | 2. 服务端开启密码验证服务,设置 `http-server.authentication.type=PASSWORD`。 376 | 3. 使用代理服务,比如 Nginx,方式为访问 Nginx 的 `HTTPS`,然后 Nginx 帮我们代理到 Presto 的 `HTTP` 上。这样客户端就可以在不用配置证书的情况下把账号密码传过来。(注意!客户端在访问时需要把端口改成 443)。 377 | 4. 服务端在 `身份验证` 逻辑部分,修改一下 HTTP 访问方式会走到的 `InsecureAuthenticator 不安全的身份验证方式` 逻辑,使所有逻辑都走到 `authenticator` 正常的身份验证方式中去,目的是让 HTTP 的方式也能验证账号密码。(这个方式不一定是最好的,只是比较粗暴) 378 | 5. 但是有个地方需要注意 Nginx 配置 HTTPS 代理是需要证书的,这里必须是公共信任的证书才会起到刚才我们所说的效果。如果使用自签的 SSL 证书则会出现如下错误。 379 | 380 | ![](vx_images/271274925157389.png) 381 | 382 | 383 | ### 实践 384 | 385 | 最后假设我们搞了一个收费的且有根认证的证书,我们可以参考如下 `Nginx` 配置,将证书配置进去。 386 | 387 | >注意!以下只是参考,最后请自行修改调整。或者查阅 Nginx 官方文档。 388 | 389 | ``` 390 | server { 391 | listen 443 ssl; 392 | server_name localhost; #域名 393 | 394 | # 增加ssl 395 | ssl_certificate /ssl/server.crt; #server证书公钥 396 | ssl_certificate_key /ssl/server.key; #server私钥 397 | 398 | ssl_session_cache shared:SSL:1m; 399 | ssl_session_timeout 5m; 400 | 401 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 402 | 403 | ssl_ciphers HIGH:!aNULL:!MD5; # 密码加密方式 404 | 405 | # 指向presto的地址和http端口 406 | location / { 407 | proxy_pass http://192.168.1.4:8080; 408 | } 409 | } 410 | ``` 411 | 412 | 下面的图片,是我用了公司的 nginx,并配置了收费证书代理presto,客户端访问后的效果。 413 | 414 | ![](vx_images/485012067938534.png) 415 | 416 | ![](vx_images/568503556733984.png) 417 | 418 | 419 | 420 | ![](vx_images/63653761654079.png) 421 | 422 | 423 | 424 | 425 | ### 结论 426 | 427 | 如果前期规模不大,然后公司内部又能建立好自己的包管理体系。又或者对用户客户端使用包的分发能够接受的话,直接修改 JDBC 客户端可以说是改动量较小的一个方式。 428 | 429 | 如果用户量规模较多涉及大量客户端使用包分发的时候,还是建议文中推荐的方式,修改服务端并使用一个代理服务来工作。 430 | 431 | 又或者用户能够接受以及学会配置证书,这样也行。(相信我,支持工作量相当庞大)。 -------------------------------------------------------------------------------- /03_通信流程/vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2021-08-16T01:44:18Z", 3 | "files": [ 4 | { 5 | "attachment_folder": "", 6 | "created_time": "2021-08-16T01:44:18Z", 7 | "id": "7", 8 | "modified_time": "2021-10-06T09:59:36Z", 9 | "name": "服务发现-主要流程介绍篇.md", 10 | "signature": "7284476565308643423", 11 | "tags": [ 12 | ] 13 | } 14 | ], 15 | "folders": [ 16 | ], 17 | "id": "21", 18 | "modified_time": "2021-08-16T01:44:18Z", 19 | "signature": "6356207469762517087", 20 | "version": 3 21 | } 22 | -------------------------------------------------------------------------------- /03_通信流程/vx_images/1034546555706.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/03_通信流程/vx_images/1034546555706.png -------------------------------------------------------------------------------- /03_通信流程/vx_images/162249199277.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/03_通信流程/vx_images/162249199277.png -------------------------------------------------------------------------------- /03_通信流程/vx_images/2122828756614.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/03_通信流程/vx_images/2122828756614.png -------------------------------------------------------------------------------- /03_通信流程/vx_images/3183894766800.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/03_通信流程/vx_images/3183894766800.png -------------------------------------------------------------------------------- /05_内存管理/Presto内存池使用调整.md: -------------------------------------------------------------------------------- 1 | # Presto内存池使用调整 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | ## 背景 8 | 9 | Presto 默认会给 Worker 开启 2 个内存池,这里面会有一些潜在的性能问题。 10 | 11 | 注意!这里的问题,是指默认的内存池情况不适用于我当前的业务,所以需要根据自身的业务来看待这个问题,不要盲目认为这样的调整一定适合你。 12 | 13 | 早期为了使用 Presto Local Cache 的缓存功能,我们整体从 Trino 迭代到了 Presto,结果发现 Presto 查询会比 Trino 要慢一些。 14 | 15 | ## 现象 16 | 17 | ### 查询耗时 18 | 19 | 我们是在 6 月份进行了迁移,迁移后发现明显变慢。 20 | 21 | ![](vx_images/473093398985098.png) 22 | 23 | 24 | ### 排队情况 25 | 26 | 集群很容易出现排队,经常出现集群里就 1 个查询,然后新进来的查询会排队。 27 | 28 | ![](vx_images/575212586114716.png) 29 | 30 | 31 | ### Worker的信息 32 | 33 | 在默认的情况下,Presto 有 2 个内存池,大部分都使用 General Pool,当有特别大的查询时才会使用 Reserved Pool。 34 | 35 | ![](vx_images/349954958637476.png) 36 | 37 | 一般情况下,查询都会去抢 General Pool 内存池,我们发现,5GB 的内存不适用于我们的业务场景。 38 | 39 | ![](vx_images/96253836776405.png) 40 | 41 | 42 | 43 | ## 分析 44 | 45 | 其实这个 调优点 ,大部分来自于经验。 46 | 47 | 因为早在 2021 以前维护 Presto 的时候,内存池的调整一般都是首要修改点。 48 | 49 | 当后期拆分到 PrestoSQL 和 Trino 的时候,新的社区把这个优化点调整了默认设置,减轻了用户的调优成本,所以在从 Trino 迁移回 Presto 的时候容易 `疏忽` 这一点。 50 | 51 | 52 | ## 原理 53 | 54 | 以前的记录: 55 | 56 | ![](vx_images/125223250132825.png) 57 | 58 | 大致原因就是,Presto 分配给用户能用的内存池,可以理解有 2 个 General Pool 和 Reserved Pool,这个内存池是由 Presto 管理的,主要是避免了反复与操作系统申请,提升内存的使用效率。 59 | 60 | 但是,默认情况下 Reserved Pool 会比 General Pool 大很多,而且只有出现大查询才会用 Reserved Pool,这里的大小是指单个查询可以使用内存的限制,而不是整个集群的内存限制。 61 | 62 | 又因为我们定位 Presto 给了 adhoc 和 bi 等场景,所以面对的大量查询都是小查询,因为我们添加了一些比较严格的限制,当一些大查询工作时都会先被那些限制给拦截掉,最终 Reserved 内存池几乎很难用上。 63 | 64 | 这里社区建议是可以将内存池合并,只使用 General,这样在面对 adhoc 和 bi 等场景时会很具有优势。 65 | 66 | ## 调整 67 | 68 | 调整后的内存使用情况: 69 | 70 | 相当于把 2 个内存池合并,不再分大查询和小查询,都来共用这 45G 的内存池,这样吞吐能力会有所提升。 71 | 72 | ![](vx_images/201333515098794.png) 73 | 74 | 其实在 Trino 中这 2 个内存池默认是合并的,所以 Trino 集群默认开启后就只有 1 个内存池,如下图: 75 | 76 | ![](vx_images/162264749038547.png) 77 | 78 | 79 | ## 调整后的效果 80 | 81 | 合并了内存池,主要是提升了内存池的上限,查询耗时不会变快,收益最大的是查询的吞吐能力变强了。 82 | 83 | 所以最后相应监控的的指标,应该为查询耗时削微降低,排队几率和耗时明显减少 84 | 85 | ![](vx_images/167824133273668.png) 86 | 87 | 88 | 89 | ## 内存池解释 90 | 91 | 在 Presto 引擎中,有两种类型的内存分配:User 和 System。 92 | 93 | User Memory 是和输入的数据强相关的。(例如,聚合的内存使用)。 94 | 95 | System Memory 是执行的副产品(比如表扫描和写入缓冲区),并且不一定与查询输入聚合等操作有很强的相关性。 96 | 97 | Presto 会为这两种内存分配 Worker 的 Memory Pools。 98 | 99 | Memory Pools 由 2个 pools 组成 General Pool 和 Reserved Pool,如图所示 100 | 101 | ![](vx_images/569313700652337.png) 102 | 103 | - General Pool:General Pool 提供 User Memory 和 System Memory 的分配。 104 | - Reserved Pool : 当有一个 Worker 的 General Pool 内存耗尽,Reserved Pool 将会发挥作用。这个时候 Coordinator 将会选出集群出消耗内存最大的查询,并将该查询分配给所有 Worker 的 Reserved Pool。 105 | 106 | > Reserved Pool 的值等于 query.max-total-memory-per-node 的大小。 107 | > query.max-total-memory-per-node 是单个节点 User memory 和 System memory 占用的最大值。 108 | 109 | 而且 Reserved Pool 是启动时系统预留的,一起动就会占用,所以这里有一个问题,在实际中的情况来讲,我们会极少使用到 Reserved Pool,而且它还占用了很多的内存资源。 110 | 111 | 因为在面向 **即席查询、报表查询、等一些小型查询时** ,很难用到 Reserved Pool 内存池,如果基于中小型查询场景配置查询限制的话,大查询都会先被这些限制给拦截 kill,就更难使用到 Reserved Pool。 112 | 113 | 所以我们可以通过配置参数,禁用 Reserved Pool。如图所示 114 | 115 | config.properties 116 | 117 | ``` 118 | experimental.reserved-pool-enabled=false 119 | ``` 120 | 121 | 效果如下 122 | 123 | ![](vx_images/377375185970357.png) 124 | -------------------------------------------------------------------------------- /05_内存管理/vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2025-01-19T03:08:38Z", 3 | "files": [ 4 | { 5 | "attachment_folder": "", 6 | "created_time": "2025-01-19T03:09:08Z", 7 | "id": "89", 8 | "modified_time": "2025-01-19T03:40:29Z", 9 | "name": "Presto内存池使用调整.md", 10 | "signature": "914462229125688532", 11 | "tags": [ 12 | ] 13 | } 14 | ], 15 | "folders": [ 16 | ], 17 | "id": "88", 18 | "modified_time": "2025-01-19T03:08:38Z", 19 | "signature": "14305649231276043446", 20 | "version": 3 21 | } 22 | -------------------------------------------------------------------------------- /05_内存管理/vx_images/125223250132825.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/05_内存管理/vx_images/125223250132825.png -------------------------------------------------------------------------------- /05_内存管理/vx_images/162264749038547.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/05_内存管理/vx_images/162264749038547.png -------------------------------------------------------------------------------- /05_内存管理/vx_images/167824133273668.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/05_内存管理/vx_images/167824133273668.png -------------------------------------------------------------------------------- /05_内存管理/vx_images/201333515098794.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/05_内存管理/vx_images/201333515098794.png -------------------------------------------------------------------------------- /05_内存管理/vx_images/349954958637476.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/05_内存管理/vx_images/349954958637476.png -------------------------------------------------------------------------------- /05_内存管理/vx_images/377375185970357.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/05_内存管理/vx_images/377375185970357.png -------------------------------------------------------------------------------- /05_内存管理/vx_images/473093398985098.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/05_内存管理/vx_images/473093398985098.png -------------------------------------------------------------------------------- /05_内存管理/vx_images/569313700652337.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/05_内存管理/vx_images/569313700652337.png -------------------------------------------------------------------------------- /05_内存管理/vx_images/575212586114716.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/05_内存管理/vx_images/575212586114716.png -------------------------------------------------------------------------------- /05_内存管理/vx_images/96253836776405.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/05_内存管理/vx_images/96253836776405.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/Connector开发实例_引.md: -------------------------------------------------------------------------------- 1 | # Connector开发实例_引 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | Presto & Trino 得益于优秀的插件思想设计,所以在开发新的数据源 Connector 时会很方便。 8 | 9 | 学习 Connector 开发前,我们可以参考一下官方文档。 10 | 11 | - https://prestodb.io/docs/0.285/develop/connectors.html 12 | - https://trino.io/docs/current/develop/connectors.html 13 | 14 | 早期 Trino 与 Presto 的 Connector 开发还是比较像的,Trino 在后期的版本已经进行了多次迭代,开发方式与 Presto 稍微有点区别了。不会为了了解 Connector 的开发思想我是建议可以先从 Presto 学起。 15 | 16 | 后续的讲解我们先从 Presto 开始,然后再讲解 Trino。 17 | 18 | 19 | ## Presto Connector 的几个基础概念 20 | 21 | 1. **ConnectorSplit**:这是Presto查询执行的基本单位。一个查询被分解成多个任务,每个任务处理一个或多个splits。每个`ConnectorSplit`代表了数据源中的一部分数据,它包含了足够的信息来定位和处理这部分数据。例如,在处理HDFS数据时,一个split可能代表一个文件块。 22 | 23 | 2. **ConnectorFactory**:这是一个工厂类,用于创建Connector实例。Presto使用`ConnectorFactory`来实例化具体的Connector,这个过程通常在Presto启动时完成。每个Connector都需要提供一个`ConnectorFactory`来允许Presto服务器动态加载和配置该Connector。 24 | 25 | 3. **ConnectorMetadata**:这个接口负责处理所有与元数据相关的操作。这包括获取表格、列、数据类型等信息。`ConnectorMetadata`是Presto与数据源之间的主要接口,用于获取关于数据源结构的信息。 26 | 27 | 4. **ConnectorSplitManager**:此组件负责将Presto查询分解成多个splits。`ConnectorSplitManager`根据查询的需求和数据源的特性,决定如何最有效地分割数据。这个过程对于查询性能至关重要。 28 | 29 | 5. **ConnectorRecordSetProvider**:这个接口用于提供对特定split中数据的访问。它负责创建`RecordSet`实例,后者封装了对数据的实际访问。`RecordSet`提供了一种迭代访问split中行数据的方式。 -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/MySQL_Connector/Presto查询Doris问题.md: -------------------------------------------------------------------------------- 1 | # Presto查询Doris问题 2 | 3 | [返回首页](../../../README.md) 4 | 5 | --- 6 | 7 | Doris 与 StarRocks 都是近几年很流行的 OLAP 引擎,但是对于已经基于 Hadoop、Hive、Spark、Flink 等生态构建的数仓体系,想再用上 Doris 一般会增加一些数据同步成本,和数据查询成本(这里的成本不是指性能,而我公司的数据架构体系中的对接、适配成本)。 8 | 9 | 这里暂时不谈彼此之间的优缺点,主要是聊在面向 OLAP 对接各个应用、或者数据平台时的一些问题。 10 | 11 | 比如对接报表平台、查数平台、数据接口服务,早期大概率可能都是 Hive、Presto、Spark、Impala 等对接方式,此时再对接 Doris 时,相当于要多一份 OLAP 对接工作。为了不改动上层应用的对接架构,如果已有 Presto 的情况下对 Connector 进行优化调整是一个性价比不错的方式,这里主要聊一个使用 Presto JDBC Connector 来查询 Doris 的问题。 12 | 13 | 为什么要用 Presto 去对接 Doris,主要还是遗留问题,迁移的工作不可能一下子就能做到全面的割接,都是渐进式的慢慢来,而且对外对接的方式 Hive、Presto、Spark 等等已经迭代了很多年了不会轻易改动,此时再增加一个新的适配,成本是较高的。 14 | 15 | 恰好 Presto 中有 JDBC Connector,经了解和沟通,发现适配好了之后 Presto 查询 Doris 的速度与裸查 Doris 勉强持平,所以去优化调整 Presto JDBC Connector 的成本相较于再适配一种新的 OLAP 引擎要成本低一些。 16 | 17 | 同时我们也可以借这个机会,学习一下 JDBC Connector 的工作流程。 18 | 19 | ## 目前的问题 20 | 21 | 数据量不是很大,在 Doris 中查询可以秒出,但是在 Presto 使用 JDBC Connector 查询则需要 30~40 秒。 22 | 23 | Doris 秒出 24 | 25 | ```sql 26 | doris> select count(*) from doris.audit_log; 27 | +----------+ 28 | | count(*) | 29 | +----------+ 30 | | 1842877 | 31 | +----------+ 32 | 1 rows in set (0.10 sec) 33 | ``` 34 | 35 | ```sql 36 | doris> select client_ip, count(*) as u_cnt from doris.audit_log group by client_ip order by u_cnt desc limit 10; 37 | +----------------------+-------+ 38 | | client_ip | u_cnt | 39 | +----------------------+-------+ 40 | | 10.112.***.***:47146 | 234 | 41 | | 10.112.***.***:45294 | 230 | 42 | | 10.112.***.***:40678 | 228 | 43 | | 10.112.***.***:48544 | 228 | 44 | | 10.112.***.***:49330 | 228 | 45 | | 10.112.***.***:38598 | 226 | 46 | | 10.112.***.***:39542 | 224 | 47 | | 10.112.***.***:56510 | 224 | 48 | | 10.112.***.***:54748 | 222 | 49 | | 10.112.***.***:51016 | 222 | 50 | +----------------------+-------+ 51 | 10 rows in set (0.10 sec) 52 | ``` 53 | 54 | 55 | Presto 中要 30 多秒 56 | 57 | ```sql 58 | presto> select count(*) from doris.audit_log; 59 | count(*) 60 | ----------- 61 | 1842877 62 | 63 | [Latency: client-side: 0:33, server-side: 0:33] [1.84M rows, 0B] [330K rows/s, 0B/s] 64 | ``` 65 | 66 | 67 | ```sql 68 | presto:default> select client_ip, count(*) as u_cnt from doris.audit_log group by client_ip order by u_cnt desc limit 10; 69 | client_ip | u_cnt 70 | ----------------------+------- 71 | 10.112.***.***:47146 | 234 72 | 10.112.***.***:45294 | 230 73 | 10.112.***.***:48544 | 228 74 | 10.112.***.***:49330 | 228 75 | 10.112.***.***:40678 | 228 76 | 10.112.***.***:38598 | 226 77 | 10.112.***.***:39542 | 224 78 | 10.112.***.***:56510 | 224 79 | 10.112.***.***:54748 | 222 80 | 10.112.***.***:51034 | 222 81 | (10 rows) 82 | 83 | [Latency: client-side: 0:06, server-side: 0:06] [1.84M rows, 0B] [330K rows/s, 0B/s] 84 | ``` 85 | 86 | 查看具体 Stage 可以发现, 输入的 Rows 是 1.84M 正好与 count(*) 的 1842877 差不多,可以理解是将数据都读到 Presto 中进行计算了,没有进行下推。 87 | 88 | ![](vx_images/7373226141508.png) 89 | 90 | 91 | ## 我们先看看 presto 投递到 doris中变成什么样了 92 | 93 | ### group by 测试 94 | 95 | 变成查询对应 group by 那一列的所有数据 96 | 97 | ```sql 98 | presto> select client_ip, count(*) as u_cnt from doris.audit_log group by client_ip order by u_cnt desc limit 10; 99 | ``` 100 | 101 | ```sql 102 | doris: SELECT `client_ip` FROM `doris`.`audit_log`/* **** : 20240128_082015_00011_mv9mr */ 103 | ``` 104 | 105 | ### limit 测试 106 | 107 | 变成查询对应表的所有数据 108 | 109 | ```sql 110 | presto> select * from doris.audit_log limit 1; 111 | ``` 112 | 113 | ```sql 114 | doris: SELECT 所有的字段 FROM `doris`.`audit_log`/* **** : 20240128_083051_00013_mv9mr */ 115 | ``` 116 | 117 | ### distinct 测试 118 | 119 | 变成查询 distinct 那一列的所有数据 120 | 121 | ```sql 122 | presto> select distinct(client_ip) from doris.audit_log limit 10; 123 | ``` 124 | 125 | ```sql 126 | doris: SELECT `client_ip` FROM `doris`.`audit_log`/* ares : 20240128_084002_00015_mv9mr */ 127 | ``` 128 | 129 | ### Presto -> JDBC -> Doris 的转变 130 | 131 | 可以判断,JDBC Connector 这块是先查出来所有数据,然后在 Presto 进行计算,没有下推或者说下推的逻辑需要调整。 132 | 133 | (可能是为了方便跨数据源 JOIN 所以这里在读数据的时候,不会做什么操作) 134 | 135 | 经过验证发现,GROUP BY,COUNT,ORDER BY,LIMIT,DISTINCT,这些常用算子也没下推下去。 136 | 137 | 接下来我们来看看 Presto JDBC Connector 的相关实现。 138 | 139 | ## JDBC Connector 解析 140 | 141 | Presto JDBC Connector 的 Plugin 相当比较简单,源码布局如下。 142 | 143 | ![](vx_images/540439154554415.png) 144 | 145 | 大部分 JDBC 的相关逻辑都在 MySqlClient 中,比如 创建表,查看表,字段改名字等。 146 | 147 | ![](vx_images/450269133345092.png) 148 | 149 | 在 MySql Connector 中只是重写了部分逻辑,JDBC 的所有基础操作,都在 BaseJdbcClient 中定义了 150 | 151 | ![](vx_images/142851698664281.png) 152 | 153 | ![](vx_images/299964170707723.png) 154 | 155 | 156 | ### 发现已有的下推 157 | 158 | ![](vx_images/28334435254105.png) 159 | 160 | 对应的 SQL 变化如下: 161 | 162 | ```sql 163 | presto> select client_ip,scan_rows from doris.audit_log where client_ip = '10.112.***.***:45690' limit 10; 164 | ``` 165 | 166 | ```sql 167 | doris: SELECT `client_ip`, `scan_rows` FROM `doris`.`audit_log` WHERE (`client_ip` = '10.112.***.***:45690')/* ares : 20240128_094150_00018_mv9mr */ 168 | ``` 169 | 170 | ## Trino 测试 171 | 172 | ### limit 测试 173 | 174 | 此时我们换过来,看看 Trino 这边是怎么进行转换的 175 | 176 | ```sql 177 | trino> select * from doris_test.*** limit 10; 178 | ``` 179 | 180 | ```sql 181 | doris: SELECT `deal_id`, `order_id`, `payment_number`, `course_id`, `sku_id`, `business_type`, `business_brand`, `primary_classification`, `secondary_classification`, `business_type_name`, `user_tag`, `belong_type`, `paid_time`, `current_time`, `status`, `buyer_amount`, `is_third_party_order`, `third_party_paid_amount` FROM `doris_test`.`***` LIMIT 10 182 | ``` 183 | 184 | 发现下推了,只读了 10 行数据。 185 | 186 | ![](vx_images/472563957777770.png) 187 | 188 | ### group by 测试 189 | 190 | ```sql 191 | presto> select client_ip, count(*) as u_cnt from doris.audit_log group by clinet_ip order by u_cnt desc limit 10; 192 | ``` 193 | 194 | 这里聚合没有下推,但是投影下推了,相当于扫描了一整列的数据进来。 195 | 196 | ```sql 197 | trino: SELECT `client_ip` FROM `doris`.`audit_log`; 198 | ``` 199 | 200 | ![](vx_images/588512825411602.png) 201 | 202 | ### distinct 测试 203 | 204 | ```sql 205 | trino> select distinct(client_ip) from doris.audit_log limit 10; 206 | ``` 207 | 208 | 发现只下推了投影 209 | 210 | ```sql 211 | doris: SELECT `business_brand` FROM `doris`.`audit_log`; 212 | ``` 213 | 214 | ![](vx_images/112696284700215.png) 215 | 216 | ### Trino JDBC 相关源码 217 | 218 | trino 中的 group by 下推相关实现 219 | 220 | ![](vx_images/346753032407151.png) 221 | 222 | 223 | ## 下推实现验证 224 | 225 | ### distinct 226 | 227 | 228 | 229 | ### aggregate 230 | 231 | 232 | 233 | ### limit 234 | 235 | 236 | 237 | ### cast 238 | 239 | 240 | 241 | ### date 242 | 243 | 244 | 245 | ## 参考 246 | 247 | - https://github.com/trinodb/trino/issues/17329 248 | - https://github.com/trinodb/trino/issues/8653 249 | - https://github.com/myfjdthink/trino-doris-demo 250 | - https://github.com/footprintanalytics/trino 251 | 252 | 253 | 254 | 打开的代码 255 | 256 | - com.facebook.presto.plugin.jdbc.JdbcClient 257 | - com.facebook.presto.plugin.jdbc.BaseJdbcClient 258 | - com.facebook.presto.plugin.jdbc.QueryBuilder 259 | - com.facebook.presto.plugin.jdbc.JdbcMetadata 260 | - com.facebook.presto.plugin.jdbc.optimization.JdbcComputePushdown -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/MySQL_Connector/vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2024-01-26T14:12:26Z", 3 | "files": [ 4 | { 5 | "attachment_folder": "", 6 | "created_time": "2024-01-28T06:26:43Z", 7 | "id": "51", 8 | "modified_time": "2024-02-26T13:26:31Z", 9 | "name": "Presto查询Doris问题.md", 10 | "signature": "1807319972120490915", 11 | "tags": [ 12 | ] 13 | } 14 | ], 15 | "folders": [ 16 | ], 17 | "id": "48", 18 | "modified_time": "2024-01-26T14:12:26Z", 19 | "signature": "812231785427746250", 20 | "version": 3 21 | } 22 | -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/MySQL_Connector/vx_images/112696284700215.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/MySQL_Connector/vx_images/112696284700215.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/MySQL_Connector/vx_images/142851698664281.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/MySQL_Connector/vx_images/142851698664281.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/MySQL_Connector/vx_images/28334435254105.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/MySQL_Connector/vx_images/28334435254105.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/MySQL_Connector/vx_images/299964170707723.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/MySQL_Connector/vx_images/299964170707723.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/MySQL_Connector/vx_images/346753032407151.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/MySQL_Connector/vx_images/346753032407151.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/MySQL_Connector/vx_images/450269133345092.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/MySQL_Connector/vx_images/450269133345092.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/MySQL_Connector/vx_images/472563957777770.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/MySQL_Connector/vx_images/472563957777770.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/MySQL_Connector/vx_images/540439154554415.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/MySQL_Connector/vx_images/540439154554415.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/MySQL_Connector/vx_images/588512825411602.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/MySQL_Connector/vx_images/588512825411602.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/MySQL_Connector/vx_images/7373226141508.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/MySQL_Connector/vx_images/7373226141508.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/Presto如何实现查询下推_初探.md: -------------------------------------------------------------------------------- 1 | # Presto如何实现查询下推_引 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | ## 参考 8 | 9 | 我们先参考其他 Connector 中的大概代码布局,发现大部分 Connector 中,都有一个 optimizer 的相关实现,参考发现,相关的查询优化逻辑大部分都是在这里面来实现。 10 | 11 | 这里需要明确,到这一步的时候 SQL 已经经过 Presto 核心的一些相关优化了,这里面属于对应 Connector 的专属优化。 12 | 13 | 以接下来要举的例子,比如我的查询在 Presto Coordinator 中已经完成了优化,但是谓词下推的优化还不能正常推到对应的引擎中(Redis、Clickhouse、以及 Paimon 等,简单举例,如果不下推下去的话,就相当于把所有的数据都查到 Presto 中,然后在 Presto 引擎中再去过滤、计算等等),此时需要就查询计划按照对应引擎允许下推的方式重新优化。 14 | 15 | (注意!这里跟包名没关系,只是约定都使用 optimizer 等) 16 | 17 | ![](vx_images/243215420747870.png) 18 | 19 | 20 | ## 关键接口 21 | 22 | Presto 中,需要实现 ConnectorPlanOptimizerProvider 接口,即可完成对应 Connector 的查询计划的逻辑优化与物理优化。 23 | 24 | 我们实现对应的查询优化即完成前面说的下推,这里我们可以先思考一个问题,是在逻辑优化中实现,还是在物理优化中实现呢,而且看了 Presto 源码中其他引擎的 Connector 的优化时,在逻辑优化与物理优化的实现中都有,那么它们的区别是什么呢? 25 | 26 | ```java 27 | public interface ConnectorPlanOptimizerProvider 28 | { 29 | /** 30 | * The plan optimizers to be applied before having the notion of distribution. 31 | */ 32 | Set getLogicalPlanOptimizers(); 33 | 34 | /** 35 | * The plan optimizers to be applied after having the notion of distribution. 36 | * The plan will be only executed on a single node. 37 | */ 38 | Set getPhysicalPlanOptimizers(); 39 | } 40 | 41 | ``` 42 | 43 | ## 关键实现 44 | 45 | 参考其他的优化实现中发现,大部分都是对入参的 PlanNode 进行 visit 操作,流程则用以下伪代码表示: 46 | 47 | ```java 48 | public class PrestoComputePushdown implements ConnectorPlanOptimizer { 49 | ... 50 | ... 51 | 52 | @Override 53 | public PlanNode optimize(...) {...} 54 | 55 | 56 | private class Visitor extends PlanVisitor { 57 | ... 58 | 59 | @Override 60 | public PlanNode visitFilter(...) {...} 61 | 62 | @Override 63 | public PlanNode visitAggregation(...) {...} 64 | 65 | ... 66 | } 67 | } 68 | ``` 69 | 70 | 关键的优化操作,就在比如 visitFilter、visitAggregation 等相关方法实现,根据方法名的不同我们可以发现是对不同的场景进行专属优化,比如有过滤、聚合、投影、TopK、去重等等。 71 | 72 | 了解更多的信息,可以参考相关接口源码 `com/facebook/presto/spi/plan/PlanVisitor.java`。 73 | 74 | 75 | ## 下推实现思路 76 | 77 | 以最近实现的 presto-paimon-connector 的例子举例,详情代码如下: 78 | 79 | [PrestoComputePushdown.java](https://github.com/apache/incubator-paimon-presto/blob/main/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoComputePushdown.java) 80 | 81 | 这里就不贴代码了,主要来讲几个实现中的关键点。 82 | 83 | ### 构造方法 84 | 85 | 在构建优化时,会根据我们的需要初始化一个辅助工具。比如在我们这个优化中,就用到了 StandardFunctionResolution 和 RowExpressionService。 86 | 87 | - StandardFunctionResolution 是一个服务接口,它在Presto中用于处理与函数解析相关的操作。在SQL查询和表达式处理中,经常需要对函数(如聚合函数、数学函数、字符串函数等)进行解析和处理。 88 | - RowExpressionService 是另一个关键服务,它在处理行表达式(Row Expressions)时发挥作用。行表达式是Presto内部用于表示列、常量、函数调用等的一种结构。在查询计划中,几乎所有的操作(如过滤、投影、聚合等)都可以表示为对行表达式的操作。 89 | 90 | ### 入口方法 optimize 91 | 92 | 谓词下推,也算是查询计划优化的一种,所以我们在继承 ConnectorPlanOptimizer 接口后,需要实现 optimize 方法它就是我们查询计划优化的入口。 93 | 94 | 通过也会进行参数相关的联动配置,比如我根据 Session 中的配置来随时控制是否开启这个优化等等,都可以在这个入口方法中进行,起到筛选,优化准备,的一些操作。 95 | 96 | 核心就在 optimize 方法的四个入参。 97 | 98 | 1. PlanNode maxSubplan,代表当前正在优化的查询计划的一部分或整个查询计划; 99 | 2. ConnectorSession session,当前查询会话的上下文信息。这包括用户身份、时区、语言设置、会话特定的配置和属性; 100 | 3. VariableAllocator variableAllocator,负责分配和管理查询计划中使用的变量。在构建或修改查询计划时,可能需要创建新的变量; 101 | 4. PlanNodeIdAllocator idAllocator,负责为查询计划中的每个节点分配唯一的标识符(ID)。每个 PlanNode 在查询计划中都有一个唯一的ID,以区分不同的节点; 102 | 103 | ### 开始优化 104 | 105 | 优化主要是对 PlanNode 进行操作,所以优化的思路可以按照 Parser 的 Visitor 模型来理解,核心就是找到 Node 然后进行各种操作。 106 | 107 | 操作的方式一般分为两种,可能还有其他的技法,我目前只发现了两种。 108 | 109 | #### PlanNode 中的 accept 方式 110 | 111 | 在 Presto 中解析 SQL 后,执行计划会使用 PlanNode 抽象类来表示 SQL 中的各个节点。 112 | 113 | 先用我简单的理解描述一下这个方法,accept 方法就是访问者设计模式(Visitor Pattern)的一部分。这种模式在处理对象结构(如树或图)时非常有用,特别是当你需要对这些结构进行操作或遍历时。一般我们的查询计划都是一个树形结构,所以我们经常要在树中遍历,迭代,此时 accept 方法就特别管用,因为它每个节点都可以接受一个访问者并将其传递给其子节点。 114 | 115 | 同时,我们有时候可能只是想到达某个节点,因为树形结构的特性,我们没法一把子直接就能搂到某个节点(这里需要有点解析器,解析SQL到AST的知识,如果不理解可以先补补),此时我们也可以通过访问者模式,在不修改节点类的情况下,到达某个节点然后进行节点的新增、修改、改写等等操作。 116 | 117 | 更重要的一点,就是解耦了数据结构的操作,因为这样的方式允许将数据结构(如查询计划树)与对它们的操作(如优化、转换)解耦。这样,可以在不改变节点类的情况下添加新的操作,大部分 SQL 都会这样来做优化。 118 | 119 | 此时我们再看下面的方法源码,就好理解了。 120 | 121 | ```java 122 | @Override 123 | public PlanNode optimize( 124 | PlanNode maxSubplan, 125 | ConnectorSession session, 126 | VariableAllocator variableAllocator, 127 | PlanNodeIdAllocator idAllocator) { 128 | if (isPaimonPushdownEnabled(session)) { 129 | return maxSubplan.accept(new Visitor(session, idAllocator), null); 130 | } 131 | return maxSubplan; 132 | } 133 | 134 | ... 135 | ... 136 | ... 137 | 138 | /** 139 | * The basic component of a Presto IR (logic plan). 140 | * An IR is a tree structure with each PlanNode performing a specific operation. 141 | */ 142 | public abstract class PlanNode { 143 | ... 144 | ... 145 | 146 | /** 147 | * A visitor pattern interface to operate on IR. 148 | */ 149 | public R accept(PlanVisitor visitor, C context) { return visitor.visitPlan(this, context); 150 | 151 | ... 152 | ... 153 | } 154 | 155 | ``` 156 | 157 | ![](vx_images/570733136434351.png) 158 | 159 | #### 计划重写 ConnectorPlanRewriter 抽象类方式 160 | 161 | 经过前面的介绍,我们知道核心就是要遍历 PlanNode 然后进行优化。此时我们在看看另外一种实现: 162 | 163 | ```java 164 | public PlanNode optimize( 165 | PlanNode maxSubplan, 166 | ConnectorSession session, 167 | VariableAllocator variableAllocator, 168 | PlanNodeIdAllocator idAllocator) 169 | { 170 | return rewriteWith(new Rewriter(session, idAllocator), maxSubplan); 171 | } 172 | ``` 173 | 174 | 这个 rewriteWith 方法是什么呢?对应源码在这 `src/main/java/com/facebook/presto/spi/ConnectorPlanRewriter.java`,我这里就不贴代码了。感兴趣的可以自己去看。 175 | 176 | 我讲一些个人的简单薄见:核心都是用 accept 方法去迭代,只是 ConnectorPlanRewriter.rewriteWith 计划重写方法提供了一些默认实现,相当于提供了一个通用的重写框架,简化了遍历和修改的操作,实现会削微简单一些。 177 | 178 | ### 一个疑问 179 | 180 | 比如我现在要优化 `select * from where a=1;` 这个 a=1 能下推到对应引擎或存储中去,而不是全搂到 Presto 进行,这算什么优化呢?对应 visit 方法的时候,是什么呢? 181 | 182 | 183 | ### 优化实现 184 | 185 | 基于以上的疑问, 186 | 187 | 188 | ![](vx_images/233241964004846.png) -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2024-01-21T03:09:31Z", 3 | "files": [ 4 | { 5 | "attachment_folder": "", 6 | "created_time": "2024-01-21T03:09:56Z", 7 | "id": "43", 8 | "modified_time": "2024-03-31T14:31:58Z", 9 | "name": "Presto如何实现查询下推_初探.md", 10 | "signature": "8877746957870467844", 11 | "tags": [ 12 | ] 13 | }, 14 | { 15 | "attachment_folder": "", 16 | "created_time": "2024-01-21T05:54:04Z", 17 | "id": "42", 18 | "modified_time": "2024-03-31T14:32:04Z", 19 | "name": "Connector开发实例_引.md", 20 | "signature": "10936665957865402748", 21 | "tags": [ 22 | ] 23 | }, 24 | { 25 | "attachment_folder": "", 26 | "created_time": "2024-03-01T04:05:13Z", 27 | "id": "58", 28 | "modified_time": "2024-03-31T14:23:42Z", 29 | "name": "Presto从零开始实现一个Connector_实现流程简述与测试.md", 30 | "signature": "4787260430611469305", 31 | "tags": [ 32 | ] 33 | } 34 | ], 35 | "folders": [ 36 | { 37 | "name": "MySQL_Connector" 38 | } 39 | ], 40 | "id": "40", 41 | "modified_time": "2024-01-21T03:09:31Z", 42 | "signature": "7262547501741017835", 43 | "version": 3 44 | } 45 | -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/103812835133576.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/103812835133576.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/113044116688597.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/113044116688597.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/150445588440189.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/150445588440189.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/165077840121458.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/165077840121458.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/17993029250787.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/17993029250787.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/189124992113409.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/189124992113409.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/233241964004846.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/233241964004846.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/233611925225585.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/233611925225585.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/243215420747870.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/243215420747870.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/323934992254238.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/323934992254238.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/338441007492207.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/338441007492207.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/338715229328626.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/338715229328626.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/400115072668379.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/400115072668379.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/416574004462281.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/416574004462281.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/485238248503811.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/485238248503811.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/528542034279598.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/528542034279598.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/570733136434351.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/570733136434351.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/577035145173827.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/577035145173827.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/585734692142966.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/585734692142966.png -------------------------------------------------------------------------------- /07_插件思想/Connector开发实例/vx_images/63885543587549.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/07_插件思想/Connector开发实例/vx_images/63885543587549.png -------------------------------------------------------------------------------- /07_插件思想/vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2024-01-21T03:08:39Z", 3 | "files": [ 4 | ], 5 | "folders": [ 6 | { 7 | "name": "Connector开发实例" 8 | } 9 | ], 10 | "id": "62", 11 | "modified_time": "2024-01-21T03:08:39Z", 12 | "signature": "16666483494182750903", 13 | "version": 3 14 | } 15 | -------------------------------------------------------------------------------- /08_运维与监控/Presto排查Worker宕机问题_缓存与内存问题排查_上.md: -------------------------------------------------------------------------------- 1 | # Presto排查Worker宕机问题_缓存与内存问题排查_上 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | ## 现象 8 | 9 | 近期有出现 Presto worker 挂掉的情况,K8s 里有看到重新启动的事件。 10 | 11 | ![](vx_images/182562213493958.png) 12 | 13 | 因为是 k8s 部署的 presto 环境,可以看到最后 pod 挂掉的日志,如下: 14 | 15 | ``` 16 | 2024-07-10T10:26:32.414+0800 ERROR 20240710_022631_00635_3qevr.1.0.32-111-56 17 | 18 | alluxio.client.file.cache.NoExceptionCacheManager 19 | Failed to get page PageId 20 | {ileId=8ac79973285671fa729d832614afaf50, PageIndex=5}, 21 | offset 0 cacheContext 22 | CacheContext{ 23 | cacheIdentifier=null, 24 | cacheQuota=alluxio.client.quota.CacheQuota$1@1f, 25 | cacheScope=CacheScope{id=.}, 26 | hiveCacheContext=null, 27 | isTemporary=false 28 | } 29 | 30 | ... 31 | ... 32 | ... 33 | 34 | java.lang.RuntimeException: java.lang.InterruptedException 35 | at alluxio.client.file.cache.TimeBoundPageStore.get(TimeBoundPageStore.java:101) 36 | at alluxio.client.file.cache.LocalCacheManager.getPage(LocalCacheManager.java:711) 37 | at alluxio.client.file.cache.LocalCacheManager.get(LocalCacheManager.java:503) 38 | at alluxio.client.file.cache.CacheManagerWithShadowCache.get(CacheManagerWithShadowCache.java:67) 39 | at alluxio.client.file.cache.NoExceptionCacheManager.get(NoExceptionCacheManager.java:105) 40 | at alluxio.client.file.cache.LocalCacheFileInStream.localCachedRead(LocalCacheFileInStream.java:186) 41 | at alluxio.client.file.cache.LocalCacheFileInStream.bufferedRead(LocalCacheFileInStream.java:144) 42 | at alluxio.client.file.cache.LocalCacheFileInStream.readInternal(LocalCacheFileInStream.java:242) 43 | at alluxio.client.file.cache.LocalCacheFileInStream.positionedRead(LocalCacheFileInStream.java:287) 44 | 45 | ... 46 | ... 47 | ... 48 | 49 | 2024-07-10T11:13:37.231+0800 ERROR 20240710_031333_01407_3qevr.16.0.1-2-91 alluxio.client.file.cache.NoExceptionCacheManager Failed to get page PageId{FileId=3b71d14bcc5c6ff6af8afdff1243b676, PageIndex=381}, offset 530484 cacheContext CacheContext{cacheIdentifier=null, cacheQuota=alluxio.client.quota.CacheQuota$1@1f, cacheScope=CacheScope{id=.}, hiveCacheContext=null, isTemporary=false} 50 | java.lang.RuntimeException: java.lang.InterruptedException 51 | at alluxio.client.file.cache.TimeBoundPageStore.get(TimeBoundPageStore.java:101) 52 | at alluxio.client.file.cache.LocalCacheManager.getPage(LocalCacheManager.java:711) 53 | at alluxio.client.file.cache.LocalCacheManager.get(LocalCacheManager.java:503) 54 | at alluxio.client.file.cache.CacheManagerWithShadowCache.get(CacheManagerWithShadowCache.java:67) 55 | at alluxio.client.file.cache.NoExceptionCacheManager.get(NoExceptionCacheManager.java:105) 56 | 57 | ... 60 more 58 | 59 | 60 | java.lang.OutOfMemoryError: Java heap space 61 | Dumping heap to java_pid7.hprof ... 62 | Heap dump file created [38170670829 bytes in 61.779 secs] 63 | Terminating due to java.lang.OutOfMemoryError: Java heap space 64 | ``` 65 | 66 | 从上述日志可以看出几个关键问题: 67 | 68 | 1. 首先出现了缓存读取异常: 69 | - Alluxio 缓存管理器无法获取页面数据 70 | - 抛出了 InterruptedException 异常 71 | - 这表明在读取缓存数据时被中断 72 | 2. 最终导致进程崩溃的是内存溢出: 73 | - 出现 Java heap space OOM 错误 74 | - 生成了约 38GB 大小的堆转储文件 75 | - 这说明 JVM 堆内存已经耗尽 76 | 3. 流程理解: 77 | - 从缓存读取异常到最终 OOM 78 | - 可能是由于缓存读取失败导致数据积压在内存中 79 | - 或者是在处理缓存异常时消耗了过多内存 80 | 81 | 这个错误初步最开始的信息看着像 Alluxio 无法获取缓存数据,但是其实是因为内存不足而导致的 OOM,引发的 Worker 宕机。 82 | 83 | 我们再继续查看 K8s 的 Pod 信息,发现确实在 11:22:39 这个时间点左右重新启动了一次。 84 | 85 | ``` 86 | Namespace: presto 87 | 88 | *** 89 | *** 90 | *** 91 | 92 | Start Time: Wed, 12 Jun 2024 19:35:44 +0800 93 | 94 | *** 95 | *** 96 | *** 97 | 98 | Containers: 99 | 100 | *** 101 | *** 102 | *** 103 | *** 104 | State: Running 105 | Started: Wed, 10 Jul 2024 11:22:39 +0800 106 | Last State: Terminated 107 | Reason: Error 108 | Exit Code: 3 109 | Started: Tue, 25 Jun 2024 16:05:54 +0800 110 | Finished: Wed, 10 Jul 2024 11:22:36 +0800 111 | Ready: True 112 | Restart Count: 3 113 | ``` 114 | 115 | ## 缓存问题思考 116 | 117 | 因为在错误日志里,看到有 `alluxio.client.file.cache.NoExceptionCacheManager Failed to get page` 等相关信息,初步是缓存空间问题,比如空间用满了没有正常换入换出导致程序挂掉。 118 | 119 | (但是仔细一想,空间不够应该是会持续报错,不至于会导致挂掉,所以暂时排除了这个想法) 120 | 121 | 这里是目前的缓存配置 122 | ``` 123 | # data 124 | cache.enabled=true 125 | cache.type=ALLUXIO 126 | cache.base-directory=file:///presto_cache/data 127 | cache.validation-enabled=false 128 | cache.alluxio.max-cache-size=2900GB 129 | ``` 130 | 131 | 因为是挂了 pv pvc 来当做缓存磁盘使用,查看对应物理机的磁盘监控没有用满的情况,最后的峰值还有 500G 的空闲空间。 132 | 133 | 下图的500多G是磁盘空闲空间,后面上涨到3.2T左右是代表有 POD 重启了,释放了磁盘空间。 134 | 135 | ![](vx_images/446733109044162.png) 136 | 137 | 如果假设缓存有问题,那么应该查看它的换入换出监控,如果只有进没有出的,那就可能是缓存有问题。 138 | 139 | Worker 的缓存空间配置的是 2.83T 使用,磁盘是有约 3.5T,查看对应挂掉 pod 的换入换出监控,发现是有正常的换入换出的,并且缓存空间最高才使用到 2.73T,还远远没有达到上限。 140 | 141 | ![](vx_images/421473603187620.png) 142 | 143 | 所以,可以排除是缓存空间问题。这里指的缓存空间问题,主要是指,缓存把磁盘空间用满了,触发了 K8s 的驱逐的问题。 144 | 145 | > 这里补充一下,为什么会有这个怀疑,因为当前维护的集群早期会经常有磁盘空间不够 K8s 把 Pod 驱除而出现的 Worker 挂掉的情况,所以会往这个方面怀疑。 146 | 147 | ## 内存问题思考 148 | 149 | 所以我们应该从日志的最后一个信息入手排查问题,可是这里有个尴尬的地方,没有配置 K8s 的相关转储配置,所以每次 OOM 挂掉后,即使生产了 dump 文件,就没真正的存下来。(算是一个技术债,后续会调整) 150 | 151 | ``` 152 | java.lang.OutOfMemoryError: Java heap space 153 | Dumping heap to java_pid7.hprof ... 154 | Heap dump file created [38170670829 bytes in 61.779 secs] 155 | Terminating due to java.lang.OutOfMemoryError: Java heap space 156 | ``` 157 | 158 | 接下来只能从其他角度入手分析,首先说一下 Presto Worker 在 K8s 环境中部署的内存配置 159 | 160 | 内存配置如下: 161 | 162 | - Pod 内存 request limit 均配置的 112G 163 | - Presto Worker 堆内存配置的 72G 164 | - Presto Worker Memory Pools 由默认的两个缩减为一个 General Pool 配置为 53G 165 | 166 | Pod 层面的内存使用 167 | 168 | ![](vx_images/526897444981667.png) 169 | 170 | ![](vx_images/266777817527765.png) 171 | 172 | ![](vx_images/464116987726505.png) 173 | 174 | 首先从 container_memory_usage_bytes 角度来看,就是内存用超过 112G 然后 OOM 挂掉了。 175 | 176 | ![](vx_images/359324008851148.png) 177 | 178 | 179 | Presto Worker 应用层面的内存使用 180 | 181 | 查看当时应用层面的监控,内存池和堆内存的余量都比较充足。 182 | 183 | 内存池是直接发生了采集中断,堆内存是使用了 26G 然后也中断 (可以判断为因为 Worker 挂了,所以监控数据没有采集到) 184 | 185 | ![](vx_images/45993249790558.png) 186 | 187 | 因为这个 pod 的应用采集数据不太明显,我们再看另外一个的,可以明显发现,内存池用光,堆内存用满,然后也是会出现监控中断,挂掉的情况。 188 | 189 | ![](vx_images/108107182762118.png) 190 | 191 | 查阅 K8s 文档,可以知道,内存的监控指标含义如下。 192 | 193 | ``` 194 | container_memory_cache 表示容器使用的缓存内存。 195 | container_memory_mapped_file 表示容器使用的映射文件内存。 196 | container_memory_rss 表示容器的常驻内存集(Resident Set Size),即实际使用的物理内存量。 197 | container_memory_swap 表示容器使用的交换内存量。 198 | container_memory_usage_bytes 表示容器当前使用的内存量,包括常驻内存和缓存,**缓存部分往往会有很多处于空闲**。 199 | container_memory_working_set_bytes 表示容器的工作集,即容器当前活跃使用的内存量,不包括缓存。 200 | container_memory_max_usage_bytes 表示容器历史上使用过的最大内存量。 201 | container_memory_failcnt 表示容器内存失败计数,即无法分配所需内存的次数。 202 | container_memory_failures_total 表示容器内存分配失败的总次数。 203 | ``` 204 | 205 | 从以上 pod 内存监控来看。在对应宕机的时间点前后 206 | 207 | - container_memory_rss 81.0G` 208 | - container_memory_cacahe 31.3G 209 | 210 | 这2个内存加起来,可以理解为我container使用的内存,81.6+34.9=116.5 超过了 pod 的 112 G,所以可以判断为是内存不足导致的挂掉。 211 | 212 | ## 初步问题结论 213 | 214 | 当给 Presto 开启了缓存使用后,相当于将 Presto 由原来的只读类型 OLAP 引擎 (我们自身业务限定,Presto 只定位查询,Hive 和 SparkSQL 负责写),改为 `读` `写` 类型OLAP 引擎。 215 | 216 | 在 K8s 环境中,会出现又读又写的场景,此时会大量使用 page cache,因为一个 Pod 只有100多G,Worker 的堆内存值有 72G,相当于留给 Pod 的 PageCache 也就在 30G 左右的范围,同时 Presto 的查询结果返回,与查询缓存输入写入,都是同步操作,所以 PageCache 会容易出现短暂的高峰使用,然后引发内存不足导致 Pod 被驱逐。 217 | 218 | 219 | ## 后续TODO 220 | 221 | 1. 为什么会出现 Alluxio 缓存读取异常 222 | 2. 为什么 JVM 堆内存监控显示使用正常,但最终还是出现了 OOM 223 | 3. 是否存在内存泄漏的可能 224 | 4. 一个pod中,Pagecache的可用阈值多少是合理的 -------------------------------------------------------------------------------- /08_运维与监控/Presto的Worker为什么会挂掉.md: -------------------------------------------------------------------------------- 1 | # Presto的Worker为什么会挂掉 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | 8 | ## 背景 9 | 10 | 平常在维护 Presto 集群时,经常会出现跑了某个 SQL 后会挂掉一个或多个 Worker,因为 Presto MPP 架构的特性,与这个 Worker 相关的 SQL 都会挂掉。 11 | 12 | 正好这里有一次类似的情况,借着这次问题的排查,我们一起学习一下 Presto 的 Worker 为什么会挂掉,以及锻炼排查问题的能力。 13 | 14 | ### 线索1 频繁出现 INTERNAL_ERROR 错误 15 | 16 | 这里有代表性的错误,但全是这个错误,但还有其他错误。 17 | 18 | ![](vx_images/122008214091069.png) 19 | 20 | 对应错误信息。 21 | 22 | ``` 23 | com.facebook.presto.spi.PrestoException: Could not communicate with the remote task. The node may have crashed or be under too much load. This is probably a transient issue, so please retry your query in a few minutes. 24 | at com.facebook.presto.server.remotetask.ContinuousTaskStatusFetcher.updateTaskStatus(ContinuousTaskStatusFetcher.java:290) 25 | at com.facebook.presto.server.remotetask.ContinuousTaskStatusFetcher.success(ContinuousTaskStatusFetcher.java:218) 26 | at com.facebook.presto.server.remotetask.ContinuousTaskStatusFetcher.success(ContinuousTaskStatusFetcher.java:67) 27 | ``` 28 | 29 | ### 线索2 Worker 频繁重启 30 | 31 | ![](vx_images/331359308530647.png) 32 | 33 | ### 线索3 查询量上升 34 | 35 | 观察核心监控数据,确实有点像异常情况,这里思考一下是真的查询量暴涨了,还是异常了呢? 36 | 37 | ![](vx_images/211956587286804.png) 38 | 39 | ## 提出假设 40 | 41 | - 往好的方面想,就是查询量比较大 42 | - 往坏的方面想,是有异常SQL 43 | 44 | ## 验证假设 45 | 46 | 如何来验证这些假设呢? 47 | 48 | 可以查看一下 `成功率`,是不是降低了,如果是降低了那证明有异常的 SQL。 49 | 50 | 然后看一下 `错误查询分类` 都在频繁出现了哪些错误。 51 | 52 | > 这个假设是事后想的了,当时在解决这个问题的时候,我没有这样想,当时的思路有点懵逼,没有冷静。 53 | > 同时也可以想想,这个假设流程有没有 `问题` ? 54 | 55 | 56 | ### 查看成功率 57 | 58 | ![](vx_images/432332157473058.png) 59 | 60 | ### 查看错误分类 61 | 62 | ![](vx_images/181821876458722.png) 63 | 64 | 65 | ## 第一次假设结论 66 | 67 | 成功率大幅度下降,而且一些平常不怎么出现的错误,也是往常的几百甚至上千倍量,比如 REMOTE_TASK_MISMATCH,REMOTE_TASK_ERROR 这些错误,都可以理解为,`集群不稳定,比如 Worker 挂掉了,在这个 Worker 中的所有查询都会挂掉`。 68 | 69 | ## 再次假设 70 | 71 | 假设是某些异常 SQL 导致的,我该如何排查呢? 72 | 73 | 我们知道,比如某个 Worker 因为这类问题挂掉,在 Worker 中所有查询都会受影响,而且挂掉的 SQL 会出现同样的错误,Presto 在这里不会明确指出来是因为某某 SQL 的什么问题导致 Worker 挂掉的。 74 | 75 | 我当时的想法是,继续查看 UI 上的实时监控和 Worker 的监控,看看有不有什么线索。 76 | 77 | ### UI 实时监控 78 | 79 | UI 中因为的查询量很大,至少有往常的 10~20 倍,一直盯着看确实没看出明确的线索。 80 | 81 | 唯一看到的线索就是 `有 SQL,算到某个百分比后,大家都卡着不动,然后会挂掉一些 Worker,紧接着一些 SQL 又失败掉,如此反复`,只是这个现象反复,但是还没找到很明确的 SQL。 82 | 83 | ### Worker 监控 84 | 85 | Worker 的监控中发现,跑的 SQL 很多,但 CPU 用的不多,内存却用的很满。 86 | 87 | 从使用趋势来看,内存有随时用满的情况。 88 | 89 | > 从这里的现象来看,也比较符合 SQL 查询比较多的情况,此时还没有明确往其他方向想。 90 | 91 | ![](vx_images/448300047956477.png) 92 | 93 | 94 | ## 暂停思考一下 95 | 96 | 根据前面的线索,其实排查到这思路已经是懵逼状态了,目前是知道有异常的SQL,但是没有找到问题的根源。 97 | 98 | 而且我前面的各种排查与假设,都是有一种过拟合的情况,比如根据错误分类判断问题,发现这种方式是禁不起考验的 `比如某个错误分类出现的次数较多,它有可能是被影响的结果,不一定是问题的原因`,错误分类它也是一个排查问题的方向,但是对于目前的问题,它不具备 `直接证明` 的能力,如果继续使用这种方式排查问题,只会加重误导自己。 99 | 100 | ``` 101 | 102 | 103 | 104 | 如果是你碰到了这个情况,你会怎么思考和排查这个问题呢? 105 | 106 | 107 | 108 | 应该使用哪个指标,或者什么方式来 直接证明 问题呢? 109 | 110 | 111 | 112 | ``` 113 | 114 | ## 最后排查 Worker 挂掉的原因 115 | 116 | **经过讨论和沟通,我们对其中有一个点比较疑惑,Presto 是有自我保护功能的,就是当一个 SQL 超限时集群会自动 KILL 达到自我保护的效果,而不会是 Worker 挂掉导致集群不稳定,因为这是有点违背常识的,那么为什么这次会出现频繁的 Worker 重启呢(因为挂掉了,K8s 保护机制会自动拉起,我们看到的现象就是反复重启)。** 117 | 118 | **(这里也可以这样理解,Presto 集群的默认配置,肯定是将集群调节在一个比较平衡的状态,就是能适应各类查询而且不至于会出现频繁宕机的情况,那么这里可以合理的怀疑,系统有Bug或者我们修改了配置)** 119 | 120 | **问题排查到这应该是顺着线索往下走,查一下 Worker 为什么会挂掉,比如日志等等。** 121 | 122 | 这次排查的 Presto 是在 K8s 中部署的,可以理解一个 Worker 对应了一个 Pod。 123 | 124 | 那么一个 Worker 挂掉,此时在 K8s 中这个 Pod 就已经消失了,然后 K8s 会对它进行重启,此时因为没有配置那种异常信息重定向等等操作,所以就一直偷懒没有查这个问题,而且平常这个问题也不多,导致这次的问题没有头绪。 125 | 126 | 冷静的想了想,`因为异常,所以 Worker 挂掉,然后一批 SQL 继续受影响,如此反复,那么此时关键点就是排查 Worker 为什么挂掉。` 127 | 128 | 最后咨询了高手,在 Pod 重启时 (时间比较短的话),可以使用命令查看上一次的日志信息。这里就不过多介绍,关键字为 `kubectl logs previous` 可以自行搜索。 129 | 130 | 查看到日志如下: 131 | 132 | ![](vx_images/78021950615480.png) 133 | 134 | 135 | 我们发现了几个重要的线索 136 | 137 | 1. 这是一个 Worker 出现了 OOM 打出来最后的异常信息; 138 | 2. 这个 Worker 当时有差不多 11 个查询在运行; 139 | 3. 这些查询最多的有占用 18G 内存; 140 | 4. 这些查询内存占用加起来差不多 40G 左右。 141 | 142 | 然后根据前面 Worker 的监控我们可以看到,堆内存配置了 64G,Worker里的那个工作内存池差不多是 40G。 143 | 144 | 最后根据 OOM 的错误可以判断,查询还在一直申请内存,然后 Worker 的堆内存不够了,所以 OOM 了,导致后续的 Worker 挂掉,查询挂掉。 145 | 146 | 那么为什么会 OOM 呢,我们是有配置一些内存限制的呀? 147 | 148 | ## 重新检查配置 149 | 150 | > 这个时候第一思绪竟然不是觉得配置配的有问题,而是其他的问题,在经过沟通和查资料发现,最后确实是配置的不合理造成的。 151 | 152 | 贴一下 Presto 中的关键配置 153 | 154 | ``` 155 | presto 156 | query.max-total-memory-per-node=40GB 157 | query.max-memory-per-node=40GB 158 | 159 | jvm 160 | -Xmx64G 161 | ``` 162 | 163 | 简单解释一下就是,Presto 的查询最多只能用 40G 内存,每个 Worker 的 jvm 堆内存配置的 64G。 164 | 165 | 我们查看一下官方文档 166 | 167 | ![](vx_images/588129864498952.png) 168 | 169 | 170 | 看到里面的建议是查询可用内存与 JVM 默认是 10 倍内存比,比如 64G JVM,那么这里 query.max-memory-per-node 配个5~6G,然后集群里跑 10 个查询是没问题的。 171 | 172 | 此时再看看我们的 40G 与 64G,顿时恍然大悟。 173 | 174 | 用前面那个 OOM 举例,最多的查询才用到 18G 按照限制它还可以继续申请,至少可以到 40G,但是 JVM 只有 64G,而且此时又有 10 多个 SQL 都是这样的情况,因为限制比较高,所有查询都可以往 40G 这个量级申请,所以 OOM 了,然后 Worker 挂掉,查询都挂掉。 175 | 176 | 不过这样也可以理解,如果按照社区的默认配置,那么对集群的运行是保守稳定的,这样 Worker 不会因为 OOM 挂掉,但是对大查询就不太友好,所以这个 40G 是对大查询友好的,如果这样超配内存限制就需要对资源进行比较精细的调度和管控,不然因为 MPP 的架构,频繁的 Worker 重启,对整体集群影响确实很大。 177 | 178 | ## 总结 179 | 180 | 这次的问题排查,有几个关键点收益很大: 181 | 182 | 1. 出现异常的时候一定要顺着问题查到关键位置,不要偷懒,比如我的关键位置就是频繁 Worker 重启,那么就需要查一下为什么 Worker 会重启。 183 | 2. 不管是已知现象,还是新的问题,都应该按照一个合理的流程排查一下,而不是误认为就是`查询量很大`,却不认为是`异常`。 184 | 3. 比如这个 OOM 导致的挂掉,其实我早就知道这个问题了,可是我为什么一直不排查呢?这里需要反思一下。 185 | 4. 在这个过程中 `降级、限流、回滚` 一个个常见的保护手段都没有,这里就不谈了,准备单独写一篇文章来介绍。 186 | 187 | 最后,根据内存超限配置的情况我们定位到了一些异常内存使用的 SQL,恰好那天这些 SQL 对应的应用也出现了问题一直在死循环的向 Presto 投递,我们将其都暂时后 Presto 恢复了正常。(这里我们的内存超配也是一个隐患点,以后会再单独出一篇文章来讲如何监控以及调优这块)。 188 | 189 | 所以结论就是,Presto 的 JVM max memory 与 query.max-memory-per-node 配置关系到你集群的一个服务模式,是应对大查询,还是小查询。 190 | 191 | **这个配置的比例很关键,一定要慎重配置。** 192 | 193 | 194 | ## 重新思考这次问题的排查 195 | 196 | 回头来看看前面说的看监控、和查问题过拟合、以及直接证明问题的这个点,那么我应该看什么指标来定位以及证明问题呢? 197 | 198 | 我觉得应该是有一个监控,能够直接证明集群有问题的,比如我这次 SQL 查询量很大,不管是正常的请求 SQL 还是异常的,其实都应该属于 `异常` 情况,反过来想比如每 N 时间可以承受 M 个 SQL,假设有一天 M 直接放大了成千上百倍,即使都是正常的 SQL,那也肯定出问题了。 199 | 200 | 所以,此时我们就可以使用 `查询次数` 这个监控来直接证明这个问题。 201 | 202 | > 这里确实在当时排查问题的时候没有意识到,算是为以后涨经验了。 203 | 204 | ![](vx_images/347412885938973.png) 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | -------------------------------------------------------------------------------- /08_运维与监控/vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2022-02-28T02:29:58Z", 3 | "files": [ 4 | { 5 | "attachment_folder": "", 6 | "created_time": "2023-04-22T15:42:00Z", 7 | "id": "28", 8 | "modified_time": "2024-01-20T02:51:24Z", 9 | "name": "基础监控接口.md", 10 | "signature": "2845011193528320072", 11 | "tags": [ 12 | ] 13 | }, 14 | { 15 | "attachment_folder": "", 16 | "created_time": "2023-04-22T15:42:13Z", 17 | "id": "29", 18 | "modified_time": "2024-02-26T13:28:26Z", 19 | "name": "对接Prometheus生态.md", 20 | "signature": "4749048823811407957", 21 | "tags": [ 22 | ] 23 | }, 24 | { 25 | "attachment_folder": "", 26 | "created_time": "2023-10-15T03:29:52Z", 27 | "id": "33", 28 | "modified_time": "2024-02-26T13:29:36Z", 29 | "name": "如何发现当前Presto集群的性能瓶颈_初探.md", 30 | "signature": "17565100698149543088", 31 | "tags": [ 32 | ] 33 | }, 34 | { 35 | "attachment_folder": "", 36 | "created_time": "2023-10-15T07:02:37Z", 37 | "id": "35", 38 | "modified_time": "2024-02-26T16:15:35Z", 39 | "name": "执行计划Stage颜色介绍.md", 40 | "signature": "13504965605256302221", 41 | "tags": [ 42 | ] 43 | }, 44 | { 45 | "attachment_folder": "192856965846251", 46 | "created_time": "2024-03-10T07:51:31Z", 47 | "id": "61", 48 | "modified_time": "2024-03-31T14:33:25Z", 49 | "name": "Presto的Worker为什么会挂掉.md", 50 | "signature": "8834755967329330819", 51 | "tags": [ 52 | ] 53 | }, 54 | { 55 | "attachment_folder": "", 56 | "created_time": "2024-04-24T09:33:49Z", 57 | "id": "66", 58 | "modified_time": "2024-07-14T10:33:39Z", 59 | "name": "如何发现当前Presto集群的性能瓶颈_IO瓶颈.md", 60 | "signature": "15515793650296082941", 61 | "tags": [ 62 | ] 63 | }, 64 | { 65 | "attachment_folder": "", 66 | "created_time": "2024-07-10T09:28:01Z", 67 | "id": "86", 68 | "modified_time": "2025-01-18T02:28:00Z", 69 | "name": "Presto排查Worker宕机问题_缓存与内存问题排查_上.md", 70 | "signature": "15535898993511246476", 71 | "tags": [ 72 | ] 73 | } 74 | ], 75 | "folders": [ 76 | ], 77 | "id": "25", 78 | "modified_time": "2022-02-28T02:29:58Z", 79 | "signature": "207324012360614", 80 | "version": 3 81 | } 82 | -------------------------------------------------------------------------------- /08_运维与监控/vx_images/103156965946975.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/103156965946975.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/107021056234868.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/107021056234868.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/108107182762118.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/108107182762118.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/108925001924772.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/108925001924772.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/114214185463339.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/114214185463339.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/122008214091069.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/122008214091069.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/123434855955931.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/123434855955931.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/127646103991186.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/127646103991186.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/131613531841143.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/131613531841143.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/132884285437333.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/132884285437333.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/149367346986962.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/149367346986962.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/149647423690409.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/149647423690409.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/162124739907155.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/162124739907155.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/181821876458722.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/181821876458722.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/182562213493958.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/182562213493958.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/204803381711407.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/204803381711407.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/211956587286804.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/211956587286804.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/232686877056302.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/232686877056302.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/233173933066205.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/233173933066205.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/243334853068317.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/243334853068317.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/25258813594877.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/25258813594877.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/266777817527765.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/266777817527765.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/271025808856344.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/271025808856344.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/299226147098254.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/299226147098254.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/331359308530647.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/331359308530647.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/33156198733529.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/33156198733529.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/347412885938973.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/347412885938973.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/347579676878651.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/347579676878651.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/351806920328416.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/351806920328416.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/359324008851148.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/359324008851148.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/360794580221242.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/360794580221242.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/396797673041505.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/396797673041505.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/412992369101981.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/412992369101981.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/417203007575711.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/417203007575711.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/421473603187620.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/421473603187620.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/432332157473058.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/432332157473058.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/446733109044162.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/446733109044162.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/448300047956477.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/448300047956477.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/45993249790558.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/45993249790558.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/464116987726505.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/464116987726505.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/4956932695016.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/4956932695016.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/497221277511829.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/497221277511829.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/521364207707988.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/521364207707988.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/526897444981667.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/526897444981667.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/534043554063705.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/534043554063705.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/577944467481899.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/577944467481899.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/588129864498952.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/588129864498952.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/595751986981801.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/595751986981801.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/599290714988590.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/599290714988590.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/6184102006630.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/6184102006630.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/78021950615480.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/78021950615480.png -------------------------------------------------------------------------------- /08_运维与监控/vx_images/84806968147010.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/08_运维与监控/vx_images/84806968147010.png -------------------------------------------------------------------------------- /08_运维与监控/基础监控接口.md: -------------------------------------------------------------------------------- 1 | # 基础监控接口 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | Presto 和 Trino 自身是通过 Airlift 轻量级后端框架开发的,我们在 WebUI 上看到的一些简单的监控数据,都是有对应监控接口的,我们可以在这些监控接口中获得一些简单的数据用于监控。 8 | 9 | ## Presto 10 | 11 | ![](vx_images/299226147098254.png) 12 | 13 | ## Trino 14 | 15 | Trino 这边会把一些 WebUI 里的接口,调整了一下,不过也大同小异。 16 | 17 | ![](vx_images/233173933066205.png) 18 | 19 | ## 接口简述 20 | 21 | Presto 与 Trino 这些接口都差不多,会新开一片文章来介绍它们的区别,并使用一个实际的例子来演示,比如开发一个 网关 可以同时代理 Presto 和 Trino。 22 | 23 | 以下对它们进行简单的介绍。 24 | 25 | ### info 26 | 27 | 查看整体 28 | 29 | ``` 30 | http://0.0.0.0:8080/v1/info 31 | ``` 32 | 33 | 查看整体状态 34 | 35 | ``` 36 | http://0.0.0.0:8080/v1/info/state 37 | ``` 38 | 39 | ### node 节点 40 | 41 | 查看所有node信息 42 | 43 | ``` 44 | http://0.0.0.0:8080/v1/node 45 | ``` 46 | 47 | 查看所有node中的失败信息 48 | 49 | ``` 50 | http://0.0.0.0:8080/v1/node/failed 51 | ``` 52 | 53 | ### query 查询 54 | 55 | 所有查询概述,登录ui看到的那个列表 56 | 57 | 这个接口是受限制 Coordinator 对查询的保存数的,默认是只保存 100 个,如果还想看很多查询的相关信息,建议使用 Event Listener 的方式将查询的 query 持久化保存起来。 58 | 59 | ``` 60 | http://0.0.0.0:8080/v1/query 61 | ``` 62 | 63 | ### task 任务 64 | 65 | ``` 66 | http://0.0.0.0:8080/v1/task 67 | ``` 68 | 69 | ### service 服务 70 | 71 | 可以看到所有注册进来的节点,Coordinator 与 Worker。 72 | 73 | ``` 74 | http://0.0.0.0:8080/v1/service 75 | ``` 76 | 77 | ### cluster 集群 78 | 79 | 整体状态 80 | 81 | ``` 82 | http://0.0.0.0:8080/v1/cluster 83 | ``` 84 | 85 | ``` 86 | { 87 | "runningQueries": 0, 88 | "blockedQueries": 0, 89 | "queuedQueries": 0, 90 | "activeWorkers": 15, 91 | "runningDrivers": 0, 92 | "reservedMemory": 0.0, 93 | "totalInputRows": 518089265913, 94 | "totalInputBytes": 65099807693962, 95 | "totalCpuTimeSecs": 1810247 96 | } 97 | ``` 98 | 99 | ### status 节点状态 100 | 101 | ``` 102 | http://0.0.0.0:8080/v1/status 103 | ``` 104 | 105 | ``` 106 | { 107 | "nodeId": "coordinator_bigdata_001", 108 | "nodeVersion": { 109 | "version": "0.203" 110 | }, 111 | "environment": "bigdata_presto_cluster", 112 | "coordinator": true, 113 | "uptime": "4.14d", 114 | "externalAddress": "0.0.0.0", 115 | "internalAddress": "0.0.0.0", 116 | "memoryInfo": { 117 | "totalNodeMemory": "60129542144B", 118 | "pools": { 119 | "reserved": { 120 | "maxBytes": 25769803776, 121 | "reservedBytes": 0, 122 | "reservedRevocableBytes": 0, 123 | "queryMemoryReservations": { 124 | 125 | }, 126 | "queryMemoryRevocableReservations": { 127 | 128 | }, 129 | "freeBytes": 25769803776 130 | }, 131 | "general": { 132 | "maxBytes": 34359738368, 133 | "reservedBytes": 0, 134 | "reservedRevocableBytes": 0, 135 | "queryMemoryReservations": { 136 | 137 | }, 138 | "queryMemoryRevocableReservations": { 139 | 140 | }, 141 | "freeBytes": 34359738368 142 | } 143 | } 144 | }, 145 | "processors": 40, 146 | "processCpuLoad": 0.0062446155574938066, 147 | "systemCpuLoad": 0.033896111919435444, 148 | "heapUsed": 21368786312, 149 | "heapAvailable": 85899345920, 150 | "nonHeapUsed": 366581480 151 | } 152 | ``` 153 | 154 | ### 带账号密码的形式 155 | 156 | ``` 157 | curl -s -u 账号:密码 http://0.0.0.0:8080/v1/node 158 | ``` 159 | 160 | ``` 161 | curl -s -u 账号:密码 http://0.0.0.0:8080/v1/service 162 | ``` -------------------------------------------------------------------------------- /08_运维与监控/如何发现当前Presto集群的性能瓶颈_IO瓶颈.md: -------------------------------------------------------------------------------- 1 | # 如何发现当前Presto集群的性能瓶颈_IO瓶颈 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | 前面我们通过各种案例的方式讲解了一些常见的性能瓶颈,本文我们来讲讲 `IO瓶颈`。 8 | 9 | ## 场景一:缓存没有正确配置导致某个 Task 慢 10 | 11 | 屏蔽了敏感信息 SQL 如下 12 | 13 | ```sql 14 | SELECT 15 | 字段1, 16 | COUNT DISTINCT 字段2 17 | FROM 18 | ( 19 | table1 20 | LEFT JOIN table2 ON ***_id = ***_id 21 | ) 22 | WHERE 23 | *** 24 | GROUP BY 25 | *** 26 | ORDER BY 27 | 1 DESC 28 | LIMIT 29 | 100 30 | ``` 31 | 32 | ### 查询的简略信息 33 | 34 | 会发现跑起来有时候需要 20 多秒,有时候只有 3 秒。 35 | 36 | 快的 3 秒左右: 37 | 38 | ![](vx_images/360794580221242.png) 39 | 40 | 41 | 慢的 20 秒左右: 42 | 43 | ![](vx_images/149647423690409.png) 44 | 45 | 46 | ### 查询的某个 Stage 中的 Task 信息 47 | 48 | 我们可以打开 Overview 页面的下面 Stage 部分,然后找找里面有不有 Elapsed 时间不一致的 Stage: 49 | 50 | 慢的 51 | 52 | ![](vx_images/132884285437333.png) 53 | 54 | 55 | 快的 56 | 57 | ![](vx_images/25258813594877.png) 58 | 59 | 60 | ### Task 中详细的数据 61 | 62 | 快的 63 | 64 | ``` 65 | "operatorSummaries": [ 66 | { 67 | "stageId": 3, 68 | "stageExecutionId": 0, 69 | "pipelineId": 2, 70 | "operatorId": 0, 71 | "planNodeId": "660", 72 | "operatorType": "ScanFilterAndProjectOperator", 73 | "totalDrivers": 7, 74 | "addInputCalls": 5043, 75 | "addInputWall": "95.68ms", 76 | "addInputCpu": "0.00ns", 77 | "addInputAllocation": "0B", 78 | "rawInputDataSize": "81.32MB", 79 | "rawInputPositions": 1945211, 80 | "inputDataSize": "81.32MB", 81 | "inputPositions": 1945211, 82 | "sumSquaredInputPositions": 810232961935, 83 | "getOutputCalls": 2030, 84 | "getOutputWall": "1.83s", 85 | "getOutputCpu": "1.76s", 86 | "getOutputAllocation": "0B", 87 | "outputDataSize": "31.78MB", 88 | "outputPositions": 954429, 89 | "physicalWrittenDataSize": "0B", 90 | "additionalCpu": "0.00ns", 91 | "blockedWall": "0.00ns", 92 | "finishCalls": 0, 93 | "finishWall": "0.00ns", 94 | "finishCpu": "0.00ns", 95 | "finishAllocation": "0B", 96 | "userMemoryReservation": "0B", 97 | "revocableMemoryReservation": "0B", 98 | "systemMemoryReservation": "0B", 99 | "peakUserMemoryReservation": "0B", 100 | "peakSystemMemoryReservation": "9.22MB", 101 | "peakTotalMemoryReservation": "9.22MB", 102 | "spilledDataSize": "0B", 103 | "runtimeStats": { 104 | ... 105 | ... 106 | ... 107 | "storageReadTimeNanos": { 108 | "name": "storageReadTimeNanos", 109 | "unit": "NANO", 110 | "sum": 95677553, 111 | "count": 35, 112 | "max": 10680828, 113 | "min": 743625 114 | }, 115 | ... 116 | ... 117 | ... 118 | } 119 | } 120 | ``` 121 | 122 | 慢的 123 | 124 | ``` 125 | "operatorSummaries": [ 126 | { 127 | "stageId": 3, 128 | "stageExecutionId": 0, 129 | "pipelineId": 2, 130 | "operatorId": 0, 131 | "planNodeId": "660", 132 | "operatorType": "ScanFilterAndProjectOperator", 133 | "totalDrivers": 8, 134 | "addInputCalls": 4124, 135 | "addInputWall": "20.87s", 136 | "addInputCpu": "0.00ns", 137 | "addInputAllocation": "0B", 138 | "rawInputDataSize": "6.21MB", 139 | "rawInputPositions": 1548937, 140 | "inputDataSize": "6.21MB", 141 | "inputPositions": 1548937, 142 | "sumSquaredInputPositions": 335570270649, 143 | "getOutputCalls": 1646, 144 | "getOutputWall": "22.54s", 145 | "getOutputCpu": "1.64s", 146 | "getOutputAllocation": "0B", 147 | "outputDataSize": "26.47MB", 148 | "outputPositions": 800714, 149 | "physicalWrittenDataSize": "0B", 150 | "additionalCpu": "0.00ns", 151 | "blockedWall": "0.00ns", 152 | "finishCalls": 0, 153 | "finishWall": "0.00ns", 154 | "finishCpu": "0.00ns", 155 | "finishAllocation": "0B", 156 | "userMemoryReservation": "0B", 157 | "revocableMemoryReservation": "0B", 158 | "systemMemoryReservation": "0B", 159 | "peakUserMemoryReservation": "0B", 160 | "peakSystemMemoryReservation": "2.15MB", 161 | "peakTotalMemoryReservation": "2.15MB", 162 | "spilledDataSize": "0B", 163 | "runtimeStats": { 164 | ... 165 | ... 166 | ... 167 | 168 | "storageReadTimeNanos": { 169 | "name": "storageReadTimeNanos", 170 | "unit": "NANO", 171 | "sum": 20868277488, 172 | "count": 32, 173 | "max": 20815882471, 174 | "min": 724840 175 | }, 176 | 177 | ... 178 | ... 179 | ... 180 | 181 | } 182 | } 183 | ``` 184 | 185 | ### 初步判断 186 | 187 | 从 Json 数据里可以很明显的看出,是 storageReadTimeNanos 慢了,它的含义就是从存储里读取数据的花费时间。 188 | 189 | 快的是 20868277488 = 20.86 秒,慢的是 95677553 = 0.09 秒,可以初步判断出,慢的是从远端存储里读的,缓存击穿了,快的是命中缓存了。 190 | 191 | 不过这样来判断,证据和理由不够直接和明确,因为就单纯一个读数据变慢了,会有多个因素。 192 | 193 | ### 进一步探索 194 | 195 | 虽然我们在前面已经知道了 Stage 里某些 Task 的执行耗时有倾斜,也知道是读数据变慢了。 196 | 197 | 但是,只通过一个读数据耗时指标,不具有说服力,所以我们再进一步我们找找其他证明线索。 198 | 199 | #### 从查询执行计划来 200 | 201 | **Scheduled Time 和 处理行数 差异** 202 | 203 | ``` 204 | 快 SQL 205 | Fragment 3 [SOURCE] 206 | CPU: 5.03m, Scheduled: 5.21m, Input: 67989968 rows (3.79GB); per task: avg.: 1446595.06 std.dev.: 215595.32, Output: 746944 207 | ``` 208 | 209 | ``` 210 | 慢 SQL 211 | Fragment 3 [SOURCE] 212 | CPU: 5.14m, Scheduled: 5.73m, Input: 67989968 rows (3.79GB); per task: avg.: 1446595.06 std.dev.: 572537.27, Output: 746944 213 | ``` 214 | 215 | 可以发现,快 SQL 的 Scheduled Time 比慢 SQL 的要少,同时 std.dev 也要少。 216 | 217 | > Scheduled Time 的含义可以理解为除了计算以外的所有耗时。 218 | > std.dev. 的含义可以理解为每个任务处理的数据行数的标准差。比如下面的含义就是每个任务平均处理 1446595.06 行,快 SQL 标准差为 215595.32 行,慢 SQL 标准差为 572537.27 行。 219 | 220 | 这里可以判断有调度不合理、数据倾斜、慢节点、缓存是否击穿等可能性。 221 | 222 | #### 从缓存角度来看 223 | 224 | 因为这个问题主要是讲缓存方面,所以可以先暂时排除调度不合理、数据倾斜、慢节点等问题,这些会放到其他场景介绍。 225 | 226 | 我们看看执行计划里 Fragment 3 的读数据算子 ScanFilterProject 的信息: 227 | 228 | ``` 229 | 快 SQL 230 | 231 | - ScanFilterProject[table = TableHandle {connectorId='hive', connectorHandle='HiveTableHandle 232 | {schemaName=***, tableName=***, analyzePartitionValues=Optional.empty}', layout='Optional 233 | [***]'}, grouped = false, filterPredicate = ***, projectLocality = LOCAL] => [***] 234 | Estimates: {rows: 67798161 (4.61GB), cpu: 4339082304.00, memory: 0.00, network: 0.00}/{rows: ? (?), 235 | cpu: 8678164608.00, memory: 0.00, network: 0.00}/{rows: ? (?), cpu: ?, memory: 0.00, network: 0.00} 236 | 237 | CPU: 1.11m (21.33%), 238 | Scheduled: 1.30m (23.04%), <-- 这里 239 | Output: 34117843 rows (1.10GB) 240 | 241 | Input avg.: 214551.14 rows, Input std.dev.: 46.49% 242 | 243 | *** 244 | 245 | Input: 67798161 rows (3.78GB), Filtered: 49.68% 246 | ``` 247 | 248 | 249 | ``` 250 | 慢 SQL 251 | - ScanFilterProject[table = TableHandle {connectorId='hive', connectorHandle='HiveTableHandle 252 | {schemaName=***, tableName=***, analyzePartitionValues=Optional.empty}', layout='Optional 253 | [***]'}, grouped = false, filterPredicate = ***, projectLocality = LOCAL] => [***] 254 | Estimates: {rows: 67798161 (4.61GB), cpu: 4339082304.00, memory: 0.00, network: 0.00}/{rows: ? (?), 255 | cpu: 8678164608.00, memory: 0.00, network: 0.00}/{rows: ? (?), cpu: ?, memory: 0.00, network: 0.00} 256 | 257 | CPU: 1.16m (21.81%), 258 | Scheduled: 2.15m (32.58%), <-- 这里 259 | Output: 34117843 rows (1.10GB) 260 | 261 | Input avg.: 214551.14 rows, Input std.dev.: 46.49% 262 | 263 | *** 264 | 265 | Input: 67798161 rows (3.78GB), Filtered: 49.68% 266 | ``` 267 | 268 | 在读数据的算子里,我们可以看到 CPU 的花费、数据输入量、数据的标准差基本都差不多,主要的区别在 Scheduled 上,这个算子对应 SQL 中的 table1。 269 | 270 | 我们此时再查看对应的缓存规则,发现 `没有对该表进行缓存`,最后将该表配置到缓存规则里即可。 271 | 272 | #### 从监控角度来看 273 | 274 | 这个 SQL 当时的监控数据没有现场了,我们从近期的一个很典型的例子来看: 275 | 276 | 当缓存命中率下降时,查询耗时会上升,再去查看审计日志,可以发现确实是读了很多新表。 277 | 278 | ![](vx_images/595751986981801.png) 279 | 280 | 由此可以证明,两个监控是有正相关性的。 281 | 282 | ### 总结 283 | 284 | 1. 为什么有时快,有时慢?这是另外一个问题,因为是多集群且都开启了缓存,集群之前的缓存配置没有统一,出现了这个时快时慢的问题。 285 | 2. Scheduled Time,可以从字面理解 `调度耗时`,我的理解是除 CPU 计算花费以外的所有时间,比如在等待 split 或者 数据 input,可以假设有 IO 瓶颈,优先查 IO 方面的问题,但不一定是 IO 方面的问题,这里要分清楚。 286 | 3. 一般 CPU Time 与 Schedule Time 比值较大时,大概率 `有` IO 瓶颈,反之没有。(这里没有绝对,可以用这个方式提前假设排查) 287 | 4. std.dev,是处理行数的标准差,可以用来判断数据计算是否均衡,一般可能有分区策略、数据倾斜、调度不合理、预处理干扰、缓存IO等问题的可能性。 288 | 5. 缓存命中率下降时,查询耗时会上升。 289 | 290 | -------------------------------------------------------------------------------- /08_运维与监控/如何发现当前Presto集群的性能瓶颈_初探.md: -------------------------------------------------------------------------------- 1 | # 如何发现当前Presto集群的性能瓶颈 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | ## 背景 8 | 9 | Presto虽然提供了强大的WebUI,但在运维角度如何定位真正的慢查询、如何发现当前查询的性能瓶颈、如何分辨当前服务的业务对象是否适合在Presto中工作,成为了难题。 10 | 11 | 接下来我们以案例的方式,来探讨和挖掘如何应对这些问题,以及后续制定什么样的运维手段可以达到快速定位、排查、调优的效果。 12 | 13 | ## 前提 14 | 15 | 接下来的案例,应该是站在更高的角度去看待它,比如业务场景角度,比如架构角度。 16 | 17 | 目的是,我们不应该将Presto定位成OLAP银弹,而是寻找它更适合的业务场景,排除那些不适合的,使其可以快速失败,或者拦截。 18 | 19 | ## 不适合的场景 20 | 21 | 根据日常维护的经验,和对架构的理解,以下场景是Presto不适合的: 22 | 23 | - 高并发场景 24 | - 在线业务数据处理 25 | - 低延迟数据写入与响应 26 | - 大规模ETL场景 27 | - 与事务强关联就场景 28 | 29 | 30 | ## 案例1 数据量很小但查询却很慢 31 | 32 | ### 排查经过 33 | 34 | SQL 逻辑不复杂这里是查的 hudi 表,发现查询完需要 4 分钟。 35 | 36 | ![](vx_images/347579676878651.png) 37 | 38 | 在页面的统计信息中显示也是4分钟 39 | 40 | ![](vx_images/232686877056302.png) 41 | 42 | 需要注意的是,这里可以先排除集群资源紧张,队列竞争的问题,因为这个SQL在多次验证的结果下,查询时长都要4分钟左右。 43 | 44 | 在执行计划中,初步可以看到 stage2 的资源需求是最大的,cpu耗时和split,都比其他的stage较多 45 | 46 | ![](vx_images/149367346986962.png) 47 | 48 | 49 | 查看stage 详细,也确实是stage2比1和0,需要资源更多,读入的split更多 50 | 51 | ![](vx_images/123434855955931.png) 52 | 53 | ![](vx_images/243334853068317.png) 54 | 55 | ![](vx_images/351806920328416.png) 56 | 57 | 排查一下SQL查询的数据,是否会有小文件的情况,因为小文件太多的话SQL会产生大量的Split。 58 | 59 | 很多慢查询的常见问题,可能就是文件太碎,Split太多造成的。 60 | 61 | ``` 62 | [PRODUCTION]$ hdfs dfs -count -q /user/***/tables/hudi_main.db/abtest/* 63 | none inf none inf 18 265 16287744 /user/***/tables/hudi.db/abtest/.hoodie 64 | none inf none inf 1 8120 3556393812 /user/***/tables/hudi.db/abtest/2023-08-30 65 | none inf none inf 1 12783 5596049664 /user/***/tables/hudi.db/abtest/2023-08-31 66 | none inf none inf 1 11480 5020598946 /user/***/tables/hudi.db/abtest/2023-09-01 67 | none inf none inf 1 10701 4680086975 /user/***/tables/hudi.db/abtest/2023-09-02 68 | none inf none inf 1 0 0 /user/***/tables/hudi.db/abtest/2023-09-03 69 | [PRODUCTION]$ hdfs dfs -ls /user/***/tables/hudi_main.db/abtest/2023-08-31 | wc -l 70 | 12784 71 | ``` 72 | 73 | 每个分区差不多1万多个小文件,每个文件不到1MB。 74 | 75 | ``` 76 | 426.4 K 1.2 M /user/***/tables/hudi.db/abtest/2023-08-31/000f2a24-c496-4214-92e9-fbb28d592437-0_20-235-0_20230831100405481.parquet 77 | ``` 78 | 79 | 关键线索:发现单分区在 5GB 的样子。 80 | 81 | ``` 82 | 5.2 G 15.6 G /user/***/tables/hudi.db/abtest/2023-08-31 83 | ``` 84 | 85 | 此时再回头重新查看执行计划: 86 | 87 | ![](vx_images/577944467481899.png) 88 | 89 | 我们可以计算一下,input 量,除以 完成的 split 数,得到410.18的数值,正好与我们前面查看的某个分区中,单个parquet文件的大小相近。 90 | 91 | ``` 92 | (5 MB * 1024 * 1024) / 12782 Split = 410.18 KB 93 | 94 | ``` 95 | 96 | 与我们查看原始数据的大小差不多,所以这里可以判断,sql的查询时间,大部分都耗费在split读数据上面了。 97 | 98 | ### 总结 99 | 100 | 在大数据环境中,小文件的危害是巨大的,不光对存储有影响对计算也会造成影响。 101 | 102 | 站在Presto运维角度来看,如果发现某个Stage的Input量级与Split量级产生了一些极端数值,此时我们可以往小文件的思路方向去排查问题。 103 | 104 | 站在数仓角度或者大数据架构角度来看,是需要着手投入小文件的治理。 105 | 106 | 站在平台的角度(此处不限于数据平台),是否可以提示用户慢在哪了,比如“查询的***表因为小文件太多,可能会影响查询性能。” 107 | 108 | TODO 统计 SQL查询小文件的比例 109 | 110 | 1. SQL维度,1个SQL中只要有表涉及到小文件,既算1次 111 | 2. SQL明细维度,1个SQL中有多少比例的表,是有小文件问题 112 | 113 | ## 案例2 逻辑很简单但查询速度不理想 114 | 115 | ### 排查经过 116 | 117 | 同样也是SQL逻辑不复杂,就是根据某几个字段分组然后对某几个字段聚合,取的数据也不是很多,就是过滤条件稍微有点多。 118 | 119 | 也可以按照计算逻辑稍微有点复杂理解。 120 | 121 | 查询需要2分钟左右。削微有点慢了。 122 | 123 | ![](vx_images/4956932695016.png) 124 | 125 | 126 | ![](vx_images/33156198733529.png) 127 | 128 | ![](vx_images/131613531841143.png) 129 | 130 | 查看执行计划,发现计划比较简单 131 | 132 | ![](vx_images/534043554063705.png) 133 | 134 | 此时的一个思路,(排除小文件问题,已经讲过一个了,肯定不会讲第二个)我们可以往执行计划的方向探索。 135 | 136 | 站在集群运维的角度,如何在保证业务逻辑的前提下能让SQL提速呢。此时我们可以查看到,查询Prerequisites Wait和Queued和Planning耗时都不高,只有Execution耗时最高,那么此时可以排除比如元数据拉取慢,HDFS集群网络波动,等等外接因素。单纯就是SQL算的慢了。 137 | 138 | 可以初步判断该SQL的性能瓶颈在于,计算的横向扩展的不够,受执行逻辑的限制只能慢慢算。 139 | 140 | 此时我们可以考虑将SQL进行横向拆分,一般常用的做法有使用子查询、with语句、union等方式,大致意思为将需要进行的逻辑等份拆分成多分,使其可以并行计算。 141 | 142 | 拆分后的逻辑如下: 143 | 144 | ![](vx_images/108925001924772.png) 145 | 146 | 执行计划发生了变化,很明显的发现那些原来的输入部分,按SQL的逻辑拆分出去了,并且实现了并行计算。 147 | 148 | ![](vx_images/396797673041505.png) 149 | 150 | 查询耗时也缩短至20秒。 151 | 152 | ![](vx_images/271025808856344.png) 153 | 154 | 155 | ### 总结 156 | 157 | 此类SQL的性能瓶颈可能就在于执行计划层面,变相的算限速了。 158 | 159 | 这类的优化,在合理的数据范围内,比如这个SQL的输入量都没超过500MB,适当的进行空间换时间的方式优化是可行的。 160 | 161 | TODO 162 | 163 | - 应该是presto有自动优化,或者是我们没找到,或者是命中的要求比较高,可以找一找 164 | - 如果拆分执行计划之后,并行逻辑多了,是否会造成多读数据的情况 165 | 166 | ## 案例3 大量JSON字符串操作 167 | 168 | ### 排查经过 169 | 170 | SQL同样也很简单,逻辑为解析json字段,然后取一部分数据。 171 | 172 | 过滤条件就只有一个分区条件,没有相关业务逻辑。 173 | 174 | ![](vx_images/103156965946975.png) 175 | 176 | 这里就不贴执行计划和其他参考信息了。这个地方主要是想表达的问题是,SQL在对一个字段进行JSON操作。 177 | 178 | 同样,这也只是个简单的举例,也有可能会出现大量的JSON操作。 179 | 180 | 此时我们可以结合 presto json 补充文档 TODO,可以理解当presto操作大量json数据的时候是特别耗性能的。 181 | 182 | 那么我们此时应该是可以思考,这个SQL的性能瓶颈可能不在于集群能力了,而是在于业务场景是否适合presto了。 183 | 184 | ### 总结 185 | 186 | 咨询用户得知,只是想在ETL之前先简单查看一下表中的数据。 187 | 188 | 当面临这类业务场景时,可以推荐使用抽样函数,文档:https://prestodb.io/docs/current/sql/select.html?highlight=sample#tablesample 189 | 190 | 191 | 192 | ## 案例4 超过内存限制 193 | 194 | ### 排查经过 195 | 196 | ### 总结 197 | 198 | ## 案例5 集群卡住 199 | 200 | - CPU瓶颈 线程堆栈 火焰图 201 | - IO瓶颈 202 | - 内存 采集下General Pool,在运行的内存情况 203 | - 网络 网卡 204 | - 磁盘 读写 205 | 206 | 207 | TODO 208 | 209 | 1. 一个OLAP引擎,在运行一个SQL的时候,是不是应该尽可能的占满资源 210 | 2. cpu和内存使用率,与最终的资源使用率和满载率的一个比值,以至于,最后如何设置集群的查询限制,来达到既能满足查询,又能满足高资源利用率。 211 | 212 | ### 排查经过 213 | 214 | ![](vx_images/127646103991186.png) 215 | 216 | 217 | ![](vx_images/84806968147010.png) 218 | 219 | 220 | TODO 火焰图 221 | 222 | 223 | -------------------------------------------------------------------------------- /08_运维与监控/对接Prometheus生态.md: -------------------------------------------------------------------------------- 1 | # 对接Prometheus生态 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | 对接 Prometheus 生态,最重要的就是将监控数据以 metrics 的形式 + 一个可以 GET 访问的接口暴露出来。 8 | 9 | 而 Presto 和 Trino 的默认监控方式,暂时还没有方便的对接方式,比如打开一个开关就会有一个 metrics 接口之类。一般是使用它的 WebUI,或者去用 WebUI 中对应的接口去监控。(比如我们早期不太熟悉的时候,就是起了一个脚本,定时获取里面的数据进行监控。) 10 | 11 | 在 Prometheus 的 exporter 生态中,监控方式一般有两种,嵌入式与外挂式。简单介绍一下这两种模式: 12 | 13 | 14 | ## 嵌入式 15 | 16 | 也可以叫 java agent 这是一种比较方便的方式,因为不需要再单独维护一个服务,只需要新增一个 jar 包,然后增加一个配置,最后重启即可。 17 | 18 | Presto 与 Trino 的配置基本类似。 19 | 20 | Trino 配置参考: 21 | 22 | ``` 23 | -server 24 | -Xmx16G 25 | -XX:InitialRAMPercentage=80 26 | -XX:MaxRAMPercentage=80 27 | -XX:G1HeapRegionSize=32M 28 | -XX:+ExplicitGCInvokesConcurrent 29 | -XX:+ExitOnOutOfMemoryError 30 | -XX:+HeapDumpOnOutOfMemoryError 31 | -XX:-OmitStackTraceInFastThrow 32 | -XX:ReservedCodeCacheSize=512M 33 | -XX:PerMethodRecompilationCutoff=10000 34 | -XX:PerBytecodeRecompilationCutoff=10000 35 | -Djdk.attach.allowAttachSelf=true 36 | -Djdk.nio.maxCachedBufferSize=2000000 37 | -XX:+UnlockDiagnosticVMOptions 38 | -XX:+UseAESCTRIntrinsics 39 | # Disable Preventive GC for performance reasons (JDK-8293861) 40 | -XX:-G1UsePreventiveGC 41 | -javaagent:/usr/lib/trino/jmx/jmx_prometheus_javaagent-0.16.1.jar=监控暴露端口:/usr/lib/trino/jmx/trino_exporter.yaml 42 | ``` 43 | 44 | Presto 配置参考: 45 | 46 | ``` 47 | -server 48 | -Xmx16G 49 | -XX:+UseG1GC 50 | -XX:G1HeapRegionSize=32M 51 | -XX:+UseGCOverheadLimit 52 | -XX:+ExplicitGCInvokesConcurrent 53 | -XX:+HeapDumpOnOutOfMemoryError 54 | -XX:+ExitOnOutOfMemoryError 55 | -javaagent:/usr/lib/presto/jmx/jmx_prometheus_javaagent-0.16.1.jar=监控暴露端口:/usr/lib/presto/jmx/presto_exporter.yaml 56 | ``` 57 | 58 | 59 | 配置完成启动后,会在进程中看到相关监控的信息。 60 | 61 | Trino 62 | 63 | ``` 64 | root 6650 1 1 Apr21 ? 00:25:01 65 | java -cp /data8/trino-server-414/lib/* -server -Xmx64G 66 | -XX:-UseBiasedLocking -XX:+UseG1GC -XX:G1HeapRegionSize=32M -XX:+ExplicitGCInvokesConcurrent -XX:+ExitOnOutOfMemoryError 67 | -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -XX:ReservedCodeCacheSize=512M -XX:PerMethodRecompilationCutoff=10000 68 | -XX:PerBytecodeRecompilationCutoff=10000 -Djdk.attach.allowAttachSelf=true -Djdk.nio.maxCachedBufferSize=2000000 69 | -Djava.library.path=/usr/lib/hadoop/lib/native:/usr/lib/hadoop/share/hadoop/common/lib:/data8/trino-server-414/hadoop-lzo 70 | -javaagent:/data8/bak/jmx_prometheus_javaagent-0.16.1.jar=20081:/data8/bak/trino_exporter.yaml -Dnode.environment=trino_414_test 71 | -Dnode.data-dir=/data8/trino-server-414/data -Dlog.levels-file=/data8/trino-server-414/etc/log.properties 72 | -Dlog.output-file=/data8/trino-server-414/data/var/log/server.log -Dlog.enable-console=false 73 | -Dconfig=/data8/trino-server-414/etc/config.properties io.trino.server.TrinoServer 74 | ``` 75 | 76 | Presto 77 | 78 | ``` 79 | root 31049 1 99 10:29 ? 00:00:09 80 | java -cp /data8/presto-server-0.279/lib/* -server -Xmx64G 81 | -XX:+UseG1GC -XX:G1HeapRegionSize=32M -XX:+UseGCOverheadLimit -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError 82 | -XX:+ExitOnOutOfMemoryError -Djava.library.path=/usr/lib/hadoop/lib/native:/usr/lib/hadoop/lzo/lib:/data8/presto-server-0.279/hadoop-lzo 83 | -javaagent:/data8/bak/jmx_prometheus_javaagent-0.16.1.jar=20082:/data8/bak/trino_exporter.yaml -Dnode.environment=test 84 | -Dnode.id=cdp_presto_test -Dnode.data-dir=/data8/presto-server-0.279/data -Dlog.levels-file=/data8/presto-server-0.279/etc/log.properties 85 | -Dlog.output-file=/data8/presto-server-0.279/data/var/log/server.log -Dlog.enable-console=false 86 | -Dconfig=/data8/presto-server-0.279/etc/config.properties com.facebook.presto.server.PrestoServer 87 | ``` 88 | 89 | 再来请求一下监控暴露端口,即可得到 metrics 格式的监控数据。 90 | 91 | ## 外挂式 92 | 93 | 嵌入式的方式,如果是要对 agent 程序调整或者配置更新什么的,因为与被监控的程序强耦合会有一些不方便的地方。此时在 Prometheus 生态中还提供了另一种外挂的方式,使用的 jmx 包为 jmx_prometheus_httpserver。 94 | 95 | 96 | 97 | 此时我们只需要准备一个的 jmx 配置,以及一个服务的启动脚本即可,一般我们会用一个 systemd 来维护这个脚本。 98 | 99 | jmx 配置,这里的 8888 是 java 程序暴露出来的 jmx 接口地址: 100 | 101 | ``` 102 | hostPort: localhost:8888 103 | blacklistObjectNames: ["org.apache.derby:*", "org.apache.logging.log4j2:*", "com.jolbox.bonecp:*"] 104 | 105 | rules: 106 | - pattern: ".*" 107 | ``` 108 | 109 | systemd 配置,这里的 9999 可以理解为将 jmx 转换为 metrics 后的接口: 110 | 111 | ``` 112 | [Unit] 113 | Description=Prometheus Jmx Exporter httpserver service 114 | After=syslog.target network.target 115 | 116 | [Service] 117 | LimitNOFILE=1000000 118 | #LimitCORE=infinity 119 | LimitSTACK=10485760 120 | User=root 121 | ExecStart=/usr/bin/java -jar /usr/lib/jmx/jmx_prometheus_httpserver-0.1.1-SNAPSHOT-jar-with-dependencies.jar 9999 /usr/lib/jmx/conf/jmx的配置.yml 122 | Restart=always 123 | RestartSec=30s 124 | Environment="JAVA_HOME=/usr/java/jdk" 125 | SuccessExitStatus=143 126 | 127 | [Install] 128 | WantedBy=multi-user.target 129 | ``` 130 | 131 | 这里以一个 yarn router 的最后效果举例。 132 | 133 | ![](vx_images/599290714988590.png) 134 | 135 | 在 linux 它相当于是一个独立的程序,然后我们监控指标,都从这个程序的 19996 端口获取,然后监控程序的调整和配置更新不会影响到主程序。 136 | 137 | 138 | ## 总结 139 | 140 | 嵌入式和外挂式都各有好处。 141 | 142 | 嵌入式的好处是运维方便,或者说几乎没有运维,但是后续的调整以及还会对主程序产生轻微的性能损耗。 143 | 144 | 外挂式的好熟就是,灵活方便,可以随意变更不影响主程序,缺点就是多了运维成本。 145 | 146 | 147 | -------------------------------------------------------------------------------- /08_运维与监控/执行计划Stage颜色介绍.md: -------------------------------------------------------------------------------- 1 | # 执行计划Stage颜色介绍 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | ## Live Plan 中 Stage 颜色含义 8 | 9 | ![](vx_images/114214185463339.png) ![](vx_images/521364207707988.png) ![](vx_images/107021056234868.png) 10 | 11 | ![](vx_images/497221277511829.png) ![](vx_images/162124739907155.png) ![](vx_images/417203007575711.png) 12 | 13 | ![](vx_images/6184102006630.png) ![](vx_images/204803381711407.png) ![](vx_images/412992369101981.png) 14 | 15 | 对应源码 16 | 17 | - presto-main/src/main/resources/webapp/src/utils.js 18 | - presto-main/src/main/resources/webapp/src/components/LivePlan.jsx 19 | 20 | -------------------------------------------------------------------------------- /10_问题总结/Presto中文问题.md: -------------------------------------------------------------------------------- 1 | # Presto中文问题 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | ## 背景 8 | 9 | > 版本 0.280 10 | 11 | 在 Presto 的 WHERE 中带有中文的查询,会有查不到数据的情况,如下图。 12 | 13 | 在不修改的情况下,需要带一些比如 like 或者去空格等等奇怪的操作(让人误以为字段里有脏数据)才能查出来。 14 | 15 | 该问题主要体现在 Parquet 数据上。 16 | 17 | ![](vx_images/291885947698598.png) 18 | 19 | ![](vx_images/363187092916256.png) 20 | 21 | ## 排查 22 | 23 | 在 Issues 中以及踩过坑的人提示,在 Trino 中找到了相关线索 https://github.com/trinodb/trino/issues/3517 24 | 25 | 这个 PR 主要是在读取 Parqeut 的元数据时(列的元数据),处理包含非 ASCII 字符的最小值和最大值字符串不正确导致无法使用中文的问题。 26 | 27 | 举例,有如下 Parquet 数据,在统计信息里,中文也会根据编码来排序出 min max: 28 | 29 | ``` 30 | ... 31 | ... 32 | 33 | city: BINARY LZO DO:0 FPO:4 SZ:68979/90480/1.31 VC:224686 ENC:RLE,BIT_PACKED,PLAIN_DICTIONARY ST:[min: 上海, max: 黑龙江, num_nulls: 0] 34 | 35 | ... 36 | ... 37 | ``` 38 | 39 | 简单解释一下 PR 里做出的修改,就是 Presto 在读取 Parquet 数据时中文字符属于非 ASCII 字符,Presto 在处理非 ASCII 字符时忽略了 Parquet 升级统计信息调整的问题所导致。 40 | 41 | ![](vx_images/561675572246622.png) 42 | 43 | PR 里有说到 PARQUET-1025 https://issues.apache.org/jira/browse/PARQUET-1025 有调整中 Parquet 中列的最大最小统计信息。 44 | 45 | 可以理解为,Parquet 1.10.0 版本开始,列的统计信息会发生变化,需要注意一下集群里的版本。 46 | 47 | Presto 目前就是直接裸读,如果集群里有过 Parqeut 的版本变更,可能会有问题。 48 | 49 | Trino 这边的修改就是,先通过 `ParquetMetadataConverter` 转换统计信息,如果发现使用的是旧格式的 UTF-8 统计信息,并且新的统计信息没有设置 min 和 max,则调用 `tryReadOldUtf8Stats` 方法进行处理,增加了一个向下兼容读取的方法,而 Presto 这边直接认为用户会升到最新 (它真的,我哭死)。 50 | 51 | 目前,我这里是 0.280 的版本,是参考了 Trino 移植了该功能。 52 | 53 | ## 总结 54 | 55 | 因为这类问题没有明确的报错,查问题时会容易掉入思想捷径的陷阱。 56 | 57 | 通过这次解决问题,可以得到一个排查问题的路线总结: 58 | 59 | 先查社区 issues,然后再先从底层存储向上反着查,因为这样在查的路径中,有可能会看到代码里的 TODO 或者注释。 60 | 61 | 62 | -------------------------------------------------------------------------------- /10_问题总结/Presto单元测试错误NoClassDefFoundError_QueryAnalyzer_引发的版本使用思考.md: -------------------------------------------------------------------------------- 1 | # Presto单元测试错误NoClassDefFoundError_QueryAnalyzer_引发的版本使用思考 2 | 3 | [返回首页](../README.md) 4 | 5 | --- 6 | 7 | ## 背景 8 | 9 | 在进行 presto 插件开发时,单元测试出现了一个 NoClassDefFoundError 的错误。 10 | 11 | 根据经验,可能是引的包版本不同,里面有一些被删掉的类然后我引用到了,而出现的问题。 12 | 13 | 但是我印象中,我都是根据 tag 来切版本使用的,为什么还会出现这个问题? 14 | 15 | ## 问题现象 16 | 17 | 执行任意单元错误,会出现如下错误 18 | 19 | ``` 20 | java.lang.NoClassDefFoundError: com/facebook/presto/spi/analyzer/QueryAnalyzer 21 | 22 | at java.lang.ClassLoader.defineClass1(Native Method) 23 | at java.lang.ClassLoader.defineClass(ClassLoader.java:757) 24 | at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 25 | at java.net.URLClassLoader.defineClass(URLClassLoader.java:473) 26 | at java.net.URLClassLoader.access$100(URLClassLoader.java:74) 27 | at java.net.URLClassLoader$1.run(URLClassLoader.java:369) 28 | at java.net.URLClassLoader$1.run(URLClassLoader.java:363) 29 | at java.security.AccessController.doPrivileged(Native Method) 30 | at java.net.URLClassLoader.findClass(URLClassLoader.java:362) 31 | at java.lang.ClassLoader.loadClass(ClassLoader.java:419) 32 | at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352) 33 | at java.lang.ClassLoader.loadClass(ClassLoader.java:352) 34 | at com.facebook.presto.server.ServerMainModule.setup(ServerMainModule.java:308) 35 | at com.facebook.airlift.configuration.AbstractConfigurationAwareModule.configure(AbstractConfigurationAwareModule.java:43) 36 | at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:344) 37 | at com.google.inject.spi.Elements.getElements(Elements.java:103) 38 | at com.google.inject.spi.Elements.getElements(Elements.java:96) 39 | at com.facebook.airlift.configuration.ConfigurationFactory.registerConfigurationClasses(ConfigurationFactory.java:164) 40 | at com.facebook.airlift.bootstrap.Bootstrap.initialize(Bootstrap.java:210) 41 | at com.facebook.presto.server.testing.TestingPrestoServer.(TestingPrestoServer.java:338) 42 | at com.facebook.presto.tests.DistributedQueryRunner.createTestingPrestoServer(DistributedQueryRunner.java:397) 43 | at com.facebook.presto.tests.DistributedQueryRunner.(DistributedQueryRunner.java:273) 44 | at com.facebook.presto.tests.DistributedQueryRunner.(DistributedQueryRunner.java:97) 45 | at com.facebook.presto.tests.DistributedQueryRunner$Builder.build(DistributedQueryRunner.java:996) 46 | at com.zhihu.presto.plugin.auditlog.persistence.TestAuditLogEventListenerToKafka.createQueryRunner(TestAuditLogEventListenerToKafka.java:57) 47 | at com.facebook.presto.tests.AbstractTestQueryFramework.init(AbstractTestQueryFramework.java:83) 48 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 49 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 50 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 51 | at java.lang.reflect.Method.invoke(Method.java:498) 52 | at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104) 53 | at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515) 54 | at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217) 55 | at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:144) 56 | at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:169) 57 | at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) 58 | at org.testng.TestRunner.privateRun(TestRunner.java:756) 59 | at org.testng.TestRunner.run(TestRunner.java:610) 60 | at org.testng.SuiteRunner.runTest(SuiteRunner.java:387) 61 | at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382) 62 | at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340) 63 | at org.testng.SuiteRunner.run(SuiteRunner.java:289) 64 | at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 65 | at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) 66 | at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293) 67 | at org.testng.TestNG.runSuitesLocally(TestNG.java:1218) 68 | at org.testng.TestNG.runSuites(TestNG.java:1133) 69 | at org.testng.TestNG.run(TestNG.java:1104) 70 | at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:65) 71 | at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:105) 72 | Caused by: java.lang.ClassNotFoundException: com.facebook.presto.spi.analyzer.QueryAnalyzer 73 | at java.net.URLClassLoader.findClass(URLClassLoader.java:387) 74 | at java.lang.ClassLoader.loadClass(ClassLoader.java:419) 75 | at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352) 76 | at java.lang.ClassLoader.loadClass(ClassLoader.java:352) 77 | ... 50 more 78 | 79 | 80 | Test ignored. 81 | 82 | =============================================== 83 | Default Suite 84 | Total tests run: 1, Failures: 0, Skips: 1 85 | Configuration Failures: 1, Skips: 0 86 | =============================================== 87 | ``` 88 | 89 | 发现引的包中,确实没有 90 | 91 | ![](vx_images/339875002621059.png) 92 | 93 | ![](vx_images/246882090600868.png) 94 | 95 | ![](vx_images/115512475986257.png) 96 | 97 | ## 检查社区的分支代码 98 | 99 | 找到问题了,我选择的版本与实际社区tag发布的版本,中间有几个pr的差距(漏了一些代码),找了几个历史的 tag 以及 branch 发现我是截取版本的时候选错了 100 | 101 | ![](vx_images/369126348320646.png) 102 | 103 | ![](vx_images/557284614693796.png) 104 | 105 | 106 | 107 | ## 历史 tag 108 | 109 | 110 | ![](vx_images/262958444662955.png) 111 | 112 | ![](vx_images/58245429538637.png) 113 | 114 | 115 | 116 | ![](vx_images/203137896913893.png) 117 | 118 | 119 | 120 | ## 总结 121 | 122 | 建议以后在选择源代码版本时,最好选带有 prepare release 的 pr 后,代表已经封版,可以 checkout 了。 123 | -------------------------------------------------------------------------------- /10_问题总结/hive元数据连接超时.md: -------------------------------------------------------------------------------- 1 | # hive元数据连接超时 2 | 3 | [返回目录](../README.md) 4 | 5 | --- 6 | 7 | ## 错误信息 8 | 9 | EXTERNAL HIVE_METASTORE_ERROR (16777216) 10 | 11 | ``` 12 | com.facebook.presto.spi.PrestoException: hive的元数据地址: java.net.SocketTimeoutException: Read timed out 13 | at com.facebook.presto.hive.metastore.thrift.ThriftHiveMetastore.getTable(ThriftHiveMetastore.java:221) 14 | at com.facebook.presto.hive.metastore.thrift.BridgingHiveMetastore.getTable(BridgingHiveMetastore.java:82) 15 | at com.facebook.presto.hive.metastore.CachingHiveMetastore.loadTable(CachingHiveMetastore.java:257) 16 | at com.google.common.cache.CacheLoader$FunctionToCacheLoader.load(CacheLoader.java:165) 17 | at com.google.common.cache.CacheLoader$1.load(CacheLoader.java:188) 18 | at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524) 19 | at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2273) 20 | at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2156) 21 | at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2046) 22 | at com.google.common.cache.LocalCache.get(LocalCache.java:3943) 23 | at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3967) 24 | at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4952) 25 | at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4958) 26 | at com.facebook.presto.hive.metastore.CachingHiveMetastore.get(CachingHiveMetastore.java:207) 27 | at com.facebook.presto.hive.metastore.CachingHiveMetastore.getTable(CachingHiveMetastore.java:252) 28 | ``` 29 | 30 | 对应sql 31 | 32 | ```sql 33 | SHOW COLUMNS FROM " 34 | 里面是一个常规的查询语句 35 | " 36 | ``` 37 | 38 | ## 解决方案 39 | 40 | 表象是 hive 元数据连接超时。 41 | 42 | 实际应该是不支持这种sql。可是sql解析是过了,走到执行的逻辑了,进行相应执行的时候报错。 43 | 44 | 经过沟通发现,有一些业务为会为了长时间保持能够顺利快速的查询(因为presto在第一次建立连接查询时,速度较慢)会在本机配置一个自动任务,每隔一段时间来执行一个sql,然后很巧的是我们的业务大部分都是使用这样的sql,来保持与presto的长连接,以达到查询的尴尬提速。 45 | 46 | 这变相算是一个使用体验的问题把。 47 | -------------------------------------------------------------------------------- /10_问题总结/jdbc错误.md: -------------------------------------------------------------------------------- 1 | # jdbc错误 2 | 3 | [返回目录](../README.md) 4 | 5 | --- 6 | 7 | 8 | ## 错误信息 9 | 10 | EXTERNAL JDBC_ERROR (67108864) 11 | 12 | Attempted reconnect 3 times 13 | 14 | ``` 15 | com.facebook.presto.spi.PrestoException: Could not create connection to database server. Attempted reconnect 3 times. Giving up. 16 | at com.facebook.presto.plugin.jdbc.JdbcRecordCursor.handleSqlException(JdbcRecordCursor.java:236) 17 | at com.facebook.presto.plugin.jdbc.JdbcRecordCursor.(JdbcRecordCursor.java:95) 18 | at com.facebook.presto.plugin.jdbc.JdbcRecordSet.cursor(JdbcRecordSet.java:59) 19 | at com.facebook.presto.spi.RecordPageSource.(RecordPageSource.java:37) 20 | at com.facebook.presto.split.RecordPageSourceProvider.createPageSource(RecordPageSourceProvider.java:42) 21 | at com.facebook.presto.split.PageSourceManager.createPageSource(PageSourceManager.java:56) 22 | at com.facebook.presto.operator.ScanFilterAndProjectOperator.getOutput(ScanFilterAndProjectOperator.java:216) 23 | at com.facebook.presto.operator.Driver.processInternal(Driver.java:373) 24 | at com.facebook.presto.operator.Driver.lambda$processFor$8(Driver.java:282) 25 | at com.facebook.presto.operator.Driver.tryWithLock(Driver.java:672) 26 | at com.facebook.presto.operator.Driver.processFor(Driver.java:276) 27 | at com.facebook.presto.execution.SqlTaskExecution$DriverSplitRunner.processFor(SqlTaskExecution.java:973) 28 | at com.facebook.presto.execution.executor.PrioritizedSplitRunner.process(PrioritizedSplitRunner.java:162) 29 | at com.facebook.presto.execution.executor.TaskExecutor$TaskRunner.run(TaskExecutor.java:492) 30 | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 31 | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 32 | at java.lang.Thread.run(Thread.java:745) 33 | Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up. 34 | at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 35 | at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 36 | at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 37 | at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 38 | ``` 39 | 40 | 41 | ## 解决方案 42 | 43 | jdbc连接有问题,请检查连接字符串,账号,密码,网络。 -------------------------------------------------------------------------------- /10_问题总结/mongodb连接异常MongoTimeoutException.md: -------------------------------------------------------------------------------- 1 | # mongodb连接异常MongoTimeoutException 2 | 3 | [返回目录](../README.md) 4 | 5 | --- 6 | 7 | ## 错误信息 8 | 9 | com.mongodb.MongoTimeoutException 10 | 11 | INTERNAL_ERROR GENERIC_INTERNAL_ERROR (65536) 12 | 13 | ``` 14 | com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=10.100.15.69:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='bigdata', source='eagle_riskcon_third', password=, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server 10.100.15.69:27017. The full response is { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }}}] 15 | at com.mongodb.connection.BaseCluster.getDescription(BaseCluster.java:167) 16 | at com.mongodb.Mongo.getConnectedClusterDescription(Mongo.java:881) 17 | at com.mongodb.Mongo.createClientSession(Mongo.java:873) 18 | at com.mongodb.Mongo$3.getClientSession(Mongo.java:862) 19 | at com.mongodb.Mongo$3.execute(Mongo.java:819) 20 | at com.mongodb.MongoIterableImpl.execute(MongoIterableImpl.java:130) 21 | at com.mongodb.MongoIterableImpl.iterator(MongoIterableImpl.java:77) 22 | at com.mongodb.MappingIterable.iterator(MappingIterable.java:40) 23 | at com.mongodb.MappingIterable.iterator(MappingIterable.java:24) 24 | at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:234) 25 | at com.facebook.presto.mongodb.MongoSession.getAllSchemas(MongoSession.java:131) 26 | at com.facebook.presto.mongodb.MongoMetadata.listSchemaNames(MongoMetadata.java:72) 27 | at com.facebook.presto.mongodb.MongoMetadata.listSchemas(MongoMetadata.java:291) 28 | at com.facebook.presto.mongodb.MongoMetadata.listTables(MongoMetadata.java:101) 29 | ``` 30 | 31 | ## 解决方案 32 | 33 | 检查mongodb连接的账号,密码,网络,能否正常连接 -------------------------------------------------------------------------------- /10_问题总结/vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2021-08-16T01:44:18Z", 3 | "files": [ 4 | { 5 | "attachment_folder": "", 6 | "created_time": "2021-08-16T01:44:18Z", 7 | "id": "9", 8 | "modified_time": "2021-08-16T01:44:18Z", 9 | "name": "hive元数据连接超时.md", 10 | "signature": "5020030538247903327", 11 | "tags": [ 12 | ] 13 | }, 14 | { 15 | "attachment_folder": "", 16 | "created_time": "2021-08-16T01:44:18Z", 17 | "id": "10", 18 | "modified_time": "2021-08-16T01:44:18Z", 19 | "name": "jdbc错误.md", 20 | "signature": "5463993087068018783", 21 | "tags": [ 22 | ] 23 | }, 24 | { 25 | "attachment_folder": "", 26 | "created_time": "2021-08-16T01:44:18Z", 27 | "id": "11", 28 | "modified_time": "2021-08-16T01:44:18Z", 29 | "name": "mongodb连接异常MongoTimeoutException.md", 30 | "signature": "863583513866213471", 31 | "tags": [ 32 | ] 33 | }, 34 | { 35 | "attachment_folder": "", 36 | "created_time": "2021-08-16T01:44:18Z", 37 | "id": "12", 38 | "modified_time": "2021-08-16T01:44:18Z", 39 | "name": "where子句中在对char类型进行判断时需要手动补齐空格.md", 40 | "signature": "5621503432031541343", 41 | "tags": [ 42 | ] 43 | }, 44 | { 45 | "attachment_folder": "", 46 | "created_time": "2021-08-16T01:44:18Z", 47 | "id": "13", 48 | "modified_time": "2021-08-16T01:44:18Z", 49 | "name": "worker资源问题.md", 50 | "signature": "3986890418781493343", 51 | "tags": [ 52 | ] 53 | }, 54 | { 55 | "attachment_folder": "", 56 | "created_time": "2021-08-16T01:44:18Z", 57 | "id": "14", 58 | "modified_time": "2021-08-16T01:44:18Z", 59 | "name": "时区问题.md", 60 | "signature": "5529866374876305503", 61 | "tags": [ 62 | ] 63 | }, 64 | { 65 | "attachment_folder": "", 66 | "created_time": "2021-08-16T01:44:18Z", 67 | "id": "15", 68 | "modified_time": "2021-08-16T01:44:18Z", 69 | "name": "最大查询内存问题.md", 70 | "signature": "7793080107100346463", 71 | "tags": [ 72 | ] 73 | }, 74 | { 75 | "attachment_folder": "", 76 | "created_time": "2021-08-16T01:44:18Z", 77 | "id": "16", 78 | "modified_time": "2021-08-16T01:44:18Z", 79 | "name": "调试代码的超时限制.md", 80 | "signature": "4541422622849701983", 81 | "tags": [ 82 | ] 83 | }, 84 | { 85 | "attachment_folder": "", 86 | "created_time": "2021-08-16T01:44:18Z", 87 | "id": "17", 88 | "modified_time": "2021-08-16T01:44:18Z", 89 | "name": "资源文件加载错误.md", 90 | "signature": "7128250462811265119", 91 | "tags": [ 92 | ] 93 | }, 94 | { 95 | "attachment_folder": "351517866742361", 96 | "created_time": "2023-12-14T05:52:20Z", 97 | "id": "73", 98 | "modified_time": "2024-07-14T09:15:34Z", 99 | "name": "Presto格式错误造成的分区问题.md", 100 | "signature": "1633471550090567806", 101 | "tags": [ 102 | ] 103 | }, 104 | { 105 | "attachment_folder": "", 106 | "created_time": "2024-04-01T03:16:21Z", 107 | "id": "69", 108 | "modified_time": "2024-07-14T10:35:28Z", 109 | "name": "Presto单元测试错误NoClassDefFoundError_QueryAnalyzer_引发的版本使用思考.md", 110 | "signature": "2330193663017756421", 111 | "tags": [ 112 | ] 113 | }, 114 | { 115 | "attachment_folder": "", 116 | "created_time": "2024-07-07T14:28:31Z", 117 | "id": "67", 118 | "modified_time": "2024-07-14T10:42:51Z", 119 | "name": "Presto中文问题.md", 120 | "signature": "5328176308462200335", 121 | "tags": [ 122 | ] 123 | } 124 | ], 125 | "folders": [ 126 | ], 127 | "id": "23", 128 | "modified_time": "2021-08-16T01:44:18Z", 129 | "signature": "660964420177959007", 130 | "version": 3 131 | } 132 | -------------------------------------------------------------------------------- /10_问题总结/vx_images/107263619547778.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/107263619547778.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/1078300593177.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/1078300593177.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/115512475986257.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/115512475986257.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/1215551671874.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/1215551671874.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/14549361614771.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/14549361614771.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/146363469472.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/146363469472.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/148752363847808.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/148752363847808.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/160963098844181.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/160963098844181.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/1800144444812.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/1800144444812.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/191142718090892.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/191142718090892.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/191177125652406.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/191177125652406.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/19577298602209.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/19577298602209.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/2005299574600.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/2005299574600.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/203137896913893.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/203137896913893.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/2045562163097.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/2045562163097.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/214481170862.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/214481170862.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/2196298922820.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/2196298922820.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/223964892608728.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/223964892608728.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/225804850777017.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/225804850777017.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/244771758758785.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/244771758758785.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/246882090600868.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/246882090600868.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/2566103443096.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/2566103443096.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/257604956063267.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/257604956063267.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/262958444662955.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/262958444662955.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/285775110754955.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/285775110754955.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/291885947698598.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/291885947698598.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/301638517892509.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/301638517892509.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/3033819718538.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/3033819718538.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/305716597429480.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/305716597429480.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/3204584276638.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/3204584276638.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/322604660699775.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/322604660699775.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/327754023446618.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/327754023446618.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/332297616282127.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/332297616282127.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/3335472797305.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/3335472797305.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/3349053077910.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/3349053077910.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/339875002621059.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/339875002621059.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/343346196443217.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/343346196443217.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/352834390551619.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/352834390551619.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/355356834802337.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/355356834802337.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/35842945923969.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/35842945923969.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/362755068519.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/362755068519.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/363187092916256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/363187092916256.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/36536341488404.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/36536341488404.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/369126348320646.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/369126348320646.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/3705692654505.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/3705692654505.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/39516826390430.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/39516826390430.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/422414765160088.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/422414765160088.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/427880250882555.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/427880250882555.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/428523785782088.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/428523785782088.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/436624884811282.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/436624884811282.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/4384372556512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/4384372556512.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/4395812035064.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/4395812035064.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/443322569735556.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/443322569735556.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/4492481668548.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/4492481668548.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/454212582145133.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/454212582145133.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/459560430293491.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/459560430293491.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/463896361320.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/463896361320.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/478280093084983.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/478280093084983.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/483733314612566.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/483733314612566.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/494364772493207.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/494364772493207.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/4965414017353.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/4965414017353.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/497897334675262.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/497897334675262.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/4998514568932.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/4998514568932.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/503626100864430.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/503626100864430.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/503742361791927.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/503742361791927.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/5071939567072.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/5071939567072.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/513823458707232.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/513823458707232.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/515567381056820.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/515567381056820.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/523448288271116.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/523448288271116.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/537397430428683.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/537397430428683.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/540757777357895.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/540757777357895.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/541762556517475.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/541762556517475.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/5545322874819.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/5545322874819.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/557284614693796.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/557284614693796.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/561473734062577.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/561473734062577.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/561675572246622.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/561675572246622.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/567996697694.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/567996697694.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/58245429538637.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/58245429538637.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/585550282763108.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/585550282763108.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/587220763239901.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/587220763239901.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/594527359238562.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/594527359238562.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/597193917531306.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/597193917531306.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/63053974823146.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/63053974823146.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/69182329661.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/69182329661.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/72005586214681.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/72005586214681.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/75323991899565.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/75323991899565.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/76116832182834.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/76116832182834.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/838803859055.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/838803859055.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/93255085597983.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/93255085597983.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/96412428061650.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/96412428061650.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/98241323900472.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/98241323900472.png -------------------------------------------------------------------------------- /10_问题总结/vx_images/98447957403437.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/10_问题总结/vx_images/98447957403437.png -------------------------------------------------------------------------------- /10_问题总结/where子句中在对char类型进行判断时需要手动补齐空格.md: -------------------------------------------------------------------------------- 1 | # where子句中在对char类型进行判断时需要手动补齐空格 2 | 3 | [返回目录](../README.md) 4 | 5 | --- 6 | 7 | 8 | ## 问题描述 9 | 10 | 当查询语句where中有char类型的字段,需要强制使用空格填充才能查到对应数据。 11 | 12 | 但是其他引擎中,比如mysql,char类型在进入where子句判断时,是会自动去除空格的。 13 | 14 | ![](vx_images/4492481668548.png) 15 | 16 | 不带空格的话,是无法查到的。 17 | 18 | ![](vx_images/2196298922820.png) 19 | 20 | 同样适用trim函数,等等也无法查到。 21 | 22 | 查了下官方的issues。这里也是推荐用户手动补齐空格。比较尴尬。 23 | 24 | ![](vx_images/2045562163097.png) 25 | 26 | 以下是我问题的解决思路: 27 | 28 | 我认为有2个方向,在执行计划优化的时候对这一块的类型进行操作,或者在最后执行的时候对其进行自动空格补齐或者去除。 29 | 30 | 那么需要定位到这2个地方。可是我目前不太确定这2个地方的精确位置在哪。 31 | 32 | 首先找了一些关于char类型实现的和讨论: 33 | 34 | 官方对char类型的开发issue https://github.com/prestodb/presto/issues/5320 35 | 36 | 有其他用户提出char的相关讨论 issue https://github.com/prestodb/presto/issues/9590 与 https://github.com/trinodb/trino/issues/3456 37 | 38 | 这些讨论都没有线索。 39 | 40 | 我想了想,如果用最快的方式实现的话,应该就是在最末尾执行时对其进行空格补齐或者统一去除。那么这样可以暂时排除在优化阶段去实现。 41 | 42 | 这样的话,其实就与hive的隐式转换中的类型转换有点像了。这里参考了网上的一篇博客,并借鉴了hive的思路。 43 | 44 | 大致原理为,我们在引擎中肯定会对各种类型进行封装,比如varchar,char,boolean等等。会封装成VarcharType,CharType等。而且它们又都是在`com.facebook.presto.spi.type` 包中。 45 | 46 | ![](vx_images/3349053077910.png) 47 | 48 | 按照presto的spi习惯,有个type的接口设计,肯定就会有相关的type实现。 49 | 50 | 于是我找了找核心模块里,确实是有的 51 | 52 | ![](vx_images/3335472797305.png) 53 | 54 | 再看里面的类,基本上就明白了一大半了。 55 | 56 | ![](vx_images/1800144444812.png) 57 | 58 | 看了里面的代码,进一步确定了,这些`Operators`就是各种类型的具体操作的定义,比如 `比较`,`计算`,等等。但是这里面的代码有个很关键的地方,就比如char举例,它就只能与char类型的数据进行操作,不支持与其他类型操作。 59 | 60 | 这里与hive比较,基本上可以理解为,presto根本就没去实现隐式转换之类的相关操作。 61 | 62 | 同时我也看了看trino里的代码,貌似也没实现。 63 | 64 | ## 解决方案 65 | 66 | 都已经找到地方了,先测试测试试试,做一个简单的修改。 67 | 68 | ![](vx_images/214481170862.png) 69 | 70 | 这样修改后,确实是可以了。 71 | 72 | 原始数据 73 | 74 | ![](vx_images/3705692654505.png) 75 | 76 | 不带空格能查到 77 | 78 | ![](vx_images/4965414017353.png) 79 | 80 | 带空格也能查到,相当于与mysql的方式兼容了 81 | 82 | ![](vx_images/838803859055.png) 83 | 84 | ## 补充知识 85 | 86 | 默认情况下,char类型采用右补空格的方式来填充字符串至规定的长度, 87 | 88 | 下面是测试情况 89 | 90 | ```sql 91 | CREATE TABLE `test` ( 92 | `name1` char(20) NOT NULL, 93 | `name2` varchar(20) NOT NULL 94 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 95 | ``` 96 | 97 | ```sql 98 | INSERT INTO `test` VALUES (' haha ', ' heihei '); 99 | ``` 100 | 101 | 查询一下 102 | 103 | ```sql 104 | SELECT CONCAT( '+', name1, '+' ) , CONCAT( '+', name2, '+' ) FROM test 105 | ``` 106 | 107 | ![](vx_images/2005299574600.png) 108 | 109 | 可以看出,char类型的字段,左右空格全部被去除,而varchar类型的字段,左边空格去除,右边空格保留。 110 | 111 | 官方文档中的解释 112 | 113 | https://dev.mysql.com/doc/refman/5.7/en/char.html 114 | 115 | 比如这一段 116 | 117 | ``` 118 | The length of a CHAR column is fixed to the length that you declare when you create the table. The length can be any value from 0 to 255. When CHAR values are stored, they are right-padded with spaces to the specified length. When CHAR values are retrieved, trailing spaces are removed unless the PAD_CHAR_TO_FULL_LENGTH SQL mode is enabled. 119 | ``` 120 | 121 | 当存储CHAR值时,会将余量数据用指定长度的空格右填充。 122 | 123 | 检索CHAR值时,将删除尾随空格,除非启用了PAD_CHAR_TO_FULL_LENGTH SQL模式。 124 | 125 | 注意,这里的解释,也就是说如果你主动存了空格,在检索的时候也会把空格一并删除。 126 | 127 | 所以,需要存空格的数据,是不会使用char类型去存储的。 128 | 129 | 为什么要用char,与varchar有什么区别。 130 | 131 | 主要优点:char是固定长度,固定长度的检索是要比动态长度的varchar检索要快速。 132 | 133 | --- 134 | 135 | 参考 136 | 137 | - https://only2yangcao.github.io/2019/03/29/2019-03-29-Presto%E9%9A%90%E5%BC%8F%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2/ -------------------------------------------------------------------------------- /10_问题总结/worker资源问题.md: -------------------------------------------------------------------------------- 1 | # worker资源问题 2 | 3 | [返回目录](../README.md) 4 | 5 | --- 6 | 7 | ## 问题描述 8 | 9 | 错误日志如下 10 | 11 | ``` 12 | com.facebook.presto.operator.PageTransportTimeoutException: 13 | Encountered too many errors talking to a worker node. The node may have crashed or be under too much load. 14 | This is probably a transient issue, so please retry your query in a few minutes. 15 | (http://127.0.0.1:8088/v1/task/20210508_030016_00135_dze99.6.4/results/3/0 - 169 failures, failure duration 300.36s, total failed request time 310.36s) 16 | at com.facebook.presto.operator.HttpPageBufferClient$1.onFailure(HttpPageBufferClient.java:411) 17 | at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1341) 18 | at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 19 | at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 20 | at java.lang.Thread.run(Thread.java:745) 21 | Caused by: java.lang.RuntimeException: java.util.concurrent.TimeoutException: Total timeout 10000 ms 22 | ``` 23 | 24 | ``` 25 | 10-05-2021 07:36:25 CST dws_ph_contract_orderno_fact_3_3_run INFO - Query 26 | 20210509_233038_07389_qp3na 27 | failed: Encountered too many errors talking to a worker node. The node may have crashed or be under too much load. 28 | This is probably a transient issue, so please retry your query in a few minutes. 29 | (http://127.0.0.1:8088/v1/task/20210509_233038_07389_qp3na.2.11/results/10/0 - 168 failures, failure duration 302.41s, total failed request time 312.41s) 30 | ``` 31 | 32 | 用户侧的表现就是查询执行失败,并出现该错误。 33 | 34 | 根据现状有两种可能: 35 | 36 | - 真的计算到内存不够了。 37 | 38 | - 资源队列划分的不合理。 39 | 40 | ## 社区讨论 41 | 42 | 发起者 hong 43 | 44 | ``` 45 | do you have any idea about this Exception: 46 | 47 | io.prestosql.operator.PageTransportTimeoutException: Encountered too many errors talking to a worker node. 48 | 49 | In my experience, this happens all the time when testing high concurrency queries. 50 | One worker will Full GC(or even worse OOM), so other worker can't talk to the worker. 51 | Here is some solution in my mind: 52 | 53 | 1. reduce the Full GC, can we tune some JVM G1 properties to reduce or avoid the Full GC? 54 | 2. is there a configuration of Presto which can tuning the time of workers' http timeout, so maybe after the Full GC, the worker can still go back and the query won't fail. 55 | 56 | how about your suggestiones, thanks! 57 | ``` 58 | 59 | 有人推荐了一种jvm的参数配置 60 | 61 | ![](vx_images/5545322874819.png) 62 | 63 | ``` 64 | BTW, We try to tune some Presto configuration such as "task.client.timeout=60s , exchange.http-client.request-timeout=600s, query.remote-task.min-error-duration=5s " which aimed at make the coordenator and work can communicate with each after Full GC, But it seems not work well. When one of the workers under Full GC, the coordinator will lost the worker soon. 65 | is there other properties to make it ok?So maybe after the Full GC, the worker can still go back and the query won't fail 66 | ``` 67 | 68 | 另一个回复 69 | 70 | ``` 71 | if you are having super long GC pauses, it's either poorly formed queries, or custom logic/functionality that does too much object invocation, or a bug in Presto. 72 | As you can see from the Yarn blog post - switching to Java 11 helped a lot. There are no magic configuration parameters in GC that are going to fix your GC problems. 73 | ``` 74 | 75 | 作者回复 76 | 77 | ``` 78 | the full gc usually take 1-2minutes. is this too long to make it faster? change java version is not easy especially on product env 79 | ``` 80 | 81 | 另一个回复,主要还是使用G1GC 82 | 83 | ``` 84 | Full GC that is 1-2 minutes, is REALLY LONG. You are stopping the world, pausing all code execution for 2 minutes. 85 | This is a simple introduction to GC tuning with GC1 - https://www.lewuathe.com/tuning-g1-gc-algorithm-on-jvm.html 86 | Read that, try to play. 87 | Also I'm not sure how much memory you are giving Presto, (it depends on the JVM version) but the JVM typically starts struggling to keep up with memory allocation beyond 32GB (on high end servers and modern JVM) you can go up somewhere around 45GB 88 | 89 | The First Cry of AtomThe First Cry of Atom 90 | Tuning G1 GC algorithm on JVM 91 | Recently I faced the necessity to tune garbage collection of our Java application. The application is Presto , distributed query execution engine. It requires a lot of memory but needs to achieve high throughput and low latency. So I read a book about tuning Java applications. 92 | ``` 93 | 94 | 社区回复 觉得堆内存少了,应该大一点 95 | 96 | ``` 97 | 32 is pretty little for Presto. We run eg 180 g heap. 98 | However mind that duration of full GC depends on Java version and CPU speed. If something else is hogging in the background, it will take longer to clean the heap up 99 | ``` 100 | 101 | 最后作者回复 102 | 103 | 都有大内存,说到当并发数上来后,问题还是会出现 104 | 105 | ``` 106 | We have 200GB memory each node while the cluster has 15 workers. One important thing is that even the worker has 300 or 500GB memory, query can still failed due to the concurrency comes to 100. maybe, is this a unavoidable problem which can solve perfectly only by add more resources? 107 | ``` 108 | 109 | 目前的思路就是,可能真是内存的问题。但是现在因为对presto的内存池没有很好的理解。所以比较快速的解决方案,应该是对jvm的参数进行调整,然后搭配用户行为监控。 110 | 111 | ## 解决方案 112 | 113 | 参考了一些朋友的设置,将jvm参数修改成这样后,效果稍微好了一点。 114 | 115 | 配置1 116 | 117 | ``` 118 | -XX:G1ReservePercent=15 119 | -XX:InitiatingHeapOccupancyPercent=40 120 | -XX:ConcGCThreads=8 121 | ``` 122 | 123 | 配置2 124 | 125 | ![](vx_images/69182329661.png) 126 | 127 | 主要是下面3条 128 | 129 | ``` 130 | -XX:PerMethodRecompilationCutoff=10000 131 | -XX:PerBytecodeRecompilationCutoff=10000 132 | 133 | -Djdk.nio.maxCachedBufferSize=2000000 134 | ``` 135 | 136 | --- 137 | 138 | 参考 139 | 140 | - https://trinodb.slack.com/archives/CFLB9AMBN/p1573089763478100 141 | - http://armsword.com/2018/05/22/the-memory-management-and-tuning-experience-of-presto/ -------------------------------------------------------------------------------- /10_问题总结/时区问题.md: -------------------------------------------------------------------------------- 1 | # 时区问题 2 | 3 | [返回目录](../README.md) 4 | 5 | --- 6 | 7 | ## 问题描述 8 | 9 | presto的部署节点与相应的catalog,都处于其他时区,比如东7区的 `Asia/Jakarta`。 10 | 11 | presto的客户端可能处于其他时区,比如东8区的 `Asia/Shanghai`。 12 | 13 | presto的逻辑是会将双方的时间都先转成UTC,然后再转换成对应的本地时间。 14 | 15 | 比如要在东8区查询数据范围 `10点-20点` 的数据,那么presto会自动将其转换为对应时区的本地时间。比如东7区的话就会转换为 `9点-19点`。 16 | 17 | 此时需要明确业务想要查询的数据时间范围。 18 | 19 | 最终是想查询数据源的 `本地时间` 还是 `对应时间`。 20 | 21 | - 本地时间:在客户端查询 `10点-20点` 的数据 就等于 服务端查询对应时区的本地时区时间,比如东7区就是 `9点-19点`。 22 | - 对应时间:在客户端查询 `10点-20点` 的数据 就等于 东7区的 `10点-20点` 23 | 24 | ## 解决方案 25 | 26 | 有两种解决方案,在sql中使用时区函数,或者修改服务端时区代码。 27 | 28 | ### 时区函数 29 | 30 | 在时间字段后面添加 `AT TIME ZONE 时区` 比如 `AT TIME ZONE 'Asia/Jakarta'`。 31 | 32 | 原始sql查询 33 | 34 | ![](vx_images/5071939567072.png) 35 | 36 | 使用时区函数查询 37 | 38 | ![](vx_images/3033819718538.png) 39 | 40 | ### 修改服务端 41 | 42 | 因为presto jdbc driver的性质,不能像常规jdbc那样,自己设置时区。 43 | 44 | 比如在连接字符串里设置这个字段 45 | 46 | ![](vx_images/1078300593177.png) 47 | 48 | presto设置了就会出现如下错误 49 | 50 | ``` 51 | Unrecognized connection property 'serverTimezone' 52 | ``` 53 | 54 | 其实就是客户端的代码逻辑里没支持这些。不让用户自己设置。 55 | 56 | 跟源码里发现,如果用户没设置,在建立连接时,就会读操作系统的默认时区。 57 | 58 | ![](vx_images/4384372556512.png) 59 | 60 | 那么如果想实现第二种,对应时间的话。 61 | 62 | 就是去修改服务端session相关的代码,将里面转换时区的逻辑暂时取消,让用户连接进去后,不接收客户端的时区,全用服务端的时区。 63 | 64 | 代码逻辑大致如下: 65 | 66 | `com.facebook.presto.server.HttpRequestSessionContext` 67 | 68 | ``` 69 | // timeZoneId = servletRequest.getHeader(PRESTO_TIME_ZONE); 70 | log.debug("time zone we got from client: %s, but we just ignore it, to use server time zone: %s", 71 | servletRequest.getHeader(PRESTO_TIME_ZONE), TimeZone.getDefault().getID()); 72 | timeZoneId = null; 73 | ``` -------------------------------------------------------------------------------- /10_问题总结/最大查询内存问题.md: -------------------------------------------------------------------------------- 1 | # 最大查询内存问题 2 | 3 | [返回目录](../README.md) 4 | 5 | --- 6 | 7 | ## 问题信息 8 | 9 | ``` 10 | 1) Error injecting constructor, java.lang.IllegalArgumentException: Max query memory per node cannot be greater than the max query total memory per node. 11 | at com.facebook.presto.memory.LocalMemoryManager.(LocalMemoryManager.java:46) 12 | at com.facebook.presto.server.ServerMainModule.setup(ServerMainModule.java:320) 13 | while locating com.facebook.presto.memory.LocalMemoryManager 14 | for the 6th parameter of com.facebook.presto.execution.SqlTaskManager.(SqlTaskManager.java:120) 15 | at com.facebook.presto.server.ServerMainModule.setup(ServerMainModule.java:307) 16 | while locating com.facebook.presto.execution.SqlTaskManager 17 | while locating com.facebook.presto.execution.TaskManager 18 | for the 1st parameter of com.facebook.presto.server.TaskResource.(TaskResource.java:102) 19 | at com.facebook.presto.server.ServerMainModule.setup(ServerMainModule.java:304) 20 | while locating com.facebook.presto.server.TaskResource 21 | at io.airlift.jaxrs.JaxrsBinder.bind(JaxrsBinder.java:33) 22 | while locating java.lang.Object annotated with @com.google.inject.internal.Element(setName=@io.airlift.jaxrs.JaxrsResource,uniqueId=202, type=MULTIBINDER, keyType=) 23 | while locating java.util.Set annotated with @io.airlift.jaxrs.JaxrsResource() 24 | for the 1st parameter of io.airlift.jaxrs.JaxrsModule.createJaxRsApplication(JaxrsModule.java:94) 25 | at io.airlift.jaxrs.JaxrsModule.createJaxRsApplication(JaxrsModule.java:94) 26 | while locating javax.ws.rs.core.Application 27 | for the 1st parameter of io.airlift.jaxrs.JaxrsModule.createResourceConfig(JaxrsModule.java:87) 28 | ``` 29 | 30 | ## 解决方案 31 | 32 | 配置中的不合理 33 | 34 | etc/config.properties 中配置了 query.max-total-memory-per-node 参数,且配置的值比较低。 35 | 36 | 比如如下配置,就会出现该错误。 37 | 38 | ``` 39 | coordinator=false 40 | discovery-server.enabled=true 41 | discovery.uri=http://127.0.0.1:8088 42 | http-server.http.port=5797 43 | query.max-memory=100GB 44 | query.max-memory-per-node=10GB 45 | query.max-total-memory-per-node=2GB 46 | ``` 47 | 48 | 应该是 query.max-total-memory-per-node `大于` query.max-memory-per-node -------------------------------------------------------------------------------- /10_问题总结/调试代码的超时限制.md: -------------------------------------------------------------------------------- 1 | # 调试代码的超时限制 2 | 3 | [返回目录](../README.md) 4 | 5 | --- 6 | 7 | ## 问题描述 8 | 9 | 在进行源代码调试的时候,会容易出现一个超时错误,错误现象如下 10 | 11 | ![](vx_images/2566103443096.png) 12 | 13 | 这个逻辑主要是在优化器优化的的阶段。 14 | 15 | 默认超时限制是180秒?我们仔细想想,什么样的sql需要180秒的优化时间?这么长肯定有问题了。 16 | 17 | ![](vx_images/4998514568932.png) 18 | 19 | 检查这个超过的具体代码位置为 20 | 21 | **presto** 22 | 23 | ![](vx_images/146363469472.png) 24 | 25 | ![](vx_images/1215551671874.png) 26 | 27 | **trino** 28 | 29 | ![](vx_images/3204584276638.png) 30 | 31 | ![](vx_images/4395812035064.png) 32 | 33 | ## 解决方案 34 | 35 | 如果我们要暂时忽略这个超时的话,可以在那个检测的地方,把超时检测的逻辑暂时注释掉 36 | 37 | 这样我们方便我们调试代码 38 | 39 | ![](vx_images/567996697694.png) -------------------------------------------------------------------------------- /10_问题总结/资源文件加载错误.md: -------------------------------------------------------------------------------- 1 | # 资源文件加载错误 2 | 3 | [返回目录](../README.md) 4 | 5 | --- 6 | 7 | ## 问题描述 8 | 9 | ``` 10 | 2021-06-13T11:26:25.520+0800 INFO main io.airlift.bootstrap.LifeCycleManager Life cycle starting... 11 | 2021-06-13T11:26:25.520+0800 INFO main io.airlift.bootstrap.LifeCycleManager Life cycle startup complete. System ready. 12 | 2021-06-13T11:26:25.521+0800 INFO main com.facebook.presto.metadata.StaticCatalogStore -- Added catalog mysql using connector mysql -- 13 | 2021-06-13T11:26:25.522+0800 INFO main com.facebook.presto.execution.resourceGroups.InternalResourceGroupManager -- Loading resource group configuration manager -- 14 | 2021-06-13T11:26:25.523+0800 ERROR main com.facebook.presto.server.PrestoServer Resource group configuration manager file is not registered 15 | java.lang.IllegalStateException: Resource group configuration manager file is not registered 16 | at com.google.common.base.Preconditions.checkState(Preconditions.java:585) 17 | at com.facebook.presto.execution.resourceGroups.InternalResourceGroupManager.setConfigurationManager(InternalResourceGroupManager.java:161) 18 | at com.facebook.presto.execution.resourceGroups.InternalResourceGroupManager.loadConfigurationManager(InternalResourceGroupManager.java:148) 19 | at com.facebook.presto.server.PrestoServer.run(PrestoServer.java:129) 20 | at com.facebook.presto.server.PrestoServer.main(PrestoServer.java:67) 21 | ``` 22 | 23 | ## 解决方案 24 | 25 | 检查名字和配置内容 26 | 27 | 如果是在开发模式的 话 28 | 29 | 需要在etc/config.properties中配置 30 | 31 | ``` 32 | ../presto-resource-group-managers/pom.xml 33 | ``` 34 | 35 | ![](vx_images/362755068519.png) -------------------------------------------------------------------------------- /11_性能优化/vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2024-07-15T07:35:14Z", 3 | "files": [ 4 | ], 5 | "folders": [ 6 | { 7 | "name": "缓存" 8 | } 9 | ], 10 | "id": "74", 11 | "modified_time": "2024-07-15T07:35:14Z", 12 | "signature": "4602395292922597682", 13 | "version": 3 14 | } 15 | -------------------------------------------------------------------------------- /11_性能优化/缓存/vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2024-07-15T07:35:15Z", 3 | "files": [ 4 | { 5 | "attachment_folder": "", 6 | "created_time": "2024-07-15T07:35:16Z", 7 | "id": "76", 8 | "modified_time": "2025-01-18T02:58:31Z", 9 | "name": "Presto元数据缓存解析.md", 10 | "signature": "13364082053676847412", 11 | "tags": [ 12 | ] 13 | } 14 | ], 15 | "folders": [ 16 | ], 17 | "id": "75", 18 | "modified_time": "2024-07-15T07:35:15Z", 19 | "signature": "4289538480533721395", 20 | "version": 3 21 | } 22 | -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/100939754061905.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/100939754061905.png -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/17954520582677.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/17954520582677.png -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/212100674524636.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/212100674524636.png -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/297740417912970.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/297740417912970.png -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/325815305841061.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/325815305841061.png -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/336684490332220.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/336684490332220.png -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/366423190978457.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/366423190978457.png -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/392895254306009.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/392895254306009.png -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/434936491765866.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/434936491765866.png -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/478543642802921.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/478543642802921.png -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/520234001625595.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/520234001625595.png -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/576649737314553.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/576649737314553.png -------------------------------------------------------------------------------- /11_性能优化/缓存/vx_images/58955495676124.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/11_性能优化/缓存/vx_images/58955495676124.png -------------------------------------------------------------------------------- /12_二次开发/vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2024-07-20T13:36:08Z", 3 | "files": [ 4 | { 5 | "attachment_folder": "", 6 | "created_time": "2024-07-20T13:36:25Z", 7 | "id": "84", 8 | "modified_time": "2024-07-20T13:55:51Z", 9 | "name": "二次开发工程体系介绍.md", 10 | "signature": "13028320103389445465", 11 | "tags": [ 12 | ] 13 | } 14 | ], 15 | "folders": [ 16 | ], 17 | "id": "83", 18 | "modified_time": "2024-07-20T13:36:08Z", 19 | "signature": "15472735091332726088", 20 | "version": 3 21 | } 22 | -------------------------------------------------------------------------------- /12_二次开发/vx_images/488675907516955.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/12_二次开发/vx_images/488675907516955.png -------------------------------------------------------------------------------- /12_二次开发/vx_images/502266107324545.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/12_二次开发/vx_images/502266107324545.png -------------------------------------------------------------------------------- /12_二次开发/vx_images/52748047793528.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/12_二次开发/vx_images/52748047793528.png -------------------------------------------------------------------------------- /12_二次开发/二次开发工程体系介绍.md: -------------------------------------------------------------------------------- 1 | # 二次开发工程体系介绍 2 | 3 | [返回首页](../../README.md) 4 | 5 | --- 6 | 7 | > 一句话介绍:Presto&Trino 得益于优秀的插件系统,在企业级大数据体系功能对接的场景中,认证、授权、审计、Hadoop 自定义功能、自定义 UDF、数据湖,全可以实现独立工程开发以插件的方式添加到 Presto 中,不会对主工程造成污染,方便主工程与社区同步。同时又因为 Connector 体系的优秀设计,在对接各种存储、数据库等引擎开发时,也可以实现独立工程的方式。 8 | 9 | 10 | 11 | ## 企业基础对接功能 12 | 13 | ### 审计 14 | 15 | https://prestodb.io/docs/current/develop/event-listener.html 16 | 17 | presto-main/src/main/java/com/facebook/presto/eventlistener/EventListenerManager.java 18 | 19 | ![](vx_images/52748047793528.png) 20 | 21 | ### 认证 22 | 23 | https://prestodb.io/docs/current/develop/password-authenticator.html 24 | 25 | presto-main/src/main/java/com/facebook/presto/server/security/PasswordAuthenticatorManager.java 26 | 27 | ![](vx_images/488675907516955.png) 28 | 29 | ### 权限 30 | 31 | https://prestodb.io/docs/current/develop/system-access-control.html 32 | 33 | presto-main/src/main/java/com/facebook/presto/security/AccessControlManager.java 34 | 35 | ![](vx_images/502266107324545.png) 36 | 37 | ### Hadoop 自定义功能 38 | 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # presto-teach 2 | 3 | 这是一个 Presto、Trino 的文档分享项目(排名不分先后)。 4 | 5 | Presto 和 Trino 的开发文档,和源码阅读,问题调优等相关资料特别少。于是就想着把自己长时间总结的,搜集的,和实际工作中遇到的问题以及二次开发相关都分享出来。 6 | 7 | ## 参与贡献注意事项 8 | 9 | - [注意事项](./注意事项.md) 10 | 11 | ## 项目架构 12 | 13 | - 01_基础概念与全面了解 14 | - [论文阅读:Presto_SQL_on_Everything](./01_基础概念与全面了解/论文阅读:Presto_SQL_on_Everything.md) 15 | - 书籍阅读:Presto实战 16 | - 书籍阅读:Presto技术内幕 17 | - 基础框架Airlift 18 | - 概念设计与角色分布 19 | - [源码分布](./01_基础概念与全面了解/源码分布.md) 20 | - [源码开发与阅读环境搭建](./01_基础概念与全面了解/源码开发与阅读环境搭建.md) 21 | - [Presto类型系统浅入](./01_基础概念与全面了解/Presto类型系统浅入.md) 22 | - 02_基础实践 23 | - 如何把Presto、Trino跑起来 24 | - [如何配置访问控制](./02_基础实践/如何配置访问控制.md) 25 | - 如何配置权限管理 26 | - 如何使用客户端连接 27 | - 如何查看WebUI 28 | - 03_通信流程 29 | - 内部通信方式与流程 30 | - 服务发现流程 31 | - [服务发现-主要流程介绍篇](./03_通信流程/服务发现-主要流程介绍篇.md) 32 | - 客户端与集群的连接通信流程 33 | - 任务提交流程 34 | - 04_计算流程 35 | - 解析流程 36 | - 解析框架Antlr在Presto中的应用 37 | - 执行计划生成流程 38 | - 执行计划优化,分布式化 39 | - 计算模型 40 | - 调度流程 41 | - 队列控制流程 42 | - 05_内存管理 43 | - 内存池的划分与调度 44 | - 配置中的内存配置与理解 45 | - [Presto内存池使用调整](./05_内存管理/Presto内存池使用调整.md) 46 | - 06_容错与恢复流程 47 | - 长时间运行任务的容错实现与讨论 [链接1](https://github.com/trinodb/trino/issues/455) [链接2](https://github.com/prestodb/presto/issues/11241) 48 | - 07_插件思想 49 | - 了解Presto的插件设计思想 50 | - Connector的设计与实现思路 51 | - Connector开发实例 52 | - [Presto如何实现查询下推_初探](./07_插件思想/Connector开发实例/Presto如何实现查询下推_初探.md) 53 | - [Connector开发实例_引](./07_插件思想/Connector开发实例/Connector开发实例_引.md) 54 | - [Presto从零开始实现一个Connector_实现流程简述与测试](./07_插件思想/Connector开发实例/Presto从零开始实现一个Connector_实现流程简述与测试.md) 55 | - MySQL_Connector 56 | - [Presto查询Doris问题](./07_插件思想/Connector开发实例/MySQL_Connector/Presto查询Doris问题.md) 57 | - 08_运维与监控 58 | - [基础监控接口](./08_运维与监控/基础监控接口.md) 59 | - [对接Prometheus生态](./08_运维与监控/对接Prometheus生态.md) 60 | - [如何发现当前Presto集群的性能瓶颈_初探](./08_运维与监控/如何发现当前Presto集群的性能瓶颈_初探.md) 61 | - [如何发现当前Presto集群的性能瓶颈_IO瓶颈](./08_运维与监控/如何发现当前Presto集群的性能瓶颈_IO瓶颈.md) 62 | - [执行计划Stage颜色介绍](./08_运维与监控/执行计划Stage颜色介绍.md) 63 | - [Presto的Worker为什么会挂掉](./08_运维与监控/Presto的Worker为什么会挂掉.md) 64 | - [Presto排查Worker宕机问题_缓存与内存问题排查_上](./08_运维与监控/Presto排查Worker宕机问题_缓存与内存问题排查_上.md) 65 | - 09_其他扩展 66 | - Presto On Spark [链接1](https://github.com/prestodb/presto/issues/13856) [链接2](https://prestodb.io/docs/current/installation/spark.html?highlight=spark) 67 | - Presto On TiKV [链接1](https://github.com/marsishandsome/presto/tree/feature/tidb-hackathon-2019) [链接2](https://github.com/tidb-incubator/TiBigData) 68 | - Presto On hetu [链接1](https://github.com/openlookeng/hetu-core) 69 | - 10_问题总结 70 | - [where子句中在对char类型进行判断时需要手动补齐空格](./10_问题总结/where子句中在对char类型进行判断时需要手动补齐空格.md) 71 | - [hive元数据连接超时](./10_问题总结/hive元数据连接超时.md) 72 | - [jdbc错误](./10_问题总结/jdbc错误.md) 73 | - [mongodb连接异常MongoTimeoutException](./10_问题总结/mongodb连接异常MongoTimeoutException.md) 74 | - [worker资源问题](./10_问题总结/worker资源问题.md) 75 | - [时区问题](./10_问题总结/时区问题.md) 76 | - [最大查询内存问题](./10_问题总结/最大查询内存问题.md) 77 | - [资源文件加载错误](./10_问题总结/资源文件加载错误.md) 78 | - [调试代码的超时限制](./10_问题总结/调试代码的超时限制.md) 79 | - [Presto单元测试错误NoClassDefFoundError_QueryAnalyzer_引发的版本使用思考](./10_问题总结/Presto单元测试错误NoClassDefFoundError_QueryAnalyzer_引发的版本使用思考.md) 80 | - [Presto格式错误造成的分区问题](./10_问题总结/Presto格式错误造成的分区问题.md) 81 | - [Presto中文问题](./10_问题总结/Presto中文问题.md) 82 | - 11_性能优化 83 | - 缓存 84 | - [Presto元数据缓存解析](./11_性能优化/缓存/Presto元数据缓存解析.md) 85 | - [Presto 在知乎的缓存加速实践](https://zhuanlan.zhihu.com/p/661179006) 86 | - [Presto 在知乎的缓存加速复盘](https://zhuanlan.zhihu.com/p/18707848840) 87 | - 索引 88 | - 调度 89 | - 12_二次开发 90 | - [二次开发工程介绍](./12_二次开发/二次开发工程体系介绍.md) 91 | - 隐式转换 92 | - 基于event-listener实现用户行为日志 93 | - 实现自定义密码认证 94 | - udf开发 95 | - hadoop包兼容 96 | - 13_资料参考(排名不分先后) 97 | - trino issues与pr 解读 98 | - trino slack 解读 99 | - presto issues与pr 解读 100 | - [zhihu专栏:presto-cn](https://www.zhihu.com/column/presto-cn) 101 | - 易观博客 102 | - [zhihu用户:qw](https://www.zhihu.com/people/qw-qw-72/posts) 103 | - 分享实践 104 | - [zhihu专栏:深入浅出Presto:PB级OLAP引擎](https://www.zhihu.com/column/c_1294277883771940864) 105 | - [个人博客:若飞](http://armsword.com/) 106 | - [个人博客:马云雷](https://mayunlei.github.io/archives/) 107 | - [oppo博客](https://www.zhihu.com/org/oppohu-lian-wang-ji-zhu) 108 | - [learn-bigdata](https://learn-bigdata.incubator.edurt.io/docs/Presto) 109 | - [个人博客:あらびき日記](https://abicky.net/tag/presto/) -------------------------------------------------------------------------------- /vx.json: -------------------------------------------------------------------------------- 1 | { 2 | "created_time": "2021-08-16T01:44:18Z", 3 | "files": [ 4 | { 5 | "attachment_folder": "213431597851479", 6 | "created_time": "2021-08-16T01:44:18Z", 7 | "id": "18", 8 | "modified_time": "2025-01-19T03:41:11Z", 9 | "name": "README.md", 10 | "signature": "8364164805889693791", 11 | "tags": [ 12 | ] 13 | }, 14 | { 15 | "attachment_folder": "", 16 | "created_time": "2021-08-16T01:44:18Z", 17 | "id": "19", 18 | "modified_time": "2021-08-16T01:44:18Z", 19 | "name": "注意事项.md", 20 | "signature": "2711912562166929503", 21 | "tags": [ 22 | ] 23 | } 24 | ], 25 | "folders": [ 26 | { 27 | "name": "01_基础概念与全面了解" 28 | }, 29 | { 30 | "name": "02_基础实践" 31 | }, 32 | { 33 | "name": "03_通信流程" 34 | }, 35 | { 36 | "name": "05_内存管理" 37 | }, 38 | { 39 | "name": "07_插件思想" 40 | }, 41 | { 42 | "name": "08_运维与监控" 43 | }, 44 | { 45 | "name": "10_问题总结" 46 | }, 47 | { 48 | "name": "11_性能优化" 49 | }, 50 | { 51 | "name": "12_二次开发" 52 | } 53 | ], 54 | "id": "1", 55 | "modified_time": "2021-08-16T01:44:18Z", 56 | "signature": "8635323004867385439", 57 | "version": 3 58 | } 59 | -------------------------------------------------------------------------------- /vx_notebook/notebook.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sqlcore/presto-teach/f9c72ee79fbdce391d48d36b748e06b69dcdad9b/vx_notebook/notebook.db -------------------------------------------------------------------------------- /vx_notebook/vx_notebook.json: -------------------------------------------------------------------------------- 1 | { 2 | "attachment_folder": "vx_attachments", 3 | "config_mgr": "vx.vnotex", 4 | "created_time": "2021-08-16T01:44:18Z", 5 | "description": "", 6 | "extra_configs": { 7 | }, 8 | "history": [ 9 | { 10 | "last_accessed_time": "2021-10-06T02:13:46Z", 11 | "line_number": -1, 12 | "path": "README.md" 13 | }, 14 | { 15 | "last_accessed_time": "2021-10-06T02:13:46Z", 16 | "line_number": -1, 17 | "path": "1_基础概念与全面了解/源码分布.md" 18 | }, 19 | { 20 | "last_accessed_time": "2021-10-06T02:14:53Z", 21 | "line_number": 417, 22 | "path": "1_基础概念与全面了解/源码开发与阅读环境搭建.md" 23 | }, 24 | { 25 | "last_accessed_time": "2021-11-04T06:01:07Z", 26 | "line_number": 498, 27 | "path": "2_通信流程/服务发现-主要流程介绍篇.md" 28 | } 29 | ], 30 | "image_folder": "vx_images", 31 | "name": "presto-teach", 32 | "tag_graph": "", 33 | "version": 3, 34 | "version_controller": "dummy.vnotex" 35 | } 36 | -------------------------------------------------------------------------------- /注意事项.md: -------------------------------------------------------------------------------- 1 | # 注意事项 2 | 3 | [返回首页](./README.md) 4 | 5 | --- 6 | 7 | ## 编辑与阅读 8 | 9 | - **强烈推荐:** 使用 [vnote](https://github.com/vnotex/vnote) 笔记来进行阅读或编辑,程序员的专属笔记!它的文档体验理论上可以超过IDEA; 10 | - 该文档建议使用IDEA阅读或编辑,以获得更好体验; 11 | - 如果使用IDEA编辑,建议安装`Paste images into MarkDown`插件,可以在编辑时直接将图片粘贴到md文本中; 12 | - 文档中对应的图片,建议与文档处于同一级目录,并建立一个`vx_images`文件夹存放; 13 | - 如果需要画图,请在其他地方画好之后粘贴进来,尽量控制图片的大小,不要太大; 14 | 15 | ## 内容 16 | 17 | 全使用标准的markdown语法进行编写,[参考教程1](https://markdown.com.cn/intro.html#markdown-%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F) [参考教程2](https://docs.github.com/cn/free-pro-team@latest/github/writing-on-github/basic-writing-and-formatting-syntax) 。 18 | 19 | 文件的最顶部尽量添加导航链接,目的是在阅读时能够方便跳转,比如: 20 | 21 | 主要 22 | 23 | ``` 24 | [返回首页](../README.md) 25 | 26 | --- 27 | ``` 28 | 29 | 或 30 | 31 | ``` 32 | [选项1](../**/**) 33 | [选项2](../**/**) 34 | [返回首页](../**/**/README.md) 35 | 36 | --- 37 | ``` 38 | 39 | ## 命名 40 | 41 | - 文件夹名和文件名,尽量不要有空格,如需要分隔,统一使用下划线; 42 | 43 | --------------------------------------------------------------------------------