自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

WiredTiger 如何修復 MongoDB 7.0.14 集合 WT 文件

原創(chuàng) 精選
數(shù)據(jù)庫 MongoDB
WiredTiger 是一個高性能的鍵值存儲和數(shù)據(jù)引擎,最初由 WiredTiger Inc. 開發(fā),后來被 MongoDB 收購并集成到 MongoDB 中。

作者 | 吳守陽

審校 | 重樓

目錄

1. 概述

2. 主要特性

3. 安裝依賴

4.安裝WiredTiger

5. WiredTiger編譯支持的參數(shù)

6. 找到故障WT文件

7. 恢復

8. 總結(jié)

概述

WiredTiger 是一個高性能的鍵值存儲和數(shù)據(jù)引擎,最初由 WiredTiger Inc. 開發(fā),后來被 MongoDB 收購并集成到 MongoDB 中。WiredTiger 提供了高效的數(shù)據(jù)存儲和檢索能力,支持多種數(shù)據(jù)結(jié)構(gòu)和壓縮算法,適用于高并發(fā)和大規(guī)模數(shù)據(jù)處理場景。

主要特性

  • 高性能:WiredTiger 通過高效的內(nèi)存管理和并發(fā)控制機制,提供了卓越的讀寫性能。
  • 多種數(shù)據(jù)結(jié)構(gòu):支持 B-Tree、LSM 樹等多種數(shù)據(jù)結(jié)構(gòu),適用于不同的應用場景。
  • 壓縮算法:支持多種壓縮算法(如 Snappy、LZ4、Zlib、Zstd),可以顯著減少存儲空間占用。
  • 事務(wù)支持:提供 ACID 事務(wù)支持,確保數(shù)據(jù)的一致性和可靠性。
  • 可擴展性:設(shè)計為高度可擴展,適用于從小型嵌入式設(shè)備到大型分布式系統(tǒng)的各種環(huán)境。
  • 靈活的配置:可以通過豐富的配置選項來優(yōu)化性能和資源使用。
  • 數(shù)據(jù)恢復:提供數(shù)據(jù)恢復功能,確保在數(shù)據(jù)損壞或系統(tǒng)故障后能夠恢復數(shù)據(jù)。

數(shù)據(jù)庫節(jié)點出現(xiàn)無法啟動的問題,顯示某個集合文件損壞,使用 --repair修復后,還是不能啟動。接下來使用WT修復,此次修復的數(shù)據(jù)庫版本的是7.0.14

安裝依賴

---安裝依賴(盡量保證這些依賴都安裝完)
yum install -y swig python3-devel openssl-devel epel-release libtool automake cmake-filesystem snappy snappy-devel lz4 lz4-devel zstd zstd-devel libzstd-devel zlib zlib-devel git make vim-common
Package swig-3.0.12-19.module_el8.3.0+557+3d058e38.x86_64 is already installed.
Package python36-devel-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64 is already installed.
Package openssl-devel-1:1.1.1k-5.el8_5.x86_64 is already installed.
Package snappy-1.1.8-3.el8.x86_64 is already installed.
Package snappy-devel-1.1.8-3.el8.x86_64 is already installed.
No match for argument: zstd-devel
Package zlib-1.2.11-17.el8.i686 is already installed.
Package zlib-1.2.11-17.el8.x86_64 is already installed.
Package zlib-devel-1.2.11-17.el8.x86_64 is already installed.
Package git-2.27.0-1.el8.x86_64 is already installed.
Package make-1:4.2.1-10.el8.x86_64 is already installed.
Package vim-common-2:8.0.1763-15.el8.x86_64 is already installed.
Error: Unable to find a match: zstd-devel

--安裝snappy-devel
https://rpmfind.net/linux/rpm2html/search.php?query=snappy-devel
wget https://rpmfind.net/linux/almalinux/8.10/PowerTools/x86_64/os/Packages/snappy-devel-1.1.8-3.el8.x86_64.rpm
yum install snappy-devel-1.1.8-3.el8.x86_64.rpm

