Revert "More memory efficient index sending"

This reverts commit 593f098276.
This commit is contained in:
Jakob Borg 2014-05-28 10:11:17 +02:00
parent 593f098276
commit 42ae2898e1

View File

@ -77,7 +77,7 @@ type rawConnection struct {
xw *xdr.Writer xw *xdr.Writer
wmut sync.Mutex wmut sync.Mutex
indexSent map[string]uint64 indexSent map[string]map[string][2]int64
awaiting []chan asyncResult awaiting []chan asyncResult
imut sync.Mutex imut sync.Mutex
@ -117,8 +117,8 @@ func NewConnection(nodeID string, reader io.Reader, writer io.Writer, receiver M
cw: cw, cw: cw,
wb: wb, wb: wb,
xw: xdr.NewWriter(wb), xw: xdr.NewWriter(wb),
indexSent: make(map[string]uint64),
awaiting: make([]chan asyncResult, 0x1000), awaiting: make([]chan asyncResult, 0x1000),
indexSent: make(map[string]map[string][2]int64),
outbox: make(chan []encodable), outbox: make(chan []encodable),
nextID: make(chan int), nextID: make(chan int),
closed: make(chan struct{}), closed: make(chan struct{}),
@ -140,29 +140,26 @@ func (c *rawConnection) ID() string {
func (c *rawConnection) Index(repo string, idx []FileInfo) { func (c *rawConnection) Index(repo string, idx []FileInfo) {
c.imut.Lock() c.imut.Lock()
var msgType int var msgType int
maxSent := c.indexSent[repo] if c.indexSent[repo] == nil {
var newMaxSent uint64
if maxSent == 0 {
// This is the first time we send an index. // This is the first time we send an index.
msgType = messageTypeIndex msgType = messageTypeIndex
c.indexSent[repo] = make(map[string][2]int64)
for _, f := range idx { for _, f := range idx {
if f.Version > newMaxSent { c.indexSent[repo][f.Name] = [2]int64{f.Modified, int64(f.Version)}
newMaxSent = f.Version
}
} }
} else { } else {
// We have sent one full index. Only send updates now. // We have sent one full index. Only send updates now.
msgType = messageTypeIndexUpdate msgType = messageTypeIndexUpdate
var diff []FileInfo var diff []FileInfo
for _, f := range idx { for _, f := range idx {
if f.Version > maxSent { if vs, ok := c.indexSent[repo][f.Name]; !ok || f.Modified != vs[0] || int64(f.Version) != vs[1] {
diff = append(diff, f) diff = append(diff, f)
newMaxSent = f.Version c.indexSent[repo][f.Name] = [2]int64{f.Modified, int64(f.Version)}
} }
} }
idx = diff idx = diff
} }
c.indexSent[repo] = newMaxSent
c.imut.Unlock() c.imut.Unlock()
c.send(header{0, -1, msgType}, IndexMessage{repo, idx}) c.send(header{0, -1, msgType}, IndexMessage{repo, idx})