0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-19 19:33:45 +02:00

ircd::db::database::env: Reduce file size system calls with cache pattern.

This commit is contained in:
Jason Volk 2022-06-15 12:18:28 -07:00
parent 58a346f18b
commit 671120415f
2 changed files with 35 additions and 5 deletions

View file

@ -1348,6 +1348,8 @@ noexcept try
};
#endif
assert(logical_size == -1UL || logical_size == fs::size(fd));
fd = fs::fd{};
return Status::OK();
}
@ -1617,6 +1619,7 @@ noexcept try
wopts.nodelay = nodelay;
wopts.interruptible = false;
fs::truncate(fd, size, wopts);
logical_size = size;
return Status::OK();
}
catch(const std::system_error &e)
@ -1668,6 +1671,9 @@ noexcept try
};
#endif
if(likely(logical_size != -1UL) && offset + length > logical_size)
logical_size = -1UL;
if(opts.direct)
return Status::OK();
@ -1732,7 +1738,14 @@ noexcept try
data(s), size(s)
};
fs::append(fd, buf, wopts);
const const_buffer appended
{
fs::append(fd, buf, wopts)
};
if(likely(logical_size != -1UL))
logical_size += size(appended);
return Status::OK();
}
catch(const std::system_error &e)
@ -1798,7 +1811,19 @@ noexcept try
data(s), size(s)
};
fs::append(fd, buf, wopts);
const const_buffer appended
{
fs::append(fd, buf, wopts)
};
const auto append_break
{
offset + size(appended)
};
if(likely(logical_size != -1UL) && append_break > logical_size)
logical_size = append_break;
return Status::OK();
}
catch(const std::system_error &e)
@ -2042,14 +2067,18 @@ noexcept try
#ifdef RB_DEBUG_DB_ENV
log::debug
{
log, "[%s] wfile:%p fd:%d get file size",
log, "[%s] wfile:%p fd:%d get file size; cached:%zd",
d.name,
this,
int(fd)
int(fd),
logical_size,
};
#endif
return fs::size(fd);
if(logical_size == -1UL)
logical_size = fs::size(fd);
return logical_size;
}
catch(const std::exception &e)
{

View file

@ -227,6 +227,7 @@ ircd::db::database::env::writable_file
bool nodelay {false};
WriteLifeTimeHint hint {WriteLifeTimeHint::WLTH_NOT_SET};
fs::fd fd;
size_t logical_size {-1UL};
size_t preallocation_block_size {0};
ssize_t preallocation_last_block {-1};