---安裝cmake
wget https://github.com/Kitware/CMake/releases/download/v3.30.3/cmake-3.30.3-linux-x86_64.tar.gz
tar -zxvf cmake-3.30.3-linux-x86_64.tar.gz
cd cmake-3.30.3
./bootstrap
make && make install
[root@easyliao012 bin]# pwd
/opt/cmake-3.30.3-linux-x86_64/bin

安裝WiredTiger

---開始編譯
wget https://github.com/wiredtiger/wiredtiger/archive/refs/tags/11.2.0.tar.gz
tar xvf 11.2.0.tar.gz
cd wiredtiger
mkdir build
cd build
 /opt/cmake-3.30.3-linux-x86_64/bin/cmake -DENABLE_SNAPPY=1 ../.
make && make install

---配置環(huán)境變量
export LD_LIBRARY_PATH=/usr/local/lib64/:$LD_LIBRARY_PATH
[root@easyliao012 lib64]# ll -h /usr/local/lib64/
-rwxr-xr-x  1 root root 121K Sep 29 14:36 libwiredtiger_snappy.so
lrwxrwxrwx  1 root root   23 Sep 27 18:23 libwiredtiger.so -> libwiredtiger.so.11.2.0
-rwxr-xr-x  1 root root  29M Sep 29 14:36 libwiredtiger.so.11.2.0
-rwxr-xr-x  1 root root 152K Sep 29 14:36 libwiredtiger_zlib.so
-rwxr-xr-x  1 root root 139K Sep 29 14:36 libwiredtiger_zstd.so

---編譯完成
root@easyliao012 data]# cd /opt/wiredtiger/wiredtiger-11.2.0/build
[root@easyliao012 build]# ls
bench           CMakeFiles           config               examples  gdb_scripts  install_manifest.txt  libwiredtiger.so         libwiredtiger.so.11.2.0-gdb.py  src   wiredtiger.pc
CMakeCache.txt  cmake_install.cmake  CTestTestfile.cmake  ext       include      lang                  libwiredtiger.so.11.2.0  Makefile                        test  wt

WiredTiger編譯支持的參數(shù)

WiredTiger 軟件支持一些額外的配置選項:

-DHAVE_ATTACH=1

功能:配置 WiredTiger 在發(fā)生故障時休眠并等待調(diào)試器附加。

用途:主要用于開發(fā)和調(diào)試,不建議在生產(chǎn)環(huán)境中使用。

-DHAVE_DIAGNOSTIC=1

功能:配置 WiredTiger 在運行時執(zhí)行各種診斷測試。

默認值:默認情況下,非發(fā)布(Release)構(gòu)建類型會啟用此選項。

用途:主要用于開發(fā)和調(diào)試,不建議在生產(chǎn)環(huán)境中使用。

-DNON_BARRIER_DIAGNOSTIC_YIELDS=1

功能:配置 WiredTiger 在線程讓步時不要使用內(nèi)存屏障,用于診斷目的。

前提條件:必須同時啟用 HAVE_DIAGNOSTIC 選項。

用途:主要用于開發(fā)和調(diào)試,不建議在生產(chǎn)環(huán)境中使用。

-DENABLE_LZ4=1

功能:配置 WiredTiger 使用 LZ4 壓縮。

默認值:如果系統(tǒng)中存在 LZ4 庫,默認情況下會啟用此選項。

用途:提高數(shù)據(jù)壓縮效率。

-DENABLE_PYTHON=1

功能:構(gòu)建 WiredTiger 的 Python API。

前提條件:需要 SWIG 工具。

默認值:如果系統(tǒng)中存在 Python,默認情況下會啟用此選項。

用途:允許使用 Python 訪問 WiredTiger 功能。

-DENABLE_SNAPPY=1

功能:配置 WiredTiger 使用 snappy 壓縮。

默認值:如果系統(tǒng)中存在 snappy 庫,默認情況下會啟用此選項。

