Exchange Database Internals: Transaction Logging and Recovery
In part 1 of this series, I discussed how to connect to the Exchange database cache and the...
Exchange database internals might seem to be a complicated topic, but we’re going to briefly discuss database internals from a very practical perspective.
Regardless of which Exchange client is used, after connecting through the various Exchange services and worker processes, a user ultimately accesses their mailbox via the Information Store process. The Exchange Information Store (formerly the Store.exe process, but with Exchange 2013 onward, Microsoft.Exchange.Store.Worker.exe) is where the Exchange Database Cache exists. A separate worker process runs for every database on a server. The cache holds all currently active Exchange database transactions in memory, such as new mail, deletions, modifications, etc. This cache can become quite large, but this is by design because keeping transactions in memory is much faster than fetching and updating database pages from disk. When the cache does read/write to the database (.edb), it does so in 32 KB pages.
Note: One of the biggest contributors to the IOPS reductions between Exchange 2003 and Exchange 2010 was the increase in database page size. Page size was 4 KB in Exchange 2003, 8 KB in 2007, and 32 KB in 2010 onwards. A larger page size translates to fewer requests to disk, as more data can be read/written per IO, but requires more RAM. |
It’s important to understand that clients connect to the cache, not the actual .edb file. No client ever directly accesses the database (.edb) or any log files (.log). Instead, all connections occur in memory to the database cache. Of course, if the database (.edb) file becomes locked due to another process (such as anti-virus or backup programs), the Information Service will eventually be unable to communicate with it, and the database will eventually dismount.
When discussing backups, transaction logs are extremely important, so it’s vital to understand which role they play in database transactions. As transactions occur in the cache, they create a series of transaction records or log data, which fills a log buffer. Once a log buffer is full (1 MB), it is flushed to disk to create a 1 MB transaction log file. This process repeats as more transactions occur in cache and the log buffer fills and is written to disk. The currently active transaction log file is always E0n.log, where n represents the number of the log stream for that database.
Note: The first database on a server will be E00.log, the second will be E01.log and so on. Once the current log file is committed to disk, it is renamed to a value such as E0000000001.log, E0000000002.log and so on. These log files are in Hexadecimal, so as an example, E0000000009.log would be followed by E000000000A.log. |
As transaction log files are written to disk, the transactions in cache might yet still not be committed to the actual database (.edb) file. This process is referred to as “write-ahead logging” (In fact, technically the transactions are written to the logs before the user sees the change). This is because writes to the database are random IO while creating a transaction log is a sequential IO. Since the data being written to the database could be located anywhere in a very large .edb file, the operation on disk is usually random. On the other hand, creating a 1 MB transaction log takes a single new sequential write operation to disk. With rotational media, this distinction becomes important as Seek Time contributes to disk latency. Sequential IO is very low impact on a disk subsystem while random IO is more burdensome. Writing the transactions sequentially to logs instead of the database (.edb) file allows the transactions to be captured efficiently (in cache and on disk in the transaction log) while also reducing random IOPS. The focus on trading random IO for sequential IO by using memory has contributed to the gradual reduction in the product’s IO requirement since Exchange 2007.
When are the transactions written to the database (.edb) file? After a predetermined amount of transaction logs are generated, the transactions in cache are flushed to the database (.edb) file. The predetermined amount is called the Checkpoint Depth Target and is tracked by the Checkpoint File (.chk). The Checkpoint File monitors the logs with the oldest outstanding uncommitted page. Databases which have no replicas/copies have a Checkpoint Depth Target of 20 transaction logs whereas databases with passive copies (DAG) have a target of 100 transaction logs. This fact will become relevant when I discuss log truncation, especially in a DAG, in part two of this series. Stay tuned for more on Exchange database internals next week.
I work for Dell as a Principal Engineer in the Global Support & Deployment organization; serving as a senior point of escalation for Microsoft technologies to Dell's ProSupport & Consulting Services customers. My specialties are Exchange, Office 365, & Directory Services; while also being responsible for internal training development/delivery & managing various projects. I'm a Microsoft Certified Master in Exchange 2010 & a Microsoft Certified Solutions Master in Exchange 2013. I enjoy getting to work with a wide variety of customers, as it allows me to assist in resolving the various complexities & challenges they encounter. I try to use that experience to help others by blogging at Exchangemaster.wordpress.com with a few of my fellow MCM's at Dell. I also co-founded an Exchange Server community on Reddit (Reddit.com/r/ExchangeServer) where I answer questions on the product & help lead discussion around Exchange/Office 365. You'll also find me blogging about various other topics at ashdrewness.wordpress.com. I'm also the co-author of the Exchange Server Troubleshooting Companion (http://exchangeserverpro.com/ebooks/exchange-server-troubleshooting-companion/) I enjoy spending time with my lovely wife Lindsay, am a Texas Longhorns/Houston Texans fan, & try to sneak out onto a golf course every chance I get.
In part 1 of this series, I discussed how to connect to the Exchange database cache and the...
As an Exchange administrator you likely work in an environment that has public folders. Public...