| 61 | } |
| 62 | |
| 63 | void MultiFileAllocationIterator::allocateChunk() |
| 64 | { |
| 65 | if (fileAllocationIterator_) { |
| 66 | if (!fileAllocationIterator_->finished()) { |
| 67 | fileAllocationIterator_->allocateChunk(); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | if (diskWriter_) { |
| 72 | diskWriter_->closeFile(); |
| 73 | diskWriter_.reset(); |
| 74 | } |
| 75 | fileAllocationIterator_.reset(); |
| 76 | ++entryItr_; |
| 77 | } |
| 78 | |
| 79 | while (entryItr_ != std::end(diskAdaptor_->getDiskWriterEntries())) { |
| 80 | if (!(*entryItr_)->getDiskWriter()) { |
| 81 | ++entryItr_; |
| 82 | continue; |
| 83 | } |
| 84 | |
| 85 | auto& fileEntry = (*entryItr_)->getFileEntry(); |
| 86 | // we use dedicated DiskWriter instead of |
| 87 | // (*entryItr_)->getDiskWriter(). This is because |
| 88 | // SingleFileAllocationIterator cannot reopen file if file is |
| 89 | // closed by OpenedFileCounter. |
| 90 | diskWriter_ = |
| 91 | DefaultDiskWriterFactory().newDiskWriter((*entryItr_)->getFilePath()); |
| 92 | // Open file before calling DiskWriterEntry::size(). Calling |
| 93 | // private function of MultiDiskAdaptor. |
| 94 | diskWriter_->openFile(fileEntry->getLength()); |
| 95 | |
| 96 | if ((*entryItr_)->needsFileAllocation() && |
| 97 | (*entryItr_)->size() < fileEntry->getLength()) { |
| 98 | A2_LOG_INFO(fmt("Allocating file %s: target size=%" PRId64 |
| 99 | ", current size=%" PRId64, |
| 100 | (*entryItr_)->getFilePath().c_str(), |
| 101 | fileEntry->getLength(), (*entryItr_)->size())); |
| 102 | switch (diskAdaptor_->getFileAllocationMethod()) { |
| 103 | #ifdef HAVE_SOME_FALLOCATE |
| 104 | case (DiskAdaptor::FILE_ALLOC_FALLOC): |
| 105 | fileAllocationIterator_ = make_unique<FallocFileAllocationIterator>( |
| 106 | diskWriter_.get(), (*entryItr_)->size(), fileEntry->getLength()); |
| 107 | break; |
| 108 | #endif // HAVE_SOME_FALLOCATE |
| 109 | case (DiskAdaptor::FILE_ALLOC_TRUNC): |
| 110 | fileAllocationIterator_ = make_unique<TruncFileAllocationIterator>( |
| 111 | diskWriter_.get(), (*entryItr_)->size(), fileEntry->getLength()); |
| 112 | break; |
| 113 | default: |
| 114 | fileAllocationIterator_ = make_unique<AdaptiveFileAllocationIterator>( |
| 115 | diskWriter_.get(), (*entryItr_)->size(), fileEntry->getLength()); |
| 116 | break; |
| 117 | } |
| 118 | fileAllocationIterator_->allocateChunk(); |
| 119 | return; |
| 120 | } |
nothing calls this directly
no test coverage detected