Skip to content

Commit

Permalink
tweaks to compare-streams debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Nov 20, 2024
1 parent 06bacb4 commit f229dc0
Showing 1 changed file with 17 additions and 44 deletions.
61 changes: 17 additions & 44 deletions cmd/gosky/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,59 +320,32 @@ var compareStreamsCmd = &cli.Command{
make(chan *comatproto.SyncSubscribeRepos_Commit, 2),
}

buffers := []map[string][]*comatproto.SyncSubscribeRepos_Commit{
make(map[string][]*comatproto.SyncSubscribeRepos_Commit),
make(map[string][]*comatproto.SyncSubscribeRepos_Commit),
buffers := []map[string]string{
make(map[string]string),
make(map[string]string),
}

addToBuffer := func(n int, event *comatproto.SyncSubscribeRepos_Commit) {
buffers[n][event.Repo] = append(buffers[n][event.Repo], event)
buffers[n][event.Repo] = event.Rev
}

pll := func(ll *lexutil.LexLink) string {
if ll == nil {
return "<nil>"
}
return ll.String()
}

findMatchAndRemove := func(n int, event *comatproto.SyncSubscribeRepos_Commit) (*comatproto.SyncSubscribeRepos_Commit, error) {
findMatchAndRemove := func(n int, event *comatproto.SyncSubscribeRepos_Commit) (int, error) {
buf := buffers[n]
slice, ok := buf[event.Repo]
if !ok || len(slice) == 0 {
return nil, nil
lastRevSeen, ok := buf[event.Repo]
if !ok || lastRevSeen == "" {
return 0, nil
}

for i, ev := range slice {
if ev.Commit == event.Commit {
if pll(ev.Prev) != pll(event.Prev) {
// same commit different prev??
return nil, fmt.Errorf("matched event with same commit but different prev: (%d) %d - %d", n, ev.Seq, event.Seq)
}
}

if i != 0 {
fmt.Printf("detected skipped event: %d (%d)\n", slice[0].Seq, i)
}

slice = slice[i+1:]
buf[event.Repo] = slice
return ev, nil
if event.Rev >= lastRevSeen {
delete(buf, event.Repo)
return 1, nil
}

return nil, fmt.Errorf("did not find matching event despite having events in buffer")
return 0, nil
}

printCurrentDelta := func() {
var a, b int
for _, sl := range buffers[0] {
a += len(sl)
}
for _, sl := range buffers[1] {
b += len(sl)
}

fmt.Printf("%d %d\n", a, b)
fmt.Printf("%d %d\n", len(buffers[1]), len(buffers[0]))
}

printDetailedDelta := func() {
Expand Down Expand Up @@ -418,25 +391,25 @@ var compareStreamsCmd = &cli.Command{
for {
select {
case event := <-eventChans[0]:
partner, err := findMatchAndRemove(1, event)
found, err := findMatchAndRemove(1, event)
if err != nil {
fmt.Println("checking for match failed: ", err)
continue
}
if partner == nil {
if found == 0 {
addToBuffer(0, event)
} else {
// the good case
fmt.Println("Match found")
}

case event := <-eventChans[1]:
partner, err := findMatchAndRemove(0, event)
found, err := findMatchAndRemove(0, event)
if err != nil {
fmt.Println("checking for match failed: ", err)
continue
}
if partner == nil {
if found == 0 {
addToBuffer(1, event)
} else {
// the good case
Expand Down

0 comments on commit f229dc0

Please sign in to comment.