Changeset 406 in code for trunk/upstream.go


Ignore:
Timestamp:
Aug 20, 2020, 3:38:57 PM (5 years ago)
Author:
contact
Message:

Replace networkHistory.offlineClients with clients

Keep the ring buffer alive even if all clients are connected. Keep the
ID of the latest delivered message even for online clients.

As-is, this is a net downgrade: memory usage increases because ring
buffers aren't free'd anymore. However upcoming commits will replace the
ring buffer with log files. This change makes reading from log files
easier.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/upstream.go

    r405 r406  
    16361636        }
    16371637
    1638         // If no client is offline, no need to append the message to the buffer
    1639         if len(uc.network.offlineClients) == 0 && !detached {
    1640                 return
    1641         }
    1642 
    16431638        history, ok := uc.network.history[entity]
    16441639        if !ok {
    16451640                history = &networkHistory{
    1646                         offlineClients: make(map[string]uint64),
    1647                         ring:           NewRing(uc.srv.RingCap),
     1641                        clients: make(map[string]uint64),
     1642                        ring:    NewRing(uc.srv.RingCap),
    16481643                }
    16491644                uc.network.history[entity] = history
    16501645
    16511646                for clientName, _ := range uc.network.offlineClients {
    1652                         history.offlineClients[clientName] = 0
     1647                        history.clients[clientName] = 0
    16531648                }
    16541649
     
    16571652                        // clients too
    16581653                        uc.forEachDownstream(func(dc *downstreamConn) {
    1659                                 history.offlineClients[dc.clientName] = 0
     1654                                history.clients[dc.clientName] = 0
    16601655                        })
    16611656                }
     
    16631658
    16641659        history.ring.Produce(msg)
     1660
     1661        if !detached {
     1662                uc.forEachDownstream(func(dc *downstreamConn) {
     1663                        history.clients[dc.clientName] = history.ring.Cur()
     1664                })
     1665        }
    16651666}
    16661667
Note: See TracChangeset for help on using the changeset viewer.