用途:提高數(shù)據(jù)壓縮效率。

-DENABLE_ZLIB=1

功能:配置 WiredTiger 使用 zlib 壓縮。

默認值:如果系統(tǒng)中存在 zlib 庫,默認情況下會啟用此選項。

用途:提高數(shù)據(jù)壓縮效率。

-DENABLE_ZSTD=1

功能:配置 WiredTiger 使用 Zstd 壓縮。

默認值:如果系統(tǒng)中存在 Zstd 庫,默認情況下會啟用此選項。

用途:提高數(shù)據(jù)壓縮效率。

-DWT_STANDALONE_BUILD=0

功能:配置 WiredTiger 禁用獨立構(gòu)建。獨立構(gòu)建默認是啟用的。

用途:如果你希望 WiredTiger 作為某個更大項目的一部分構(gòu)建,可以禁用獨立構(gòu)建。

-DHAVE_BUILTIN_EXTENSION_LZ4=1, -DHAVE_BUILTIN_EXTENSION_SNAPPY=1, -DHAVE_BUILTIN_EXTENSION_ZLIB=1, -DHAVE_BUILTIN_EXTENSION_ZSTD=1

功能:配置 WiredTiger 在主庫中包含對擴展的支持。這避免了需要額外的庫來支持這些擴展。目前支持的內(nèi)置擴展選項包括 lz4, snappy, zlib 和 zstd。

用途:簡化依賴管理,減少外部庫的依賴。

-DSPINLOCK_TYPE[=pthread, pthread_adaptive, gcc]

功能:配置 WiredTiger 使用特定的互斥鎖類型進行序列化。

選項:

pthread(默認):使用 POSIX 1003.1c 線程互斥鎖。

pthread_adaptive:使用配置為自適應的 POSIX 1003.1c 線程互斥鎖(如果該功能可用)。

gcc:使用基于 GCC 的自旋鎖。

用途:優(yōu)化多線程環(huán)境中的性能

找到故障WT文件

找到故障集合對應的wt文件

