Definition定义
replSetResizeOplogreplSetResizeOplogalso supports specifying the minimum number of hours to preserve an oplog entry.还支持指定保留oplog条目的最小小时数。
要在Changed in version 5.0.在版本5.0中的更改。To set thereplSetOplogsize inmongosh, use theDouble()constructor.mongosh中设置replSetOplog大小,请使用Double()构造函数。replSetResizeOplogenables you to resize the oplog or its minimum retention period dynamically without restarting the使您能够动态调整oplog或其最小保留期的大小,而无需重新启动mongodprocess.mongod进程。You must run this command against the您必须对admindatabase.admin数据库运行此命令。
Compatibility兼容性
This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:
Important
This command is not supported in MongoDB Atlas clusters. MongoDB Atlas集群不支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令。
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Note
To resize the oplog in Atlas, see Set Minimum Oplog Window.要调整Atlas中oplog的大小,请参阅设置最小oplog窗口。
Syntax语法
The command has the following form:该命令具有以下形式:
db.adminCommand(
{
replSetResizeOplog: <int>,
size: <double>,
minRetentionHours: <double>
}
)Command Fields命令字段
The command takes the following fields:该命令包含以下字段:
replSetResizeOplog | int | Set to 1. |
size |
| |
minRetentionHours |
|
Behavior行为
You can use 您可以在运行Wired Tiger存储引擎或内存存储引擎的replSetResizeOplog on mongod instances running with the Wired Tiger storage engine or the in-memory storage engine.mongod实例上使用replSetResizeOplog。
See the Change the Oplog Size of Self-Managed Replica Set Members tutorial for a procedure on using 有关使用replSetResizeOplog命令调整Oplog大小的过程,请参阅更改自我管理副本集成员的Oplog大小教程。replSetResizeOplog command to resize the oplog.
The oplog can grow past its configured size limit to avoid deleting the oplog可以超过其配置的大小限制,以避免删除多数提交点。majority commit point.
You cannot drop the 您无法删除local.oplog.rs collection. For more information on this restriction, see Oplog Collection Behavior.local.oplog.rs集合。有关此限制的更多信息,请参阅Oplog集合行为。
replSetResizeOplog overrides the maximum oplog size or minimum oplog retention period set at startup by:通过以下方式覆盖启动时设置的最大oplog大小或最小oplog保留期:
replication.oplogSizeMB/--oplogSizeMB, and,以及storage.oplogMinRetentionHours/--oplogMinRetentionHoursrespectively.分别。
The new oplog size persists after a server restart, unless you use:新的oplog大小在服务器重启后仍然存在,除非您使用:
Important
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 results in truncation of oplog entries older that the specified period if the oplog has exceeded the maximum configured size.同样,如果oplog超过了配置的最大大小,缩短oplog的最小保留期会导致比指定时间段更早的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条目的客户端出现意外行为,包括:
Open change streams may become invalidated开放的变更流可能会失效Secondaries which have not replicated those oplog entries may require resynchronization.未复制这些oplog条目的借调人员可能需要重新同步。Backups using对成员使用mongodumpwith--oplogagainst the member may not capture entries prior to truncation.mongodump和--oplog的备份可能无法在截断之前捕获条目。
Minimum Oplog Retention Period最短操作日志保留期
A 当配置了最小oplog保留期时,mongod has the following behavior when configured with a minimum oplog retention period:mongod具有以下行为:
The oplog can grow without constraint so as to retain oplog entries for the configured number of hours. This may result in reduction or exhaustion of system disk space due to a combination of high write volume and large retention period.oplog可以无约束地增长,以便在配置的小时数内保留oplog条目。由于写入量大和保留期长,这可能会导致系统磁盘空间减少或耗尽。If the oplog grows beyond its maximum size, the如果oplog增长超过其最大大小,即使oplog恢复到最大大小或配置为较小的最大大小,mongodmay continue to hold that disk space even if the oplog returns to its maximum size or is configured for a smaller maximum size.mongod也可能继续保留该磁盘空间。See Reducing Oplog Size Does Not Immediately Return Disk Space.请参阅减小操作日志大小不会立即返回磁盘空间。The在执行oplog条目保留时,mongodcompares the system wall clock to an oplog entries creation wall clock time when enforcing oplog entry retention.mongod将系统时钟与oplog条目创建时钟进行比较。Clock drift between cluster components may result in unexpected oplog retention behavior.集群组件之间的时钟漂移可能会导致意外的oplog保留行为。See Clock Synchronization for more information on clock synchronization across cluster members.有关跨群集成员的时钟同步的更多信息,请参阅时钟同步。
replSetResizeOplog Does Not Replicate To Other Members不复制给其他成员
Changing the oplog size or minimum oplog retention period 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保留期不会更改副本集中任何其他成员的oplo大小。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 Oplog Size Does Not Immediately Return Disk Space减小操作日志大小不会立即返回磁盘空间
Reducing the oplog size does not immediately reclaim that disk space. This includes oplog size reduction due to truncation of oplog events older than of the minimum oplog retention period.减小oplog大小并不会立即回收磁盘空间。这包括由于截断早于最小oplog保留期的oplog事件而导致的oplog大小减小。
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. Running compact against oplog.rs therefore prevents oplog synchronization. compact会阻止它所运行的数据库上的所有操作。因此,对oplog运行compact会阻止oplog同步。For a procedure on resizing the oplog and compacting 有关调整oplog大小和压缩oplog.rs, see Change the Oplog Size of Self-Managed Replica Set Members.oplog.rs的过程,请参阅更改自我管理副本集成员的oplog大小。
Resource Locking资源锁定
replSetResizeOplog takes an exclusive (W) lock on the oplog and blocks other operations on the collection until it finishes.replSetResizeOplog对oplog进行独占(W)锁,并阻止对集合的其他操作,直到它完成。
For more information on locking in MongoDB, see FAQ: Concurrency.有关MongoDB中锁定的更多信息,请参阅常见问题解答:并发。
Examples示例
Change the Maximum Oplog Size更改最大操作日志大小
Use the 使用db.collection.stats() mongosh method to display the current maximum oplog size, maxSize, in megabytes. For example:db.collection.stats()mongosh方法显示当前最大oplog大小maxSize,单位为兆字节。例如:
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": Long("16834")
Warning
Reducing the size of the oplog in a node removes data from it. This may cause replica members syncing with that node to become stale. 减小节点中oplog的大小会从中删除数据。这可能会导致与该节点同步的副本成员变得过时。To resync those members, see Resync a Member of a Self-Managed Replica Set.要重新同步这些成员,请参阅重新同步自我管理副本集的成员。
Change the Minimum Oplog Retention Period更改最短操作日志保留期
Connect将mongoshto themongodreplica set member.mongosh连接到mongod复制集成员。Optional. Use the可选。使用db.serverStatus()command to verify the current minimum oplog retention value asoplogTruncation.oplogMinRetentionHours:db.serverStatus()命令将当前最小oplog保留值验证为oplogTruncation.oplogMinRetentionHours:db.getSiblingDB("admin").serverStatus().oplogTruncation.oplogMinRetentionHoursThe command returns the currently configured minimum oplog retention period for the该命令返回mongod. For example:mongod当前配置的最小oplog保留期。例如:1.5If the如果mongodhas no minimum oplog retention period, the operation returns an empty result.mongod没有最小oplog保留期,则操作返回空结果。Use the使用replSetResizeOplogcommand to modify the configured minimum oplog retention period. For example, the following sets the minimum oplog retention period to2hours:replSetResizeOplog命令修改配置的最短oplog保留期。例如,以下将oplog的最短保留期设置为2小时:db.adminCommand({
"replSetResizeOplog" : 1,
"minRetentionHours" : 2
})