MySQL分布式数据库中间件的一致性实现

 2022-04-06 08:04

论文总字数:29236字

摘 要

随着互联网规模的发展和扩大,数据存储的要求在日渐地增长。从刚开始发展的单机规模存储到现在的分布式集群部署,存储需求和机器部署的同步增加导致了不可避免的一致性问题。所以有必要设计一套不仅在理论上论证成功的,同样也适用于工业高效生产的一致性存储方案。

针对上述内容,本文设计并实现了基于MySQL的分布式数据库中间件。首先是基于Netty框架实现了高性能的RPC通信基础模块,该模块用来提供稳定的网络通信和高并发的业务处理能力。同时本文将基于该RPC通信基础模块和学术界已经论证成立的Raft算法,实现了高可靠和安全的一致性模块。该模块将以MySQL作为基础的存储组件实现日志复制相关功能。并且本文提供适应各种情况的分布式环境下Leader选举功能。为了保证节点之间的逻辑关系稳定,本文还实现了定时的心跳机制和选举机制,能够保障在节点出现异常情况下通过相关机制恢复到正常情况。最后通过该分布式数据库中间件,用户只需要实现对应的业务状态机,便能无感知地让数据获得分布式存储能力,提高数据库的可靠性。

关键词:分布式存储,MySQL,一致性,远程传输调用

Abstract

With the development and expansion of the Internet scale, the requirements for data storage are growing. From the single-scale storage that has just begun to the current distributed cluster deployment, the increased synchronization of storage requirements and machine deployment has led to inevitable consistency issues. Therefore, it is necessary to design a set of consistent storage solutions that are not only theoretically successful, but also applicable to industrial high-efficiency production.

In view of the above, this thesis designs and implements a distributed database middleware based on MySQL. The first is to implement a high-performance RPC communication infrastructure module based on the Netty framework, which is used to provide stable network communication and high concurrent business processing capabilities. At the same time, based on the RPC communication basic module and the Raft algorithm that has been demonstrated by the academic community, this thesis implements a highly reliable and secure consistency module. This module implements log replication related functionality with MySQL-based storage components. And this article provides the Leader election function in a distributed environment that adapts to various situations. In order to ensure the stable logical relationship between nodes, this thesis also implements a timed heartbeat mechanism and an election mechanism to ensure that the normal mechanism is restored through the relevant mechanism in the event of an abnormality in the node. Finally, through the distributed database middleware, the user only needs to implement the corresponding business state machine, so that the data can be distributed stored without awareness, and the reliability of the database is improved.

Keywords: Distributed storage, MySQL, Consistency, RPC

目 录

摘 要 I

Abstract II

第一章 绪论 1

1.1 研究背景及意义 1

1.2 国内外研究现状 1

1.3 研究目标和内容 3

1.4 论文组织与结构 3

第二章 相关理论与技术研究 5

2.1 分布式数据库简介 5

2.1.1 分布式数据库系统概述 5

2.1.2 MySQL数据库简介 5

2.2 分布式一致性理论基础原理 5

2.2.1 CAP理论 5

2.2.2 BASE理论 6

2.2.3 FLP impossibility理论 6

2.3 分布式一致性Raft算法概述 7

2.4 RPC通信原理简介 9

2.4.1 Netty框架技术 9

2.4.2 跨语言通信协议Protocol Buffers 9

2.4.3 代码生成类库Cglib 10

2.5 本章小节 10

第三章 中间件的需求分析与架构设计 11

3.1 中间件中RPC通信的功能与性能需求分析 11

3.2 中间件中一致性能力的功能与性能需求分析 11

3.3 中间件总体架构设计 12

3.3.1 RPC通信层总体架构设计 12

3.3.2 一致性保障层总体架构设计 15

3.4 本章小节 16

第四章 中间件的实现 17

4.1 RPC通信模块 17

4.1.1 RPC消息协议模块 17

4.1.2 Netty网络处理模块 18

4.1.3 RpcClient中ConnectionManager网络连接模块 18

4.1.4 RpcServer中任务处理模块 19

4.2 Leader选举模块 20

4.2.1 选举流程 20

4.2.2 通信消息设计 20

4.3 日志复制模块 21

4.3.1 日志复制流程 21

4.3.2 日志存储设计 23

4.3.3 通信消息设计 23

4.4 投票模块 24

4.4.1 选举投票器设计 24

4.4.2 日志复制投票箱设计 25

4.5 本章小结 26

第五章 系统测试 28

5.1 测试环境 28

5.2 测试方案 28

5.2.1 RPC通信层测试方案 28

5.2.2 一致性保障层测试方案 28

5.3 测试结果及分析 29

5.3.1 RPC通信层测试结果 29

5.3.2 一致性保障层测试结果及分析 31

5.4 本章小结 33

第六章 总结与展望 34

6.1 全文总结 34

6.2 研究展望 34

参考文献 36

致谢 35

绪论

    1. 研究背景及意义

在当前的互联网生产环境中,对于大型的平台应用比如电商、网约车、餐饮外卖等等,它们其中任意的系统每天产生的订单量、消费记录、互动数据等都是十分庞大的。由于单机数据库性能受限于网络带宽、磁盘IO速度、内存空间、CPU计算能力等等基础因素的制约,因此生产环境中部署单机数据库应用是无法扛住业务产生的各种各样的数据的。

一个数据库最基本也是最核心的能力就是将数据完整地永久性地保存下来,从而提供最基础的数据支持方便用来做一些关于数据的分析和处理。目前业界主流的数据库有关系型数据库和非关系型数据库,比如NOSQL类型数据库等。使用关系型数据库主要目的是存储具有相关性的不同数据从而满足不同的业务场景对数据的计算需求。基于数据的存储之后,用户会要求使用数据做一些简单的扫表操作查询,或者是其他的一些复杂的查询操作,比如对数据进行复杂的聚合、联表、分组等操作。而使用非关系型数据库则是能够充分利用存储结构的简单进行深度的优化和处理,用户的查询指令要求一般不需要进行特殊的SQL层的处理和解析,性能很高,并且数据之间的关系一般呈现低耦合的特性非常容易实现水平扩展。

剩余内容已隐藏,请支付后下载全文,论文总字数:29236字

您需要先支付 80元 才能查看全部内容!立即支付

该课题毕业论文、开题报告、外文翻译、程序设计、图纸设计等资料可联系客服协助查找;