mongosh mongodb://mon1:30000 -u "admin" --authenticationDatabase "admin" -p sdhjfREWccacFWEF23e
mongos>use db2
db2> db.user1.stats()
    shard1: {
      ns: 'db2.user1',
      size: 9800,
      count: 214,
      avgObjSize: 45,
      numOrphanDocs: 0,
      storageSize: 40960,
      freeStorageSize: 16384,
      capped: false,
      wiredTiger: {
        metadata: { formatVersion: 1 },
        creationString: 'access_pattern_hint=none,allocation_size=4KB,app_metadata=(formatVersion=1),write_timestamp_usage=none',
        type: 'file',
        uri: 'statistics:table:collection-0-7625617652108868965',

###在shard1中找到user1集合對應的collection-0--8815599204543663053.wt
[root@shard1 data]# ll -h collection-0--8815599204543663053.wt
-rw------- 1 root root 24K Sep 29 14:46 collection-0--8815599204543663053.wt

恢復

---前提條件,數(shù)據(jù)庫應當停止
/opt/mongodb/bin/mongod --config /monogocluster/shard2/config/mongo-conf  --shutdown
---修復前備份數(shù)據(jù)文件

---修復操作需要在mongo數(shù)據(jù)目錄中執(zhí)行
/usr/local/bin/wt -v -C "extensions=[/usr/local/lib64/libwiredtiger_snappy.so]"  salvage file:collection-0--8815599204543663053.wt
---啟動數(shù)據(jù)庫
/opt/mongodb/bin/mongod --config /monogocluster/shard2/config/mongo-conf

數(shù)據(jù)庫恢復成功

--有時會出現(xiàn)這種報錯
{"t":{"$date":"2024-09-29T15:38:40.833+08:00"}, F  STORAGE  [initandlisten] Please read the documentation for starting MongoDB with --repair here: http://dochub.mongodb.org/core/repair
{"t":{"$date":"2024-09-29T15:38:40.833+08:00"}, F  -        [initandlisten] Fatal Assertion 50944 at src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 922
{"t":{"$date":"2024-09-29T15:38:40.833+08:00"}, F  -        [initandlisten] \n\n***aborting after fassert() failure\n\n

執(zhí)行以下操作修復

[root@ data]# /opt/mongodb/bin/mongod --dbpath /monogocluster/shard1/data --repair


再次啟動數(shù)據(jù)庫

查詢數(shù)據(jù)庫

[direct: mongos] test> use db2
switched to db db2
[direct: mongos] db2> db.user1.find()
[
  { _id: ObjectId("66f52c1a5e111baf0aa33a76"), id: 1, name: 'ty1' },
  { _id: ObjectId("66f52c1a5e111baf0aa33a7a"), id: 5, name: 'ty5' },
  { _id: ObjectId("66f52c1a5e111baf0aa33a7c"), id: 7, name: 'ty7' },
  { _id: ObjectId("66f52c1a5e111baf0aa33a7e"), id: 9, name: 'ty9' },
  { _id: ObjectId("66f52c1a5e111baf0aa33a7f"), id: 10, name: 'ty10' },
  { _id: ObjectId("66f52c1a5e111baf0aa33a82"), id: 13, name: 'ty13' }]

總結(jié)

WiredTiger 11.2.0 是一個強大且靈活的數(shù)據(jù)引擎,不僅提供了高效的數(shù)據(jù)存儲和檢索能力,還具備強大的數(shù)據(jù)恢復功能。通過合理的配置和優(yōu)化,WiredTiger 可以確保數(shù)據(jù)的完整性和可靠性,適用于多種高性能存儲和檢索場景。在使用過程中,合理配置和優(yōu)化是確保性能和數(shù)據(jù)安全的關(guān)鍵。通過注意配置優(yōu)化、數(shù)據(jù)一致性、性能監(jiān)控、安全性和升級維護,可以充分發(fā)揮 WiredTiger 的優(yōu)勢,滿足不同應用場景的需求。

作者介紹

吳守陽,51CTO社區(qū)編輯,擁有8年DBA工作經(jīng)驗,熟練管理MySQL、Redis、MongoDB等開源數(shù)據(jù)庫。精通性能優(yōu)化、備份恢復和高可用性架構(gòu)設(shè)計。善于故障排除和自動化運維,保障系統(tǒng)穩(wěn)定可靠。具備良好的團隊合作和溝通能力,致力于為企業(yè)提供高效可靠的數(shù)據(jù)庫解決方案。

責任編輯:華軒 來源: 51CTO
相關(guān)推薦

2014-12-17 10:54:14

MongoDB

2017-09-07 15:43:24

數(shù)據(jù)庫MongoDBMySQL

2022-05-12 11:12:46

MongoDB索引元數(shù)據(jù)

2020-02-05 09:53:03

Windows 10系統(tǒng)文件Windows

2021-07-09 18:26:41

PythonMySQL MongoDB

2019-03-04 11:30:07

修復Windows 10系統(tǒng)文件

2018-12-18 10:15:53

修復Windows 10DLL文件

2010-06-17 17:26:21

如何修復Grub

2019-03-04 14:40:46

Linux文件系統(tǒng)修復

2018-08-16 10:15:41

修復Windows 10bootres.dll

2015-08-24 09:44:16

VMware快照VMDK

2018-06-04 15:35:39

修復Windows 10Windows

2018-05-30 14:29:14

WindowsWindows 10系統(tǒng)文件

2018-07-26 11:35:20

WindowsWindows 10修復

2010-06-17 12:57:27

如何修復Grub

2013-05-30 08:49:37

網(wǎng)絡(luò)路由路由修復路由

2020-02-13 09:51:13

修復Windows 10配置文件

2018-03-06 09:30:58

2011-03-21 13:28:14

MongoDB文件存取

2016-01-05 10:06:09

軟件移植受損代碼代碼復制
點贊
收藏

51CTO技術(shù)棧公眾號