Skip to content

Transition rules manager to rule to client relationship #475

@bracyw

Description

@bracyw

Description

Currently the rules manager uses a client to rule structure that requires O(all_clients) iterations for each MQTT message:

clients_map: FxHashMap<ClientId, FxHashMap<Topic, Vec<Rule>>>,
rules_lookup: FxHashMap<Topic, FxHashSet<ClientId>>,

The current timing is not the worst as our client subscription size would most likely be at a max of 10 for the foreseeable future, however, logic-wise this is helpful and ultimately good to support early on.

Transition to:

pub struct RuleManager {
    rules: FxHashMap<RuleId, Rule>,
    topic_index: RwLock<FxHashMap<Topic, FxHashSet<RuleId>>>,
    subscriptions: RwLock<BiMultiMap<RuleId, ClientId>>,
}

BiMultiMap provides O(1) bidirectional lookups:

  • Rule → Clients (for MQTT notifications)
  • Client → Rules (for UI focused queries (what rules am I subbed too?)

Ultimately this will be transitioned to a database in the future, which should be seem less as the rules manager acts as a wrapper for whatever logic we decide it needs.

Acceptance Criteria

  • functionality stays the same (test with Postman before changes)
  • MQTT message processing uses O(1) topic lookup
  • all operations stay within O(n) time
  • concurrent MQTT processing enabled

Proposed Solution

  1. Create BiMultiMap<L, R> struct (ask @bracyw (me) for more details)
  2. Create new RuleManager structure with the new fields above
  3. Convert old functions to logic for the new structure

Metadata

Metadata

Assignees

Labels

difficultA task most likely involving researchscylla-serverDevelopment Focused in the Backend

Type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions