0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd:Ⓜ️:dbs: Purge old cruft; add various \briefs.

This commit is contained in:
Jason Volk 2018-04-12 19:26:33 -07:00
parent 90597bc59c
commit cee7a17330
2 changed files with 21 additions and 220 deletions

View file

@ -11,6 +11,8 @@
#pragma once #pragma once
#define HAVE_IRCD_M_DBS_H #define HAVE_IRCD_M_DBS_H
/// Database Schema
///
namespace ircd::m::dbs namespace ircd::m::dbs
{ {
struct init; struct init;
@ -61,12 +63,17 @@ struct ircd::m::dbs::write_opts
bool history {true}; bool history {true};
}; };
/// Database Schema Descriptors
///
namespace ircd::m::dbs::desc namespace ircd::m::dbs::desc
{ {
// Full description // Full description
extern const database::description events; extern const database::description events;
//
// Direct columns // Direct columns
//
extern const database::descriptor events_auth_events; extern const database::descriptor events_auth_events;
extern const database::descriptor events_content; extern const database::descriptor events_content;
extern const database::descriptor events_depth; extern const database::descriptor events_depth;
@ -84,18 +91,25 @@ namespace ircd::m::dbs::desc
extern const database::descriptor events_state_key; extern const database::descriptor events_state_key;
extern const database::descriptor events_type; extern const database::descriptor events_type;
//
// Metadata columns // Metadata columns
extern const database::descriptor events__state_node; //
// room events sequence
extern const db::prefix_transform events__room_events__pfx; extern const db::prefix_transform events__room_events__pfx;
extern const db::comparator events__room_events__cmp; extern const db::comparator events__room_events__cmp;
extern const database::descriptor events__room_events; extern const database::descriptor events__room_events;
// room present state mapping sequence
extern const db::prefix_transform events__room_state__pfx;
extern const database::descriptor events__room_state;
// room present joined members sequence
extern const db::prefix_transform events__room_origins__pfx; extern const db::prefix_transform events__room_origins__pfx;
extern const database::descriptor events__room_origins; extern const database::descriptor events__room_origins;
extern const db::prefix_transform events__room_state__pfx; // state btree node key-value store
extern const database::descriptor events__room_state; extern const database::descriptor events__state_node;
} }
struct ircd::m::dbs::init struct ircd::m::dbs::init

View file

