On this page本页内容
replSetResizeOplog
New in version 4.4.在版本4.4中新增。 replSetResizeOplog
also supports specifying the minimum number of hours to preserve an oplog entry.还支持指定保留oplog条目的最小小时数。
Changed in version 5.0.在版本5.0中更改。
replSetOplog
size in mongosh
, use the Double()
constructor.mongosh
中设置replSetOplog
大小,请使用Double()
构造函数。
replSetResizeOplog
enables you to resize the oplog or its minimum retention period dynamically without restarting the 允许您动态调整oplog或其最小保留期,而无需重新启动mongod
process.mongod
进程。
You must run this command against the 您必须对admin
database.admin
数据库运行此命令。
The command has the following form:命令的格式如下:
db.adminCommand(
{
replSetResizeOplog: <int>,
size: <double>,
minRetentionHours: <double>
}
)
replSetResizeOplog
takes the following fields:采用以下字段:
replSetResizeOplog | int | 1 .1 。 |
size | double |
|
minRetentionHours | double |
|
You can only use 您只能在使用Wired Tiger存储引擎运行的replSetResizeOplog
on mongod
instances running with the Wired Tiger storage engine.mongod
实例上使用replSetResizeOplog
。
See the Change the Size of the Oplog tutorial for a procedure on using 有关使用replSetResizeOplog
command to resize the oplog.replSetResizeOplog
命令调整Oplog大小的过程,请参阅更改Oplog大小教程。
Starting in MongoDB 4.0, the oplog can grow past its configured size limit to avoid deleting the 从MongoDB 4.0开始,oplog可以超过其配置的大小限制,以避免删除多数提交点。majority commit point
.
Starting in MongoDB 4.0, MongoDB forbids dropping the 从MongoDB 4.0开始,MongoDB禁止删除local.oplog.rs
collection. local.oplog.rs
集合。For more information on this restriction, see Oplog Collection Behavior.有关此限制的详细信息,请参阅Oplog集合行为。
replSetResizeOplog
overrides the maximum oplog size or minimum oplog retention period set at startup by:通过以下方式覆盖启动时设置的最大oplog大小或最小oplog保留期:
replication.oplogSizeMB
/ --oplogSizeMB
storage.oplogMinRetentionHours
/
--oplogMinRetentionHours
The new oplog size persists after a server restart, unless you use:新的oplog大小在服务器重新启动后仍然存在,除非您使用:
Reducing the maximum oplog size results in truncation of the oldest oplog entries until the oplog reaches the new configured size.减小最大oplog大小会导致截断最旧的oplog条目,直到oplog达到新的配置大小。
Similarly, reducing the minimum oplog retention period (new in 4.4) results in truncation of oplog entries older that the specified period if the oplog has exceeded the maximum configured size.类似地,如果oplog已超过最大配置大小,则缩短最小oplog保留期(4.4中的新增)将导致截断早于指定时间段的oplog条目。
Oplog truncation due to reduced oplog size or retention period can result in unexpected behavior from clients still reading those oplog entries, including:由于Oplog大小或保留期减少而导致的Oplog截断可能会导致仍在读取这些Oplog条目的客户端出现意外行为,包括:
resynchronization
。mongodump
with --oplog
against the member may not capture entries prior to truncation.mongodump
和--oplog
的备份可能无法在截断之前捕获条目。A 当配置了最小oplog保留期时,mongod
has the following behavior when configured with a minimum oplog retention period (New in 4.4):mongod
具有以下行为(4.4中的新增):
mongod
may continue to hold that disk space even if the oplog returns to its maximum size or is configured for a smaller maximum size. mongod
可能会继续保留该磁盘空间,即使oplog恢复到其最大大小或配置为较小的最大大小。mongod
compares the system wall clock to an oplog entries creation wall clock time when enforcing oplog entry retention. mongod
将系统时钟与oplog条目创建时钟时间进行比较。replSetResizeOplog
Changing the oplog size or minimum oplog retention period (new in 4.4) of a given replica set member with 使用replSetResizeOplog
does not change the oplog size of any other member in the replica set. replSetResizeOplog
更改给定副本集成员的oplog大小或最小oplog保留期(4.4中新增)不会更改副本集中任何其他成员的oplog大小。You must run 必须在群集中的每个副本集成员上运行replSetResizeOplog
on each replica set member in your cluster to change the oplog size or minimum retention period for all members.replSetResizeOplog
,才能更改所有成员的oplog大小或最小保留期。
Reducing the oplog size does not immediately reclaim that disk space. 减小oplog大小不会立即回收磁盘空间。This includes oplog size reduction due to truncation of oplog events older than of the minimum oplog retention period (New in 4.4).这包括由于截断比最小oplog保留期早的oplog事件而导致的oplog大小减小(4.4中的新增)。
To immediately free unused disk space after reducing the oplog size, run 要在减少oplog大小后立即释放未使用的磁盘空间,请在维护期间对compact
against the oplog.rs
collection in the local
database during a maintenance period. local
数据库中的oplog.rs
集合运行compact
。compact
blocks all operations on the database it runs against. compact
阻止对其运行的数据库的所有操作。Running 因此,针对compact
against oplog.rs
therefore prevents oplog synchronization. oplog.rs
运行compact
会阻止oplog同步。For a procedure on resizing the oplog and compacting 有关调整oplog大小和压缩oplog.rs
, see Change the Size of the Oplog.oplog.rs
的过程,请参阅更改oplog大小。
Changed in version 4.2.2.在版本4.2.2中更改。
replSetResizeOplog
takes an exclusive (W) lock on the oplog
and blocks other operations on the collection until it finishes.replSetResizeOplog
获取oplog
的独占(W)锁,并阻止集合上的其他操作,直到其完成。replSetResizeOplog
takes a global exclusive (W) lock and blocks all other operations until it finishes.replSetResizeOplog
使用全局独占(W)锁,并阻止所有其他操作,直到完成。For more information on locking in MongoDB, see FAQ: Concurrency.有关MongoDB中锁定的更多信息,请参阅常见问题解答:并发。
Use the 使用db.collection.stats()
mongosh
method to display the current maximum oplog size, maxSize
, in megabytes. db.collection.stats()
mongosh
方法以兆字节为单位显示当前最大oplog大小maxSize
。For example:
db.getSiblingDB("local").oplog.rs.stats(1024*1024).maxSize
The above command returns the oplog size of this member in megabytes:上述命令返回此成员的oplog大小(MB):
990
The following command uses 以下命令使用replSetResizeOplog
to change the oplog size of this member to 16384 megabytes:replSetResizeOplog
将此成员的oplog大小更改为16384 MB:
db.adminCommand({ "replSetResizeOplog": 1, size: Double(16384)})
To verify the new oplog size, rerun the 要验证新的oplog大小,请重新运行db.collection.stats()
method:db.collection.stats()
方法:
db.getSiblingDB("local").oplog.rs.stats(1024*1024).maxSize
The above command returns:上述命令返回:
"maxSize": NumberLong("16834")
Reducing the size of the oplog in a node removes data from it. 减小节点中oplog的大小会从中删除数据。This may cause replica members syncing with that node to become stale. 这可能会导致与该节点同步的副本成员过时。To resync those members, see Resync a Member of a Replica Set.要重新同步这些成员,请参阅重新同步副本集的成员。
mongosh
to the mongod
replica set member.mongosh
连接到mongod
复制集成员。Optional. 可选。Use the 使用db.serverStatus()
command to verify the current minimum oplog retention value as oplogTruncation.minRetentionHours
:db.serverStatus()
命令将当前最小oplog保留值验证为oplogTruncation.minRetentionHours
:
db.getSiblingDB("admin").serverStatus().oplogTruncation.minRetentionHours
The command returns the currently configured minimum oplog retention period for the 该命令返回当前为mongod
. mongod
配置的最小oplog保留期。For example:例如:
1.5
If the 如果mongod
has no minimum oplog retention period, the operation returns an empty result.mongod
没有最小的oplog保留期,则操作返回空结果。
Use the 使用replSetResizeOplog
command to modify the configured minimum oplog retention period. replSetResizeOplog
命令修改配置的最小oplog保留期。For example, the following sets the minimum oplog retention period to 例如,以下命令将oplog的最短保留时间设置为2
hours:2
小时:
db.adminCommand({ "replSetResizeOplog" : 1, "minRetentionHours" : 2 })