Hive2MySQL初步架构_MySQL
系统简介
本系统负责将Hive处理后的数据导出到MySQL服务器上,采用 主/从
架构。zeus2将待导出的数据信息放到zookeeper上,Zookeeper将该信息发送给master。master通过JobWatcher接收待处理的表信息,将这些信息转换为任务,并分发给client处理。当client处理完成时,会更新MySQL上数据处理表,表示该部分任务已经处理完成
模块简介
master
- 简介
为服务,会一直运行。包含接收zookeeper上传来的待导出数据的元信息、任务导出、任务超时处理、任务执行完成后的元数据更新、告警等功能 - 流程
- 启动master服务
- 通过JobWatcher线程获取待处理的任务,并更新到队列MasterContext.finishedTZ中
- MasterContext中加入一个线程,扫描队列MasterContext.finishedTZ,如果有任务,则开始解析任务并进行任务分发
- 任务分发的时候,将分发任务加入到executor,执行完成的时候,得到返回码,并根据返回码,进行相应的处理
- MasterContext中加入一个线程,用于监控超时的client,如果超时,则将该client加入到超时列表中,以后不进行分发
- 关键点
- MySQL节点的选择
- 需求
为了后续计算的方便,需要将能存储在一个MySQL服务器上的数据全部导出到一个节点上,例如上个月站点A
导出到MySQL1
上,这个月,还得将站点A
的数据导出到节点MySQL1
上。 - 解决方案
导出时,为了保证每次数据都导出到一个节点上去,需要维持一张site和host间对应的关系表。而部分站点的数据非常大,会超过MySQL服务器的单表阈值,这样部分站点的数据需要分发到不同的节点上去。site和节点之间的关系不是一一对应的。而大站点只是用户中的一部分,还存在一些小站点,一个MySQL服务器可能存放数个站点的数据。为了应对这些挑战,我们将站点分为三种SITE_LEVEL:SMALL_SITE、BIG_SITE、HUG_SITE,并分别采用不同的导出策略。
SMALL_SITE 网站的数据量较小,一个站点只存放在一个MySQL服务器上去。所有的数据都会导出到一台MYSQL服务器上去。当数据超过MYSQL服务器单表限制的时候,会将数据导出到负载最小的MySQL服务器上去。某site很长时间以来一直使用我们的服务器时,可能会出现这种情况。
BIG_SITE 导出的策略和SMALL_SITE一样,但是获取MySQL服务器的方法和SMALL_SITE不一样,BIG_SITE按照轮询的方式将HIVE上的数据导出到MYSQL中去,即今天的数据导出到MYSQL1
上,明天的数据可能导出到MySQL2上。而SMALL_SITE的数据均导出到一台MYSQL服务器上。
HUG_SITE 将站点每天的访问信息分发到不同的MYSQL服务器上去
- 注解
- HDFS路径
/user/hive/warehouse/ptmind_data.db/${tableName}_${tableType}/sitetz=${timezone}/partdt=${date}/partsid=${sid}
如/user/hive/warehouse/ptmind_data.db/sum_page_visits_stats_olap_d/sitetz=E0800/partdt=2014-06-02/partsid=56fbce4e
- tableType
明细表的类型为x,其他表暂时只支持天d
1
private
String getTabType(String tableName) {
if
(tableName.equals(Constant.TB_1)) {
return
x;}
else
{
return
d;}}
Copy after login - HDFS路径
client
- 简介
- 部署在MySQL服务器上
- 执行HDFS2MySQL的导出任务
- 流程
- 通过clientBootstrap监控消息
- 当监控到任务时,执行HDFS2MySQL的导出任务
2.1 通过shell脚本,从HDFS上下载数据
2.2 将元数据更新到MySQL服务器中
2.3 删除本地文件
2.4 根据表中插入行的数目判断数据是否导出成功
2.5 将执行情况返回给master - 定时向master发送心跳信息
- 注解
- 存储的本地路径:
/tmp/ptbalancer/data/${tableName}_${tableType}_${date}_${当前时间戳}
节点间通信
-
中间件
netty
master
ServerBootstrap
client
ClientBootstrap
传输数据 PB
相比XML,PB有更好的传输效率、压缩率更高、解析速度更快

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.
