In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to use C++ to delete large tables in the database". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Background: the IO pressure of the database is very great. If the large table is deleted online, it will cause great jitter to IO and business. The common practice as a DBA is to establish a hard connection between .frm and .ibd, and then on drop table tablename;, but the table file still exists on this machine. If you delete the table file directly with rm, it will cause the until of IO to reach 100%.
Question: so how to avoid IO reaching 100% when deleting files?
Solution: gradually erase files through ftruncate. Below, I provide my own slowrm to delete files. Test the io usage between 10-20%, and delete at a speed of more than 100G per hour (here is only a rough version, you can modify it yourself)
# include
# include
# include
# include
# include
# include
/ / determine whether the input is legal
Int fileInputLegal (const char * pfile=nullptr)
Int main (int argc,char * argv []) {
/ / use stat to get the file size
/ / call open to open the file and get the file descriptor
/ / call ftrucate to reduce the size of the file until 0
Int fd =-1
/ / this parameter has been adjusted
Int deleteBytes = 1024700
/ / the purpose is to get the length of the file
Struct stat buf
Off_t fileSize = 0
If (argc! = 2) {
Std::cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.