Get the App
SLTechnology News&Howtos  ›  Database  › 

Whether MongoDB cannot log in to the application when indexing

Shulou Source: shulou.com Published: 2022-05-31 17:37:43 10月13日 Update

Whether MongoDB can not log in to the application when building the index, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

Background introduction:

Mongodb version 3.0.2

Indexing and collection and account query collection are on the same server and on different database names.

Because mongodb3.0.2 is used, it is known that 3. 0 is a row-level lock, so dba does not add the parameter background:true when indexing the table.

Check the cause:

The time when a colleague is unable to log in to the application coincides with the time period when the library has an index. So the main investigation is on the index. Later, the problem was confirmed by repeating the problem.

When the main library starts to build indexes, the read and write of the main library is normal. The application can be accessed normally. However, when the main database index is established and Secondary pulls a batch of oplog, when the oplog is replayed from the library, there is a special Lock::ParallelBatchWriterMode lock that blocks all read requests. This explains why the application cannot be accessed a few minutes after indexing.

After that, I consulted the information:

Try to avoid dirty reading and wait for a batch of oplog to be replayed before users are allowed to read the data.

Try to ensure synchronization performance. Imagine that if ordinary locks are used when replaying oplog, then oplog playback needs to compete with normal reads and writes for lock resources. If there are a large number of reads on the Secondary, it is bound to cause backup synchronization to gradually lag behind.

Although version 3. 0 read-write locks do not block the database, do not ignore the impact of the synchronization lock Lock::ParallelBatchWriterMode.

Resolve the problem:

Build an index when the database is as idle as possible

When building an index, it is best to add background:true.

This is the answer to the question about whether MongoDB can not log in to the application when building the index. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Tags: Index question application login data synchronization database time more version help solution blocking different easy ordinary special easy content reason Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Information MySQL Shulou Tech Info OPPO Reno