0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-27 11:18:51 +02:00

ircd:Ⓜ️:dbs: Reorg write_opts; throw panic on nul event_idx; various.

This commit is contained in:
Jason Volk 2019-05-07 15:19:38 -07:00
parent 9d5f0049cf
commit 180c83634f
4 changed files with 38 additions and 43 deletions

View file

@ -105,44 +105,41 @@ struct ircd::m::dbs::write_opts
static const std::bitset<256> event_refs_all;
static const std::bitset<64> appendix_all;
/// Operation code
/// Operation code; usually SET or DELETE. Note that we interpret the
/// code internally and may set different codes for appendages of the
/// actual transaction.
db::op op {db::op::SET};
/// Principal's index number. Most codepaths do not permit zero; must set.
uint64_t event_idx {0};
/// Fuse panel to toggle transaction elements.
std::bitset<64> appendix {appendix_all};
/// Whether the event.source can be used directly for event_json. Defaults
/// to false unless the caller wants to avoid a redundant re-stringify.
bool json_source {false};
/// Selection of what reference types to manipulate in event_refs. Refs
/// will not be made if it is not appropriate for the event anyway, so
/// this defaults to all bits. User can disable one or more ref types
/// by clearing a bit.
std::bitset<256> event_refs {event_refs_all};
/// User can supply a view of already-generated keys with event_refs_key().
/// This vector will be checked first before generating that key, which
/// can avoid any index() queries internally to generate it.
vector_view<const string_view> event_refs_hint;
/// Whether the present state table `room_state` should be updated by
/// this operation if appropriate.
bool present {true};
/// Whether the history state btree `state_node` + `room_events` value
/// should be updated by this operation if appropriate.
bool history {true};
/// The state btree root to perform the update on.
string_view root_in;
/// After the update is performed, the new state btree root is returned
/// into this buffer.
mutable_buffer root_out;
/// Fuse panel to toggle transaction elements.
std::bitset<64> appendix {appendix_all};
/// Selection of what reference types to manipulate in event_refs. Refs
/// will not be made if it is not appropriate for the event anyway, so
/// this defaults to all bits. User can disable one or more ref types
/// by clearing a bit.
std::bitset<256> event_refs {event_refs_all};
/// Whether the present state table `room_state` should be updated by
/// this operation if appropriate.
bool present {true};
/// Whether the history state btree `state_node` + `room_events` value
/// should be updated by this operation if appropriate.
bool history {false};
/// Whether the event.source can be used directly for event_json. Defaults
/// to false unless the caller wants to avoid a redundant re-stringify.
bool json_source {false};
};
enum ircd::m::dbs::appendix::index

View file

@ -232,7 +232,7 @@ ircd::m::dbs::write(db::txn &txn,
const write_opts &opts)
{
if(unlikely(opts.event_idx == 0))
throw ircd::error
throw panic
{
"Cannot write to database: no index specified for event."
};
@ -871,7 +871,9 @@ try
const string_view &new_root
{
opts.op == db::op::SET && opts.appendix.test(appendix::HISTORY)?
opts.op == db::op::SET &&
opts.appendix.test(appendix::HISTORY) &&
opts.history?
state::insert(txn, opts.root_out, opts.root_in, event):
strlcpy(opts.root_out, opts.root_in)
};
@ -932,7 +934,8 @@ try
{
target.valid &&
defined(json::get<"state_key"_>(target)) &&
opts.appendix.test(appendix::HISTORY)?
opts.appendix.test(appendix::HISTORY) &&
opts.history?
//state::remove(txn, state_root_out, state_root_in, target):
strlcpy(opts.root_out, opts.root_in):
strlcpy(opts.root_out, opts.root_in)

View file

@ -121,8 +121,8 @@ ircd::m::room::state::force_present(const m::event &event)
opts.event_idx = m::index(event);
opts.present = true;
opts.history = false;
opts.room_head = false;
opts.room_refs = false;
opts.appendix.reset(dbs::appendix::ROOM_HEAD);
opts.appendix.reset(dbs::appendix::ROOM_HEAD_REFS);
m::dbs::_index__room_state(txn, event, opts);
m::dbs::_index__room_joined(txn, event, opts);
@ -174,8 +174,8 @@ ircd::m::room::state::rebuild_present(const state &state)
opts.event_idx = event_idx;
opts.present = true;
opts.history = false;
opts.room_head = false;
opts.room_refs = false;
opts.appendix.reset(dbs::appendix::ROOM_HEAD);
opts.appendix.reset(dbs::appendix::ROOM_HEAD_REFS);
m::dbs::_index__room_state(txn, event, opts);
m::dbs::_index__room_joined(txn, event, opts);
@ -225,8 +225,8 @@ ircd::m::room::state::rebuild_history(const state &state)
opts.root_out = root[++r % 2];
opts.present = false;
opts.history = true;
opts.room_head = false;
opts.room_refs = false;
opts.appendix.reset(dbs::appendix::ROOM_HEAD);
opts.appendix.reset(dbs::appendix::ROOM_HEAD_REFS);
int64_t depth{0};
for(; it; ++it)
@ -3245,8 +3245,6 @@ ircd::m::room::head::rebuild(const head &head)
m::dbs::write_opts opts;
opts.op = db::op::SET;
opts.room_head = true;
opts.room_refs = true;
for(; it; ++it)
{
const m::event &event{*it};
@ -3282,7 +3280,6 @@ ircd::m::room::head::reset(const head &head)
// Iterate all of the existing heads with a delete operation
m::dbs::write_opts opts;
opts.op = db::op::DELETE;
opts.room_head = true;
m::room::head{room}.for_each([&room, &opts, &txn, &ret]
(const m::event::idx &event_idx, const m::event::id &event_id)
{
@ -3337,8 +3334,6 @@ ircd::m::room::head::modify(const m::event::id &event_id,
// Iterate all of the existing heads with a delete operation
m::dbs::write_opts opts;
opts.op = op;
opts.room_head = true;
opts.room_refs = refs;
opts.event_idx = event.event_idx;
m::dbs::_index__room_head(txn, event, opts);

View file

@ -844,8 +844,8 @@ ircd::m::vm::write_append(eval &eval,
wopts.root_out = new_root_buf;
wopts.present = opts.present;
wopts.history = opts.history;
wopts.room_head = opts.room_head;
wopts.room_refs = opts.room_refs;
wopts.appendix.set(dbs::appendix::ROOM_HEAD, opts.room_head);
wopts.appendix.set(dbs::appendix::ROOM_HEAD_REFS, opts.room_refs);
wopts.json_source = opts.json_source;
wopts.event_idx = eval.sequence;