mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
ircd::db::database::env: Reduce file size system calls with cache pattern.
This commit is contained in:
parent
58a346f18b
commit
671120415f
2 changed files with 35 additions and 5 deletions
|
@ -1348,6 +1348,8 @@ noexcept try
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
assert(logical_size == -1UL || logical_size == fs::size(fd));
|
||||||
|
|
||||||
fd = fs::fd{};
|
fd = fs::fd{};
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
@ -1617,6 +1619,7 @@ noexcept try
|
||||||
wopts.nodelay = nodelay;
|
wopts.nodelay = nodelay;
|
||||||
wopts.interruptible = false;
|
wopts.interruptible = false;
|
||||||
fs::truncate(fd, size, wopts);
|
fs::truncate(fd, size, wopts);
|
||||||
|
logical_size = size;
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
catch(const std::system_error &e)
|
catch(const std::system_error &e)
|
||||||
|
@ -1668,6 +1671,9 @@ noexcept try
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if(likely(logical_size != -1UL) && offset + length > logical_size)
|
||||||
|
logical_size = -1UL;
|
||||||
|
|
||||||
if(opts.direct)
|
if(opts.direct)
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
|
|
||||||
|
@ -1732,7 +1738,14 @@ noexcept try
|
||||||
data(s), size(s)
|
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();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
catch(const std::system_error &e)
|
catch(const std::system_error &e)
|
||||||
|
@ -1798,7 +1811,19 @@ noexcept try
|
||||||
data(s), size(s)
|
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();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
catch(const std::system_error &e)
|
catch(const std::system_error &e)
|
||||||
|
@ -2042,14 +2067,18 @@ noexcept try
|
||||||
#ifdef RB_DEBUG_DB_ENV
|
#ifdef RB_DEBUG_DB_ENV
|
||||||
log::debug
|
log::debug
|
||||||
{
|
{
|
||||||
log, "[%s] wfile:%p fd:%d get file size",
|
log, "[%s] wfile:%p fd:%d get file size; cached:%zd",
|
||||||
d.name,
|
d.name,
|
||||||
this,
|
this,
|
||||||
int(fd)
|
int(fd),
|
||||||
|
logical_size,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return fs::size(fd);
|
if(logical_size == -1UL)
|
||||||
|
logical_size = fs::size(fd);
|
||||||
|
|
||||||
|
return logical_size;
|
||||||
}
|
}
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -227,6 +227,7 @@ ircd::db::database::env::writable_file
|
||||||
bool nodelay {false};
|
bool nodelay {false};
|
||||||
WriteLifeTimeHint hint {WriteLifeTimeHint::WLTH_NOT_SET};
|
WriteLifeTimeHint hint {WriteLifeTimeHint::WLTH_NOT_SET};
|
||||||
fs::fd fd;
|
fs::fd fd;
|
||||||
|
size_t logical_size {-1UL};
|
||||||
size_t preallocation_block_size {0};
|
size_t preallocation_block_size {0};
|
||||||
ssize_t preallocation_last_block {-1};
|
ssize_t preallocation_last_block {-1};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue