MCPcopy
hub / github.com/mochi-mqtt/server / readStore

Method readStore

server.go:1555–1602  ·  view source on GitHub ↗

readStore reads in any data from the persistent datastore (if applicable).

()

Source from the content-addressed store, hash-verified

1553
1554// readStore reads in any data from the persistent datastore (if applicable).
1555func (s *Server) readStore() error {
1556 if s.hooks.Provides(StoredClients) {
1557 clients, err := s.hooks.StoredClients()
1558 if err != nil {
1559 return fmt.Errorf("failed to load clients; %w", err)
1560 }
1561 s.loadClients(clients)
1562 s.Log.Debug("loaded clients from store", "len", len(clients))
1563 }
1564
1565 if s.hooks.Provides(StoredSubscriptions) {
1566 subs, err := s.hooks.StoredSubscriptions()
1567 if err != nil {
1568 return fmt.Errorf("load subscriptions; %w", err)
1569 }
1570 s.loadSubscriptions(subs)
1571 s.Log.Debug("loaded subscriptions from store", "len", len(subs))
1572 }
1573
1574 if s.hooks.Provides(StoredInflightMessages) {
1575 inflight, err := s.hooks.StoredInflightMessages()
1576 if err != nil {
1577 return fmt.Errorf("load inflight; %w", err)
1578 }
1579 s.loadInflight(inflight)
1580 s.Log.Debug("loaded inflights from store", "len", len(inflight))
1581 }
1582
1583 if s.hooks.Provides(StoredRetainedMessages) {
1584 retained, err := s.hooks.StoredRetainedMessages()
1585 if err != nil {
1586 return fmt.Errorf("load retained; %w", err)
1587 }
1588 s.loadRetained(retained)
1589 s.Log.Debug("loaded retained messages from store", "len", len(retained))
1590 }
1591
1592 if s.hooks.Provides(StoredSysInfo) {
1593 sysInfo, err := s.hooks.StoredSysInfo()
1594 if err != nil {
1595 return fmt.Errorf("load server info; %w", err)
1596 }
1597 s.loadServerInfo(sysInfo.Info)
1598 s.Log.Debug("loaded $SYS info from store")
1599 }
1600
1601 return nil
1602}
1603
1604// loadServerInfo restores server info from the datastore.
1605func (s *Server) loadServerInfo(v system.Info) {

Callers 2

ServeMethod · 0.95
TestServerReadStoreFunction · 0.80

Calls 12

loadClientsMethod · 0.95
loadSubscriptionsMethod · 0.95
loadInflightMethod · 0.95
loadRetainedMethod · 0.95
loadServerInfoMethod · 0.95
ProvidesMethod · 0.65
StoredClientsMethod · 0.65
StoredSubscriptionsMethod · 0.65
StoredSysInfoMethod · 0.65
ErrorfMethod · 0.45

Tested by 1

TestServerReadStoreFunction · 0.64