@ -1193,229 +1193,18 @@ ircd::m::dbs::desc::events_prev_state
} }
}; };
/*
const ircd::database::descriptor
event_id_in_sender
{
// name
"event_id in sender",
// explanation
R"(### developer note:
key is "@sender$event_id"
the prefix transform is in effect. this column indexes events by
sender offering an iterable bound of the index prefixed by sender
)",
// typing (key, value)
{
typeid(ircd::string_view), typeid(ircd::string_view)
},
// options
{},
// comparator
{},
// prefix transform
event_id_in,
};
/// prefix transform for origin in
///
/// This transform expects a concatenation ending with an origin which means
/// the prefix can be the same for multiple origins; therefor we can find
/// or iterate "origin in X" where X is some repeated prefix
///
/// TODO: strings will have character conflicts. must address
const ircd::db::prefix_transform
origin_in
{
"origin in",
[](const ircd::string_view &key)
{
return has(key, ":::");
//return key.find(':') != key.npos;
},
[](const ircd::string_view &key)
{
return split(key, ":::").first;
//return rsplit(key, ':').first;
}
};
const ircd::database::descriptor
origin_in_room_id
{
// name
"origin in room_id",
// explanation
R"(### developer note:
key is "!room_id:origin"
the prefix transform is in effect. this column indexes origins in a
room_id offering an iterable bound of the index prefixed by room_id
)",
// typing (key, value)
{
typeid(ircd::string_view), typeid(ircd::string_view)
},
// options
{},
// comparator - sorts from highest to lowest
{}, //ircd::db::reverse_cmp_string_view{},
// prefix transform
origin_in,
};
const ircd::database::descriptor
origin_joined_in_room_id
{
// name
"origin_joined in room_id",
// explanation
R"(### developer note:
key is "!room_id:origin"
the prefix transform is in effect. this column indexes origins in a
room_id offering an iterable bound of the index prefixed by room_id
)",
// typing (key, value)
{
typeid(ircd::string_view), typeid(ircd::string_view)
},
// options
{},
// comparator - sorts from highest to lowest
{}, //ircd::db::reverse_cmp_string_view{},
// prefix transform
origin_in,
};
/// prefix transform for room_id
///
/// This transform expects a concatenation ending with a room_id which means
/// the prefix can be the same for multiple room_id's; therefor we can find
/// or iterate "room_id in X" where X is some repeated prefix
///
const ircd::db::prefix_transform room_id_in
{
"room_id in",
[](const ircd::string_view &key)
{
return key.find('!') != key.npos;
},
[](const ircd::string_view &key)
{
return rsplit(key, '!').first;
}
};
const ircd::database::descriptor
prev_event_id_for_event_id_in_room_id
{
// name
"prev_event_id for event_id in room_id",
// explanation
R"(### developer note:
)",
// typing (key, value)
{
typeid(ircd::string_view), typeid(ircd::string_view)
},
// options
{},
// comparator
{},
// prefix transform
event_id_in
};
/// prefix transform for event_id in room_id,type,state_key
///
/// This transform is special for concatenating room_id with type and state_key
/// and event_id in that order with prefix being the room_id,type,state_key. This
/// will index multiple event_ids with the same type,state_key in a room which
/// allows for a temporal depth to the database; event_id for type,state_key only
/// resolves to a single latest event and overwrites itself as per the room state
/// algorithm whereas this can map all of them and then allows for tracing.
///
/// TODO: arbitrary type strings will have character conflicts. must address
/// TODO: with grammars.
const ircd::db::prefix_transform
event_id_in_room_id_type_state_key
{
"event_id in room_id,type_state_key",
[](const ircd::string_view &key)
{
return has(key, '$');
},
[](const ircd::string_view &key)
{
return split(key, '$').first;
}
};
const ircd::database::descriptor
prev_event_id_for_type_state_key_event_id_in_room_id
{
// name
"prev_event_id for type,state_key,event_id in room_id",
// explanation
R"(### developer note:
)",
// typing (key, value)
{
typeid(ircd::string_view), typeid(ircd::string_view)
},
// options
{},
// comparator
{},
// prefix transform
event_id_in_room_id_type_state_key
};
*/
const ircd::database::description const ircd::database::description
ircd::m::dbs::desc::events ircd::m::dbs::desc::events
{ {
// Requirement of RocksDB/LevelDB // Requirement of RocksDB/LevelDB
{ "default" }, { "default" },
////////
// //
// These columns directly represent event fields indexed by event_id and // These columns directly represent event fields indexed by event_id and
// the value is the actual event values. Some values may be JSON, like // the value is the actual event values. Some values may be JSON, like
// content. // content.
// //
events_auth_events, events_auth_events,
events_content, events_content,
events_depth, events_depth,
@ -1433,25 +1222,23 @@ ircd::m::dbs::desc::events
events_state_key, events_state_key,
events_type, events_type,
////////
// //
// These columns are metadata composed from the event data. Specifically, // These columns are metadata composed from the event data. Specifically,
// they are designed for fast sequential iterations. // they are designed for fast sequential iterations.
// //
// (room_id, event_id) => (state_root) // (room_id, (depth, event_id)) => (state_root)
// Sequence of all events for a room, ever. // Sequence of all events for a room, ever.
events__room_events, events__room_events,
// (room_id, origin) => () // (room_id, (origin, user_id)) => ()
// Sequence of all PRESENTLY JOINED origins for a room. // Sequence of all PRESENTLY JOINED origins for a room.
events__room_origins, events__room_origins,
// (room_id, type, state_key) => (event_id) // (room_id, (type, state_key)) => (event_id)
// Sequence of the PRESENT STATE of the room. // Sequence of the PRESENT STATE of the room.
events__room_state, events__room_state,
////////
// //
// Other columns // Other columns
// //