Skip to content

Commit

Permalink
ircd::m: Add slave refresh interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
jevolk committed Mar 20, 2023
1 parent 1973e2c commit fc495f0
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/ircd/m/homeserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct ircd::m::homeserver
static homeserver *init(const struct opts *);
static void fini(homeserver *) noexcept;
static bool rehash(homeserver *);
static bool refresh(homeserver *);
};

struct ircd::m::homeserver::key
Expand Down
11 changes: 11 additions & 0 deletions include/ircd/m/vm/seq.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace ircd::m::vm::sequence
{
struct refresh;

extern ctx::dock dock;
extern uint64_t retired; // already written; always monotonic
extern uint64_t committed; // pending write; usually monotonic
Expand All @@ -25,3 +27,12 @@ namespace ircd::m::vm::sequence
uint64_t max();
uint64_t min();
}

struct ircd::m::vm::sequence::refresh
{
uint64_t database[2] {0, 0};
uint64_t retired[2] {0, 0};
m::event::id::buf event_id;

refresh();
};
35 changes: 35 additions & 0 deletions matrix/homeserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,41 @@ ircd::m::homeserver::rehash(homeserver *const homeserver)
return true;
}

bool
IRCD_MODULE_EXPORT
ircd::m::homeserver::refresh(homeserver *const homeserver)
try
{
if(!homeserver)
return false;

const ctx::uninterruptible::nothrow ui;
const vm::sequence::refresh refresh;
if(ircd::debugmode)
log::logf
{
log, log::level::DEBUG,
"refreshed events[%12lu -> %-12lu] vm[%10lu -> %-10lu] %s",
refresh.database[0],
refresh.database[1],
refresh.retired[0],
refresh.retired[1],
string_view{refresh.event_id},
};

return true;
}
catch(const std::exception &e)
{
log::error
{
log, "refresh :%s",
e.what(),
};

return false;
}

//
// homeserver::homeserver::homeserver
//
Expand Down
28 changes: 28 additions & 0 deletions matrix/vm_seq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@ ircd::m::vm::sequence::committed;
decltype(ircd::m::vm::sequence::uncommitted)
ircd::m::vm::sequence::uncommitted;

//
// refresh::refresh
//

ircd::m::vm::sequence::refresh::refresh()
{
auto &database
{
db::database::get("events")
};

if(!database.slave)
return;

this->database[0] = db::sequence(database);
this->retired[0] = sequence::retired;

db::refresh(database);
sequence::retired = sequence::get(this->event_id);

this->database[1] = db::sequence(database);
this->retired[1] = sequence::retired;
}

//
// tools
//

uint64_t
ircd::m::vm::sequence::min()
{
Expand Down

0 comments on commit fc495f0

Please sign in to comment.