diff options
author | Jakob Borg <jakob@nym.se> | 2014-07-01 13:22:45 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-07-01 17:08:14 +0200 |
commit | 5353659f9fcb840142ba4c8d83f48654d43d4bdc (patch) | |
tree | 46655c6223122c69540d6a53ef9e47944d2c0451 | |
parent | 7ac00e189b8ddaa7654c61becdd1c3391e6df50a (diff) |
Add temporary debug logging for #344 (revert later)
-rw-r--r-- | files/set.go | 5 | ||||
-rw-r--r-- | files/set_debug.go | 51 | ||||
-rw-r--r-- | model/model.go | 3 |
3 files changed, 59 insertions, 0 deletions
diff --git a/files/set.go b/files/set.go index bcb7048dfc..0f0d657f2d 100644 --- a/files/set.go +++ b/files/set.go @@ -49,6 +49,7 @@ func (m *Set) Replace(id uint, fs []scanner.File) { } m.Lock() + log("Replace", id, len(fs)) if len(fs) == 0 || !m.equals(id, fs) { m.changes[id]++ m.replace(id, fs) @@ -65,6 +66,7 @@ func (m *Set) ReplaceWithDelete(id uint, fs []scanner.File) { } m.Lock() + log("ReplaceWithDelete", id, len(fs)) if len(fs) == 0 || !m.equals(id, fs) { m.changes[id]++ @@ -102,7 +104,9 @@ func (m *Set) Update(id uint, fs []scanner.File) { if debug { l.Debugf("Update(%d, [%d])", id, len(fs)) } + m.Lock() + log("Update", id, len(fs)) m.update(id, fs) m.changes[id]++ m.Unlock() @@ -220,6 +224,7 @@ func (m *Set) equals(id uint, fs []scanner.File) bool { func (m *Set) update(cid uint, fs []scanner.File) { remFiles := m.remoteKey[cid] if remFiles == nil { + printLog() l.Fatalln("update before replace for cid", cid) } for _, f := range fs { diff --git a/files/set_debug.go b/files/set_debug.go new file mode 100644 index 0000000000..76dac1e28d --- /dev/null +++ b/files/set_debug.go @@ -0,0 +1,51 @@ +package files + +import ( + "fmt" + "time" + + "github.com/calmh/syncthing/cid" +) + +type logEntry struct { + time time.Time + method string + cid uint + node string + nfiles int +} + +func (l logEntry) String() string { + return fmt.Sprintf("%v: %s cid:%d node:%s nfiles:%d", l.time, l.method, l.cid, l.node, l.nfiles) +} + +var ( + debugLog [10]logEntry + debugNext int + cm *cid.Map +) + +func SetCM(m *cid.Map) { + cm = m +} + +func log(method string, id uint, nfiles int) { + e := logEntry{ + time: time.Now(), + method: method, + cid: id, + nfiles: nfiles, + } + if cm != nil { + e.node = cm.Name(id) + } + debugLog[debugNext] = e + debugNext = (debugNext + 1) % len(debugLog) +} + +func printLog() { + l.Debugln("--- Consistency error ---") + for _, e := range debugLog { + l.Debugln(e) + } +} diff --git a/model/model.go b/model/model.go index a05de8afd9..01519f267e 100644 --- a/model/model.go +++ b/model/model.go @@ -98,6 +98,9 @@ func NewModel(indexDir string, cfg *config.Configuration, clientName, clientVers sup: suppressor{threshold: int64(cfg.Options.MaxChangeKbps)}, } + // TEMP: #344 + files.SetCM(m.cm) + var timeout = 20 * 60 // seconds if t := os.Getenv("STDEADLOCKTIMEOUT"); len(t) > 0 { it, err := strconv.Atoi(t) |