StoneDB Source Code Interpretation Series | Tianmu Engine Tool Class Module Source Code Explanation (1)
The StoneDB source code interpretation series of articles has officially started, and we are expected to meet you in the form of Zhou Geng. Please provide more support~The source code interpretation content of this article has been shared live
The StoneDB source code interpretation series of articles has officially started, and we are expected to meet you in the form of Zhou Geng. Please provide more support~
The source code interpretation content of this article has been shared live.
Each tool Class belongs to the core components of the Tianmu engine. These components can be said to be the cornerstone of Tianmu. Due to the wide range of tool Classes, we will select some major ones in the source code interpretation series to share with you, including: log system, exception handling, stack tracking, Thread pool, memory management, data compression/decompression, etc. This article mainly shares the first four points.
Source code structure
As is well known, large projects have a huge amount of code. In order to facilitate management and maintenance, developers generally divide the source code into different directories based on functional modules. Therefore, when analyzing large projects, it is necessary to first understand the role of each directory in the project, and then interpret the corresponding code according to their own needs.
The Logging System of Tianmu Engine
The log types of Tianmu engine are divided into three categories: system logs, debugging logs, and query engine execution result logs. The abnormal information of the system, stack information of abnormal situations, and some timing information are all recorded in the system log. System maintenance and developers can use logs to understand server software and hardware information, check for errors during the configuration process, and identify the causes of errors. Frequent analysis of logs can help understand the server's load, performance, and security, thus taking timely measures to correct errors.
The Logging System of Tianmu Engine
The system logs are divided into the following 7 levels:
Using enumeration types to represent various levels
EnumLogCtl_ Level { DisaBLED = 0, FATAL = one, ERROR = two, WARN = three, INFO = four, DEBUG = five, TRACE = six };
And it supports mapping MySQL log level to Tianmu log level, which can be achieved by setting the parameter tianmu_ Global_ Debug_ Level to control the output level of logs:
The higher the level of the log, the more information will be output, and of course, detailed log information will affect the operational performance of the system, which needs to be determined according to the situation.
Tianmu's system logs will be uniformly logged to the MySQL installation directory in the/log/tianmu. log file
Log System Core Class:
Class Utils:: LogCtl
Log the debugging logs to the/log/trace.log file in the MySQL installation directory.
fromtianmu_control_trace one0
Call interface object:
System:: Channelrccontrol
three.
The result log of the query engine execution is landed in the/log/query.log file in the StoneDB installation directory.
from
tianmu_ini_controlquerylog one0
Call interface object:
System:: Channelrcquerylog
stack trace
Save stack related information (such as function calls and symbol information of the stack) for future debugging and troubleshooting. Currently, the Tianmu system adds stack information recording based on exception handling modules. If there are any abnormal situations, the on-site stack information will be recorded. The call information of the stack will be recorded in Tianmu's system log at the WARN level, in the directory where the log is located:/log/tianmu. log file under the StoneDB installation directory.
In order to obtain stack information, Tianmu usedProvided in glibcBacktrace()andBacktrace_ Symbols ()and call stackUsing abi in g++:__ Cxa_ Demangle, demangleThe process of converting C++ABI identifiers into C++source identifiers is called demangle. Simply put, the process of identifying function names after C++compilation is called demangle
Call function interface:
GetStackTrace();
exception handling
Tianmuexception handling
exception handling
Tianmu andWARNTianmuStoneDB/log/tianmu.log
exception handling
Class Common:: Exception
Thread pool
Tianmu's threads are implemented based on new features in C++
Thread pool
Class Utils:: thread_ Pool
It has the following advantages:
- Tianmu Thread pool C++oneone std::thread
- std::condition_variable and std::mutex and,and
- Thread pool
- Tianmu std::thread::hardware_concurrency() CPU Thread poolThread pooland CPUCPU and
one.Thread pool
TianmuThread poolThread pool
- Thread pool
The main function is to load the data from the insertbuffer into the database
Utils:: thread_ Pool delay_insert_thread_pool;
- Thread pool
and
Utils:: thread_ Pool load_thread_pool;
- Thread pool
Provide parallel processing capabilities during the query process
Utils:: thread_ Pool query_thread_pool;
- delete & update Thread pool
delete andupdate
Utils:: thread_ Pool delete_or_update_thread_pool
Thread pooland
two.Thread pool
Thread pool StoneDB Thread poolThread poolandThread pool
The following figure shows the process of calling the StoneDB system during thread initialization:
The above is the entire content of this article.
Disclaimer: The content of this article is sourced from the internet. The copyright of the text, images, and other materials belongs to the original author. The platform reprints the materials for the purpose of conveying more information. The content of the article is for reference and learning only, and should not be used for commercial purposes. If it infringes on your legitimate rights and interests, please contact us promptly and we will handle it as soon as possible! We respect copyright and are committed to protecting it. Thank you for sharing.(Email:[email protected])