聊聊SpinalTap的Transaction
大家好,今天本人给大家带来文章《聊聊SpinalTap的Transaction》,文中内容主要涉及到MySQL,如果你对数据库方面的知识点感兴趣,那就请各位朋友继续看下去吧~希望能真正帮到你们,谢谢!
序
本文主要研究一下SpinalTap的Transaction
Transaction
SpinalTap/spinaltap-model/src/main/java/com/airbnb/spinaltap/mysql/Transaction.java
@Value
@RequiredArgsConstructor
public class Transaction {
private final long timestamp;
private final long offset;
private final BinlogFilePos position;
private final String gtid;
public Transaction(long timestamp, long offset, BinlogFilePos position) {
this.timestamp = timestamp;
this.offset = offset;
this.position = position;
this.gtid = null;
}
}
- Transaction定义了timestamp、offset、position、gtid属性
MysqlMutationMetadata
SpinalTap/spinaltap-model/src/main/java/com/airbnb/spinaltap/mysql/mutation/MysqlMutationMetadata.java
@Value
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class MysqlMutationMetadata extends Mutation.Metadata {
private final DataSource dataSource;
private final BinlogFilePos filePos;
private final Table table;
private final long serverId;
private final Transaction beginTransaction;
private final Transaction lastTransaction;
/** The leader epoch of the node resource processing the event. */
private final long leaderEpoch;
/** The mutation row position in the given binlog event. */
private final int eventRowPosition;
public MysqlMutationMetadata(
DataSource dataSource,
BinlogFilePos filePos,
Table table,
long serverId,
long id,
long timestamp,
Transaction beginTransaction,
Transaction lastTransaction,
long leaderEpoch,
int eventRowPosition) {
super(id, timestamp);
this.dataSource = dataSource;
this.filePos = filePos;
this.table = table;
this.serverId = serverId;
this.beginTransaction = beginTransaction;
this.lastTransaction = lastTransaction;
this.leaderEpoch = leaderEpoch;
this.eventRowPosition = eventRowPosition;
}
}
- MysqlMutationMetadata定义了dataSource、filePos、table、serverId、beginTransaction、lastTransaction、leaderEpoch、eventRowPosition属性
MysqlMutationMapper
SpinalTap/spinaltap-mysql/src/main/java/com/airbnb/spinaltap/mysql/event/mapper/MysqlMutationMapper.java
@Slf4j @RequiredArgsConstructor public abstract class MysqlMutationMapperimplements Mapper > { @NonNull private final DataSource dataSource; @NonNull private final TableCache tableCache; @NonNull private final AtomicReference beginTransaction; @NonNull private final AtomicReference lastTransaction; @NonNull private final AtomicLong leaderEpoch; public static Mapper >> create( @NonNull final DataSource dataSource, @NonNull final TableCache tableCache, @NonNull final SchemaTracker schemaTracker, @NonNull final AtomicLong leaderEpoch, @NonNull final AtomicReference beginTransaction, @NonNull final AtomicReference lastTransaction, @NonNull final MysqlSourceMetrics metrics) { final AtomicReference gtid = new AtomicReference(); return ClassBasedMapper. >>builder() .addMapper(TableMapEvent.class, new TableMapMapper(tableCache)) .addMapper(GTIDEvent.class, new GTIDMapper(gtid)) .addMapper(QueryEvent.class, new QueryMapper(beginTransaction, gtid, schemaTracker)) .addMapper(XidEvent.class, new XidMapper(lastTransaction, gtid, metrics)) .addMapper(StartEvent.class, new StartMapper(dataSource, tableCache, metrics)) .addMapper( UpdateEvent.class, new UpdateMutationMapper( dataSource, tableCache, beginTransaction, lastTransaction, leaderEpoch)) .addMapper( WriteEvent.class, new InsertMutationMapper( dataSource, tableCache, beginTransaction, lastTransaction, leaderEpoch)) .addMapper( DeleteEvent.class, new DeleteMutationMapper( dataSource, tableCache, beginTransaction, lastTransaction, leaderEpoch)) .build(); } protected abstract List mapEvent(@NonNull final Table table, @NonNull final R event); public List map(@NonNull final R event) { Table table = tableCache.get(event.getTableId()); return mapEvent(table, event); } MysqlMutationMetadata createMetadata( @NonNull final Table table, @NonNull final BinlogEvent event, final int eventPosition) { return new MysqlMutationMetadata( dataSource, event.getBinlogFilePos(), table, event.getServerId(), event.getOffset(), event.getTimestamp(), beginTransaction.get(), lastTransaction.get(), leaderEpoch.get(), eventPosition); } static ImmutableMap zip( @NonNull final Serializable[] row, @NonNull final Collection columns) { if (row.length != columns.size()) { log.error("Row length {} and column length {} don't match", row.length, columns.size()); } final ImmutableMap.Builder builder = ImmutableMap.builder(); final Iterator columnIterator = columns.iterator(); for (int position = 0; position
- MysqlMutationMapper定义了dataSource、tableCache、beginTransaction、lastTransaction、leaderEpoch属性;它提供了createMetadata方法,它接收table、event、eventPosition参数返回新建的MysqlMutationMetadata
InsertMutationMapper
SpinalTap/spinaltap-mysql/src/main/java/com/airbnb/spinaltap/mysql/event/mapper/InsertMutationMapper.java
class InsertMutationMapper extends MysqlMutationMapper{ InsertMutationMapper( @NonNull final DataSource dataSource, @NonNull final TableCache tableCache, @NonNull final AtomicReference beginTransaction, @NonNull final AtomicReference lastTransaction, @NonNull final AtomicLong leaderEpoch) { super(dataSource, tableCache, beginTransaction, lastTransaction, leaderEpoch); } @Override protected List mapEvent( @NonNull final Table table, @NonNull final WriteEvent event) { final List rows = event.getRows(); final List mutations = new ArrayList(); final Collection cols = table.getColumns().values(); for (int position = 0; position
- InsertMutationMapper继承了MysqlMutationMapper,其构造器要求输入dataSource、tableCache、beginTransaction、lastTransaction、leaderEpoch参数
UpdateMutationMapper
SpinalTap/spinaltap-mysql/src/main/java/com/airbnb/spinaltap/mysql/event/mapper/UpdateMutationMapper.java
final class UpdateMutationMapper extends MysqlMutationMapper{ UpdateMutationMapper( @NonNull final DataSource dataSource, @NonNull final TableCache tableCache, @NonNull final AtomicReference beginTransaction, @NonNull final AtomicReference lastTransaction, @NonNull final AtomicLong leaderEpoch) { super(dataSource, tableCache, beginTransaction, lastTransaction, leaderEpoch); } @Override protected List mapEvent( @NonNull final Table table, @NonNull final UpdateEvent event) { final List mutations = Lists.newArrayList(); final Collection cols = table.getColumns().values(); final List > rows = event.getRows(); for (int position = 0; position
- UpdateMutationMapper继承了MysqlMutationMapper,其构造器要求输入dataSource、tableCache、beginTransaction、lastTransaction、leaderEpoch参数
DeleteMutationMapper
SpinalTap/spinaltap-mysql/src/main/java/com/airbnb/spinaltap/mysql/event/mapper/DeleteMutationMapper.java
final class DeleteMutationMapper extends MysqlMutationMapper{ DeleteMutationMapper( @NonNull final DataSource dataSource, @NonNull final TableCache tableCache, @NonNull final AtomicReference beginTransaction, @NonNull final AtomicReference lastTransaction, @NonNull final AtomicLong leaderEpoch) { super(dataSource, tableCache, beginTransaction, lastTransaction, leaderEpoch); } @Override protected List mapEvent( @NonNull final Table table, @NonNull final DeleteEvent event) { final Collection cols = table.getColumns().values(); final List mutations = new ArrayList(); final List rows = event.getRows(); for (int position = 0; position
- DeleteMutationMapper继承了MysqlMutationMapper,其构造器要求输入dataSource、tableCache、beginTransaction、lastTransaction、leaderEpoch参数
小结
Transaction定义了timestamp、offset、position、gtid属性;MysqlMutationMetadata定义了dataSource、filePos、table、serverId、beginTransaction、lastTransaction、leaderEpoch、eventRowPosition属性
doc
今天带大家了解了MySQL的相关知识,希望对你有所帮助;关于数据库的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~
MySql轻松入门系列————第一站 从源码角度轻松认识mysql整体框架图
- 上一篇
- MySql轻松入门系列————第一站 从源码角度轻松认识mysql整体框架图
- 下一篇
- 技术分享 | kubernetes 环境测试部署 MySQL 的随想
-
- 数据库 · MySQL | 14小时前 | MySQL · 错误排查 · mysql 空间数据 长度单位 ST_FrechetDistance SRID 0 ER_GEOMETRY_IN_UNKNOWN_LENGTH_UNIT
- MySQL ST_FrechetDistance 指定米单位为什么报错
- 360浏览 收藏
-
- 数据库 · MySQL | 14小时前 | MySQL教程 · mysql SRID GIS ST_IsClosed 地理坐标系 SRS
- MySQL ST_IsClosed 为什么不支持地理坐标系
- 448浏览 收藏
-
- 数据库 · MySQL | 14小时前 | MySQL · mysql JSON 数组 MEMBER OF JSON_CONTAINS JSON 类型
- MySQL MEMBER OF 怎样判断 JSON 数组是否包含值
- 425浏览 收藏
-
- 数据库 · MySQL | 14小时前 | MySQL · 数据类型 · JSON · 索引优化 · mysql 索引 json_extract 生成列 MySQL 8.4 CAST JSON_UNQUOTE
- MySQL 生成列提取 JSON 字段怎样选类型
- 389浏览 收藏
-
- 数据库 · MySQL | 14小时前 | mysql 稳定排序 窗口函数 ROW_NUMBER 并列值
- MySQL ROW_NUMBER 遇到并列值怎样稳定排序
- 296浏览 收藏
-
- 数据库 · MySQL | 15小时前 | mysql STATEMENT_DIGEST_TEXT max_digest_length 摘要截断
- MySQL STATEMENT_DIGEST_TEXT 为什么出现省略号
- 137浏览 收藏
-
- 数据库 · MySQL | 15小时前 | MySQL教程 · mysql GeoJSON SRID GIS ST_AsGeoJSON
- MySQL ST_AsGeoJSON 怎样把空间对象转换成 GeoJSON
- 157浏览 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 543次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 516次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 500次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 485次学习
-
- PubMedQA
- 深入了解PubMedQA生物医学问答数据集,涵盖其核心功能、使用方法及在临床决策、药物研发等场景的应用,助力提升NLP模型性能。
- 1034次使用
-
- H2O EvalGPT
- H2O EvalGPT是H2O.ai推出的开源LLM评估平台,提供详细的大模型性能排行榜、行业特定基准测试及A/B测试功能,助您快速选择最适合项目的高性能大语言模型。
- 1033次使用
-
- LMArena
- LMArena是加州大学伯克利分校推出的AI模型匿名评测平台。通过盲测投票机制,用户可对比不同大模型回答并生成实时排行榜,助力开发者优化模型及用户选择最佳AI工具。
- 1177次使用
-
- HELM
- 深入了解斯坦福推出的HELM(Holistic Evaluation of Language Models)大模型评测体系。本文解析其核心功能、安装配置步骤及应用场景,涵盖准确性、公平性、鲁棒性等多维度指标,助力开发者全面优化语言模型性能。
- 1139次使用
-
- MMBench
- MMBench是由上海人工智能实验室等机构联合推出的多模态基准测试平台,提供细粒度能力评估、大规模数据集及VLMEvalKit工具。本文详细介绍其核心功能、安装使用方法及应用场景,助力开发者全面评估多模态模型性能。
- 981次使用
-
- MySQL 明明加了索引,为什么查询还是很慢?先查这 6 个点
- 2026-06-27 374浏览
-
- golang MySQL实现对数据库表存储获取操作示例
- 2022-12-22 499浏览
-
- golang 基于 mysql 简单实现分布式读写锁
- 2023-01-07 384浏览
-
- 详解如何利用GORM实现MySQL事务
- 2023-01-07 184浏览
-
- Go语言实现操作MySQL的基础知识总结
- 2023-01-23 265浏览

