[SERVER-64752] Does WT metadata change when closing a readonly WT_CONNECTION? Created: 21/Mar/22  Updated: 29/Oct/23  Resolved: 21/Mar/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.0.0-rc0

Type: Question Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: A. Jesse Jiryu Davis
Resolution: Fixed Votes: 0
Labels: shard-merge-milestone-1
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-64759 Reopen WT connection in readonly mode... Closed
Backwards Compatibility: Fully Compatible
Participants:

 Description   

When we started implementing PM-2353, Dan Gottlieb provided this helpful sketch that shows how to import MongoDB collections from a directory full of WT files. It follows these steps:

1. Call wiredtiger_open on the directory of WT files
2. Fetch WT table and file metadata and save them in memory
3. Close the WT_CONNECTION
4. Select which files to import
5. Move selected files from temp directory to mongod's dbpath
6. Call WT_SESSION::create for each selected file, using metadata from step 2

Dan asked, regarding step 3:

Closing WT I believe will take a checkpoint. Even though we did no logical writes, it's not obvious to me that the root node offsets we saved as part of the WT metadata sit still. The most conservative thing to do is copy the files at this step before closing WT. Obviously that's less desirable than just moving the files. Moving the files underneath WT while running will almost certainly result WT taking down the whole mongod process.

Worth clarifying with WT how these files can be safely and optimally transfered to the "real" dbpath. If my hunch is right that moving files after closing is not safe today – my guess is it's easy for WT to add configuration string to `WT_CONNECTION::close` that skips taking a checkpoint or find some equivalent solution.

Could a WiredTiger expert answer his question?



 Comments   
Comment by Keith Smith [ 29/Mar/22 ]

jesse, your guess is correct.  WiredTiger doesn't perform rollback-to-stable on a readonly connection. 

Comment by A. Jesse Jiryu Davis [ 29/Mar/22 ]

keith.smith late-breaking question about this: Does WT execute rollback-to-stable if we open a WT database in readonly mode? If so we could call wiredtiger_open just once. But I'm guessing the answer is "no", since rollback-to-stable would seem to violate the "readonly" contract.

Comment by A. Jesse Jiryu Davis [ 21/Mar/22 ]

Let's follow Keith's suggestion. Even if our current code is safe, it relies on WT internals instead of the WT API. It's more future-proof to close and reopen with "readonly=true".

Comment by Keith Smith [ 21/Mar/22 ]

jesse:

Dan G is correct that WT will take a checkpoint at connection close.  Normally we skip checkpoint on a file if no data has changed. I'm not sure offhand whether the checkpoint at close behaves the same way.  I will look into that.  

Regardless of the answer, an alternative that would certainly work would be to reopen the connection readonly after step #1.  I.e., expand #1 to:

  • Call wiredtiger_open on the directory of backed up WT files
  • Close the connection
  • Open a new WT connection with the readonly=true config setting
  • Continue as described above.

 

Generated at Thu Feb 08 06:01:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.