MONGODB: UNDERSTANDING OPLOG
The following table clearly explains what each Oplog field denotes.
| F | Alias | Details | Operations | Values |
| ts | TimeSpace | Holds the “Time of the operation” & “incremental id”. For all bulk (insert/remove/update) operations “Time of the operation” remains same and id changes to an incremental value. Default value of the id is 1 | For All Operations | (Time of the operation, incremental id) |
| h | hash | a unique ID for each operation | For All Operations | NumberLong(“7202552052460497158”) |
| t | NA | NA | For All Operations | NumberLong(1) |
| v | version# | version | For All Operations | 2 |
| op | Operation Type | Write operations (import/Insert/Delete/Update/) | Write Operations | i/d/u |
| Commands that affect database (Create, Drop: Database/collection) | Command Operations | C | ||
| Informational Operation | No-Operation | N | ||
| ns | NameSpace | The database and collection affected by the operation | Write Operations | (db_name.collection_name) |
| Command Operations | (db_name.$cmd)) | |||
| No-Operation | Blank | |||
| O | Operation | Info/Data of the Operations | Initiate Replica Set | {“msg” : “initiate set”} |
| On Electing as Primary | {“msg” : “new primary”} | |||
| Add Node1 as Secondary | {“msg” : “Reconfig Set”, “version”:2} | |||
| Add Node2 as Secondary | {“msg” : “Reconfig Set”, “version”:3} | |||
| Remove Node1 from RepSet | {“msg” : “Reconfig Set”, “version”:4} | |||
| Create Collection | { “create” : “posts” } | |||
| Drop Collection | { “drop” : “posts” } | |||
| Drop Database | { “dropDatabase” : 1 } | |||
| Insert/Delete a Document | {“_id”:1, “Name”:”ABC”} | |||
| Set () for update | { “$set” : { “Name” : “MyTest” } } | |||
| O2 | Update Operation | Holds the _id of the document to be updated | Update Document |
Oplog Default Size
When you start a replica set member for the first time, MongoDB creates an oplog of a default size.
- Default oplog size in Windows/Unix :
5% of physical memory/free disk space
50MB to 50GB of physical memory
990MB to 50GB of free disk space
- Default oplog size in OS X 64 bit :
192MB of physical memory/free disk space
Change Oplog size
- Đối với WiredTiger Storage Engine thì để thực hiện thay đổi oplog size cho mỗi member trong replicate
thì chỉ cần sử dụng replSetResizeOplog command. Bắt đầu thực hiện trên secondary trước rồi sau đó mới
thực hiên trên primary.
Các bước thực hiện như sau :
- 1. Connect to replica set member
- 2. Verify the current size oplog size.
use local
db.oplog.rs.status().maxSize
- 3. change the oplog size
db.adminCommand({replSetResizeOplog: 1, size: 16000}) (đơn vị byte)
Note: Nếu giàm kích thước oplog size xuống thì kích thước dung lượng dư thừa trên đĩa sẽ vẫn không được thu hồi
đi, nên cần phải thực hiện compact trên oplog để lấy lại dung lương đĩa.
commnad:
use local
db.runCommand({"compact" : "oplog.rs"})
Why the the big difference between storageSize and dataSize:
Nguyên nhân dẫn đến vấn đề này là do sự phân mảnh ( fragmentation) của data file. MongoDB cố gắng sử dụng free space
giữa các fragmented data khi có thể và nó không có giải phóng ra chó HDH. Tuy nhiên trong WiredTiger thì StỏageSize có thể nhỏ hơn dataSize nếu compression is enabled.
- Để có thể giải phóng nhưng dung lương này thì cần phải thực hiện run compact or repair operation
# Repair MongoDB
MongoDB repair operation repairs all errors & inconsistencies in data storage. Nếu journaling is enable thì không cần đến repair. server uses journal to get into clean state automatically after restart. The job requires free disk space equal to the size of your current data set plus 2 gigabytes.
# Compacting MongoDB
MongoDB compact operation rewrite all document and index in a collection to contiguous blocks of disk space.
Vì compact sẽ thực hiện block all other operations trên collection đó, nên nếu trường hơp mà replication thì cần thực hiên trên secondary trước sau đó mới đên primary.
- Default oplog size in Windows/Unix :
5% of physical memory/free disk space
50MB to 50GB of physical memory
990MB to 50GB of free disk space
- Default oplog size in OS X 64 bit :
192MB of physical memory/free disk space
Change Oplog size
- Đối với WiredTiger Storage Engine thì để thực hiện thay đổi oplog size cho mỗi member trong replicate
thì chỉ cần sử dụng replSetResizeOplog command. Bắt đầu thực hiện trên secondary trước rồi sau đó mới
thực hiên trên primary.
Các bước thực hiện như sau :
- 1. Connect to replica set member
- 2. Verify the current size oplog size.
use local
db.oplog.rs.status().maxSize
- 3. change the oplog size
db.adminCommand({replSetResizeOplog: 1, size: 16000}) (đơn vị byte)
Note: Nếu giàm kích thước oplog size xuống thì kích thước dung lượng dư thừa trên đĩa sẽ vẫn không được thu hồi
đi, nên cần phải thực hiện compact trên oplog để lấy lại dung lương đĩa.
commnad:
use local
db.runCommand({"compact" : "oplog.rs"})
Why the the big difference between storageSize and dataSize:
Nguyên nhân dẫn đến vấn đề này là do sự phân mảnh ( fragmentation) của data file. MongoDB cố gắng sử dụng free space
giữa các fragmented data khi có thể và nó không có giải phóng ra chó HDH. Tuy nhiên trong WiredTiger thì StỏageSize có thể nhỏ hơn dataSize nếu compression is enabled.
- Để có thể giải phóng nhưng dung lương này thì cần phải thực hiện run compact or repair operation
# Repair MongoDB
MongoDB repair operation repairs all errors & inconsistencies in data storage. Nếu journaling is enable thì không cần đến repair. server uses journal to get into clean state automatically after restart. The job requires free disk space equal to the size of your current data set plus 2 gigabytes.
# Compacting MongoDB
MongoDB compact operation rewrite all document and index in a collection to contiguous blocks of disk space.
Vì compact sẽ thực hiện block all other operations trên collection đó, nên nếu trường hơp mà replication thì cần thực hiên trên secondary trước sau đó mới đên primary.
Nhận xét
Đăng nhận xét