Changeset 406 in code for trunk


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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r404 r406  
    865865                }
    866866
    867                 seq, ok := history.offlineClients[dc.clientName]
     867                seq, ok := history.clients[dc.clientName]
    868868                if !ok {
    869869                        continue
    870870                }
    871                 delete(history.offlineClients, dc.clientName)
    872 
    873                 // If all clients have received history, no need to keep the
    874                 // ring buffer around
    875                 if len(history.offlineClients) == 0 {
    876                         delete(net.history, target)
    877                 }
     871                history.clients[dc.clientName] = history.ring.Cur()
    878872
    879873                consumer := history.ring.NewConsumer(seq)
  • 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
  • trunk/user.go

    r399 r406  
    5252
    5353type networkHistory struct {
    54         offlineClients map[string]uint64 // indexed by client name
    55         ring           *Ring             // can be nil if there are no offline clients
     54        clients map[string]uint64 // indexed by client name
     55        ring    *Ring             // can be nil if there are no offline clients
    5656}
    5757
     
    194194                        net.forEachDownstream(func(dc *downstreamConn) {
    195195                                net.offlineClients[dc.clientName] = struct{}{}
    196                                 if history != nil {
    197                                         history.offlineClients[dc.clientName] = history.ring.Cur()
    198                                 }
    199196
    200197                                dc.SendMessage(&irc.Message{
     
    424421
    425422                                net.offlineClients[dc.clientName] = struct{}{}
    426                                 for target, history := range net.history {
    427                                         if ch, ok := net.channels[target]; ok && ch.Detached {
    428                                                 continue
    429                                         }
    430                                         history.offlineClients[dc.clientName] = history.ring.Cur()
    431                                 }
    432423                        })
    433424
Note: See TracChangeset for help on using the changeset viewer.