Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output fake txn when no entry event comes before a resolved event #83

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cdc/txn/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func CollectRawTxns(
delete(entryGroups, ts)
}
}
// TODO: Handle the case when readyTsList is empty
sort.Slice(readyTxns, func(i, j int) bool {
return readyTxns[i].TS < readyTxns[j].TS
})
Expand All @@ -129,6 +128,14 @@ func CollectRawTxns(
return err
}
}
if len(readyTxns) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about put L131 - L137 after L121

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference?

Copy link
Contributor

@zier-one zier-one Nov 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if readyTxns is empty, we can skip the loop on L126.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But never mind, not a big deal here.

log.Info("Forwarding fake txn", zap.Uint64("ts", resolvedTs))
fakeTxn := RawTxn{
TS: resolvedTs,
Entries: nil,
}
outputFn(ctx, fakeTxn)
}
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions cdc/txn/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,40 @@ func (cs *CollectRawTxnsSuite) TestShouldConsiderSpanResolvedTs(c *check.C) {
c.Assert(string(txn.Entries[2].Key), check.Equals, "key1-3")
}

func (cs *CollectRawTxnsSuite) TestShouldOutputBinlogEvenWhenThereIsNoRealEvent(c *check.C) {
entries := []kv.KvOrResolved{
{Resolved: &kv.ResolvedSpan{Timestamp: 1024}},
{Resolved: &kv.ResolvedSpan{Timestamp: 2000}},
}

cursor := 0
input := func(ctx context.Context) (kv.KvOrResolved, error) {
if cursor >= len(entries) {
return kv.KvOrResolved{}, errors.New("End")
}
e := entries[cursor]
cursor++
return e, nil
}

var rawTxns []RawTxn
output := func(ctx context.Context, txn RawTxn) error {
rawTxns = append(rawTxns, txn)
return nil
}

ctx := context.Background()
tracker := mockTracker{forwarded: []bool{true, true}}
err := CollectRawTxns(ctx, input, output, &tracker)
c.Assert(err, check.ErrorMatches, "End")

c.Assert(rawTxns, check.HasLen, len(entries))
for i, t := range rawTxns {
c.Assert(t.Entries, check.HasLen, 0)
c.Assert(t.TS, check.Equals, entries[i].Resolved.Timestamp)
}
}

type mountTxnsSuite struct{}

var _ = check.Suite(&mountTxnsSuite{})
Expand Down