Skip to content

Commit de152bf

Browse files
author
Artyom Ivanov
committed
Replace ExtendResult with std::optional
1 parent ae4a822 commit de152bf

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

src/jrd/nbak.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ bool BackupManager::extendDatabase(thread_db* tdbb)
389389
if (maxAllocPage >= maxPage)
390390
return true;
391391

392-
const auto extensionResult = pgSpace->extend(tdbb, maxPage, true);
392+
const auto allocatedPages = pgSpace->extend(tdbb, maxPage, true);
393393
maxAllocPage = pgSpace->maxAlloc();
394-
if (extensionResult.success && maxAllocPage > maxPage)
394+
if (allocatedPages.has_value() && maxAllocPage > maxPage)
395395
return true;
396396

397397
// Fast file extension not succeeded for some reason, try file extension via direct file writes.

src/jrd/pag.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ namespace
312312
const ULONG usedPages = sequence * pageMgr.pagesPerPIP + pipUsed;
313313

314314
const bool allocateExactNumberOfPages = dbb->dbb_flags & DBB_no_reserve;
315-
const auto extensionResult = pageSpace->extend(tdbb, usedPages + initPages, allocateExactNumberOfPages);
316-
if (extensionResult.success)
317-
initPages = extensionResult.pagesAllocated;
315+
const auto allocatedPages = pageSpace->extend(tdbb, usedPages + initPages, allocateExactNumberOfPages);
316+
if (allocatedPages.has_value())
317+
initPages = allocatedPages.value();
318318
else
319319
{
320320
// For some reason fast file extension failed, maybe it is not supported by filesystem, or
@@ -1938,7 +1938,7 @@ ULONG PageSpace::usedPages(const Database* dbb)
19381938
return pgSpace->usedPages();
19391939
}
19401940

1941-
PageSpace::ExtendResult PageSpace::extend(thread_db* tdbb, const ULONG pageNum, bool forceSize)
1941+
std::optional<ULONG> PageSpace::extend(thread_db* tdbb, const ULONG pageNum, bool forceSize)
19421942
{
19431943
/**************************************
19441944
*
@@ -1958,11 +1958,11 @@ PageSpace::ExtendResult PageSpace::extend(thread_db* tdbb, const ULONG pageNum,
19581958
fb_assert(dbb == tdbb->getDatabase());
19591959

19601960
if (!PIO_fast_extension_is_supported(*file))
1961-
return {.success = false};
1961+
return std::nullopt;
19621962

19631963
// First, check it with the cached `maxPageNumber` value.
19641964
if (pageNum < maxPageNumber || pageNum < maxAlloc())
1965-
return {.success = true, .pagesAllocated = maxPageNumber - pageNum};
1965+
return maxPageNumber - pageNum;
19661966

19671967
const ULONG MAX_EXTEND_BYTES = static_cast<ULONG>(dbb->dbb_config->getDatabaseGrowthIncrement());
19681968
if (MAX_EXTEND_BYTES < MIN_EXTEND_BYTES)
@@ -1989,12 +1989,12 @@ PageSpace::ExtendResult PageSpace::extend(thread_db* tdbb, const ULONG pageNum,
19891989
try
19901990
{
19911991
if (!PIO_extend(tdbb, file, extPages, dbb->dbb_page_size))
1992-
return {.success = false};
1992+
return std::nullopt;
19931993

19941994
// File was extended, reset cached value
19951995
maxPageNumber = 0;
19961996

1997-
return {.success = true, .pagesAllocated = extPages};
1997+
return extPages;
19981998
}
19991999
catch (const status_exception&)
20002000
{
@@ -2005,15 +2005,15 @@ PageSpace::ExtendResult PageSpace::extend(thread_db* tdbb, const ULONG pageNum,
20052005
// if file was extended, return, else try to extend by less pages
20062006

20072007
if (const auto newMaxPageNumber = maxAlloc(); oldMaxPageNumber < newMaxPageNumber)
2008-
return {.success = true, .pagesAllocated = newMaxPageNumber - oldMaxPageNumber};
2008+
return newMaxPageNumber - oldMaxPageNumber;
20092009

20102010
extPages = MAX(reqPages, extPages / 2);
20112011
}
20122012
else
20132013
{
20142014
gds__log("Error extending file \"%s\" by %lu page(s).\nCurrently allocated %lu pages, requested page number %lu",
20152015
file->fil_string, extPages, maxPageNumber, pageNum);
2016-
return {.success = false};
2016+
return std::nullopt;
20172017
}
20182018
}
20192019
}

src/jrd/pag.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,8 @@ class PageSpace : public pool_alloc<type_PageSpace>
129129
ULONG usedPages();
130130
static ULONG usedPages(const Database* dbb);
131131

132-
struct ExtendResult
133-
{
134-
bool success = false;
135-
ULONG pagesAllocated = 0;
136-
};
137132
// extend page space
138-
ExtendResult extend(thread_db* tdbb, ULONG pageNum, bool forceSize);
133+
std::optional<ULONG> extend(thread_db* tdbb, ULONG pageNum, bool forceSize);
139134

140135
// get SCN's page number
141136
ULONG getSCNPageNum(ULONG sequence) noexcept;

0 commit comments

Comments
 (0)