| 2682 | |
| 2683 | // Write one block of a page of a physical page in the page file. Futures returned must be allowed to complete. |
| 2684 | ACTOR static UNCANCELLABLE Future<Void> writePhysicalBlock(DWALPager* self, |
| 2685 | Reference<ArenaPage> page, |
| 2686 | int blockNum, |
| 2687 | int blockSize, |
| 2688 | PhysicalPageID pageID, |
| 2689 | PagerEventReasons reason, |
| 2690 | unsigned int level, |
| 2691 | bool header) { |
| 2692 | |
| 2693 | state PriorityMultiLock::Lock lock = wait(self->ioLock.lock(header ? ioMaxPriority : ioMinPriority)); |
| 2694 | ++g_redwoodMetrics.metric.pagerDiskWrite; |
| 2695 | g_redwoodMetrics.level(level).metrics.events.addEventReason(PagerEvents::PageWrite, reason); |
| 2696 | if (self->memoryOnly) { |
| 2697 | return Void(); |
| 2698 | } |
| 2699 | |
| 2700 | // If a truncation up to include pageID has not yet been completed |
| 2701 | if (pageID >= self->filePageCount) { |
| 2702 | // And no extension pending will include pageID |
| 2703 | if (pageID >= self->filePageCountPending) { |
| 2704 | // Update extension to a new one that waits on the old one and extends further |
| 2705 | self->fileExtension = extendToCover(self, pageID, self->fileExtension); |
| 2706 | } |
| 2707 | |
| 2708 | // Wait for extension that covers pageID to complete; |
| 2709 | wait(self->fileExtension); |
| 2710 | } |
| 2711 | |
| 2712 | // Note: Not using forwardError here so a write error won't be discovered until commit time. |
| 2713 | debug_printf("DWALPager(%s) op=writeBlock %s\n", self->filename.c_str(), toString(pageID).c_str()); |
| 2714 | wait(self->pageFile->write(page->rawData() + (blockNum * blockSize), blockSize, (int64_t)pageID * blockSize)); |
| 2715 | |
| 2716 | // This next line could crash on shutdown because this actor can't be cancelled so self could be destroyed after |
| 2717 | // write, so enable this line with caution when debugging. |
| 2718 | // debug_printf("DWALPager(%s) op=writeBlockDone %s\n", self->filename.c_str(), toString(pageID).c_str()); |
| 2719 | |
| 2720 | return Void(); |
| 2721 | } |
| 2722 | |
| 2723 | ACTOR static Future<Void> extendToCover(DWALPager* self, uint64_t pageID, Future<Void> previousExtension) { |
| 2724 | // Calculate new page count, round up to nearest multiple of growth size > pageID |
no test coverage detected