mirror of
https://github.com/matrix-construct/construct
synced 2025-03-14 05:20:17 +01:00
ircd::json::stack: Improve active checkpoint invalidation related.
This commit is contained in:
parent
9b2de5f4fc
commit
128fdfa8a3
2 changed files with 34 additions and 17 deletions
|
@ -74,6 +74,7 @@ struct ircd::json::stack
|
|||
size_t remaining() const;
|
||||
const_buffer completed() const;
|
||||
|
||||
size_t invalidate_checkpoints();
|
||||
bool flush(const bool &force = false) noexcept;
|
||||
size_t rewind(const size_t &bytes);
|
||||
void clear();
|
||||
|
|
50
ircd/json.cc
50
ircd/json.cc
|
@ -745,15 +745,18 @@ noexcept try
|
|||
|
||||
if(cp)
|
||||
{
|
||||
log::dwarning
|
||||
const size_t invalidated
|
||||
{
|
||||
"Flushing json::stack(%p) %zu bytes under checkpoint(%p)",
|
||||
this,
|
||||
size(buf.completed()),
|
||||
cp,
|
||||
invalidate_checkpoints()
|
||||
};
|
||||
|
||||
cp = nullptr;
|
||||
log::dwarning
|
||||
{
|
||||
"Flushing json::stack(%p) %zu bytes under %zu checkpoints.",
|
||||
this,
|
||||
size(buf.completed()),
|
||||
invalidated,
|
||||
};
|
||||
}
|
||||
|
||||
// The user returns the portion of the buffer they were able to flush
|
||||
|
@ -775,6 +778,17 @@ catch(...)
|
|||
return false;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::json::stack::invalidate_checkpoints()
|
||||
{
|
||||
size_t ret(0);
|
||||
for(auto cp(this->cp); cp; cp = cp->pc, ++ret)
|
||||
cp->s = nullptr;
|
||||
|
||||
this->cp = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::json::stack::clear()
|
||||
{
|
||||
|
@ -1498,15 +1512,15 @@ ircd::json::stack::checkpoint::checkpoint(stack &s,
|
|||
ircd::json::stack::checkpoint::~checkpoint()
|
||||
noexcept
|
||||
{
|
||||
if(!s)
|
||||
return;
|
||||
|
||||
if(std::uncaught_exceptions() && exception_rollback)
|
||||
decommit();
|
||||
|
||||
if(!committing())
|
||||
rollback();
|
||||
|
||||
if(!s)
|
||||
return;
|
||||
|
||||
assert(s->cp == this);
|
||||
s->cp = pc;
|
||||
}
|
||||
|
@ -1514,11 +1528,19 @@ noexcept
|
|||
bool
|
||||
ircd::json::stack::checkpoint::rollback()
|
||||
{
|
||||
if(!s || !s->cp)
|
||||
if(!s)
|
||||
{
|
||||
log::dwarning
|
||||
{
|
||||
"Attempting rollback of invalidated checkpoint(%p).",
|
||||
this,
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(point <= s->buf.consumed());
|
||||
s->buf.rewind(s->buf.consumed() - point);
|
||||
s->rewind(s->buf.consumed() - point);
|
||||
|
||||
const chase top
|
||||
{
|
||||
|
@ -1539,9 +1561,6 @@ ircd::json::stack::checkpoint::rollback()
|
|||
bool
|
||||
ircd::json::stack::checkpoint::decommit()
|
||||
{
|
||||
if(!s || !s->cp)
|
||||
return false;
|
||||
|
||||
committed = false;
|
||||
return true;
|
||||
}
|
||||
|
@ -1549,9 +1568,6 @@ ircd::json::stack::checkpoint::decommit()
|
|||
bool
|
||||
ircd::json::stack::checkpoint::recommit()
|
||||
{
|
||||
if(!s || !s->cp)
|
||||
return false;
|
||||
|
||||
committed = true;
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue