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

Dead code cleanup #14894

Merged
merged 3 commits into from
Jan 5, 2024
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
25 changes: 4 additions & 21 deletions go/mysql/collations/colldata/uca_contraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"math/rand"
"os"
"reflect"
"sort"
"testing"
"unicode/utf8"
Expand All @@ -36,7 +35,6 @@ type CollationWithContractions struct {
Collation Collation
Contractions []uca.Contraction
ContractFast uca.Contractor
ContractTrie uca.Contractor
}

func findContractedCollations(t testing.TB, unique bool) (result []CollationWithContractions) {
Expand All @@ -58,7 +56,7 @@ func findContractedCollations(t testing.TB, unique bool) (result []CollationWith
continue
}

rf, err := os.Open(fmt.Sprintf("testdata/mysqldata/%s.json", collation.Name()))
rf, err := os.Open(fmt.Sprintf("../testdata/mysqldata/%s.json", collation.Name()))
Copy link
Contributor

Choose a reason for hiding this comment

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

was this not working before, or maybe a VTROOT issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was not working before anymore but that was not noticed since there tests only run when you manually generate the collation data.

if err != nil {
t.Skipf("failed to open JSON metadata (%v). did you run colldump?", err)
}
Expand Down Expand Up @@ -91,14 +89,13 @@ func findContractedCollations(t testing.TB, unique bool) (result []CollationWith
Collation: collation,
Contractions: meta.Contractions,
ContractFast: contract,
ContractTrie: uca.NewTrieContractor(meta.Contractions),
})
}
return
}

func testMatch(t *testing.T, name string, cnt uca.Contraction, result []uint16, remainder []byte, skip int) {
assert.True(t, reflect.DeepEqual(cnt.Weights, result), "%s didn't match: expected %#v, got %#v", name, cnt.Weights, result)
assert.Equal(t, result, cnt.Weights, "%s didn't match: expected %#v, got %#v", name, cnt.Weights, result)
assert.Equal(t, 0, len(remainder), "%s bad remainder: %#v", name, remainder)
assert.Equal(t, len(cnt.Path), skip, "%s bad skipped length %d for %#v", name, skip, cnt.Path)

Expand All @@ -112,21 +109,15 @@ func TestUCAContractions(t *testing.T) {
head := cnt.Path[0]
tail := cnt.Path[1]

result := cwc.ContractTrie.FindContextual(head, tail)
testMatch(t, "ContractTrie", cnt, result, nil, 2)

result = cwc.ContractFast.FindContextual(head, tail)
result := cwc.ContractFast.FindContextual(head, tail)
Comment on lines -116 to +112
Copy link
Member

Choose a reason for hiding this comment

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

Why are we removing the testMatch on ContractTrie here?

Copy link
Member

Choose a reason for hiding this comment

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

got my answer below :)

testMatch(t, "ContractFast", cnt, result, nil, 2)
continue
}

head := cnt.Path[0]
tail := string(cnt.Path[1:])

result, remainder, skip := cwc.ContractTrie.Find(charset.Charset_utf8mb4{}, head, []byte(tail))
testMatch(t, "ContractTrie", cnt, result, remainder, skip)

result, remainder, skip = cwc.ContractFast.Find(charset.Charset_utf8mb4{}, head, []byte(tail))
result, remainder, skip := cwc.ContractFast.Find(charset.Charset_utf8mb4{}, head, []byte(tail))
testMatch(t, "ContractFast", cnt, result, remainder, skip)
}
})
Expand Down Expand Up @@ -239,10 +230,6 @@ func BenchmarkUCAContractions(b *testing.B) {
b.Run(fmt.Sprintf("%s-%.02f-fast", cwc.Collation.Name(), frequency), func(b *testing.B) {
benchmarkFind(b, input, cwc.ContractFast)
})

b.Run(fmt.Sprintf("%s-%.02f-trie", cwc.Collation.Name(), frequency), func(b *testing.B) {
benchmarkFind(b, input, cwc.ContractTrie)
})
}
}

Expand All @@ -259,9 +246,5 @@ func BenchmarkUCAContractionsJA(b *testing.B) {
b.Run(fmt.Sprintf("%s-%.02f-fast", cwc.Collation.Name(), frequency), func(b *testing.B) {
benchmarkFindJA(b, input, cwc.ContractFast)
})

b.Run(fmt.Sprintf("%s-%.02f-trie", cwc.Collation.Name(), frequency), func(b *testing.B) {
benchmarkFindJA(b, input, cwc.ContractTrie)
})
}
}
2 changes: 1 addition & 1 deletion go/mysql/collations/colldata/uca_tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func verifyAllCodepoints(t *testing.T, expected map[rune][]uint16, weights uca.W
}

func loadExpectedWeights(t *testing.T, weights string) map[rune][]uint16 {
fullpath := fmt.Sprintf("testdata/mysqldata/%s.json", weights)
fullpath := fmt.Sprintf("../testdata/mysqldata/%s.json", weights)
weightsMysqlFile, err := os.Open(fullpath)
if err != nil {
t.Skipf("failed to load %q (did you run 'colldump' locally?)", fullpath)
Expand Down
84 changes: 0 additions & 84 deletions go/mysql/collations/internal/uca/contractions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,93 +17,9 @@ limitations under the License.
package uca

import (
"fmt"

"vitess.io/vitess/go/mysql/collations/charset"
)

type trie struct {
children map[rune]*trie
weights []uint16
}

func (t *trie) walkCharset(cs charset.Charset, remainder []byte, depth int) ([]uint16, []byte, int) {
if len(remainder) > 0 {
cp, width := cs.DecodeRune(remainder)
if cp == charset.RuneError && width < 3 {
return nil, nil, 0
}
if ch := t.children[cp]; ch != nil {
return ch.walkCharset(cs, remainder[width:], depth+1)
}
}
return t.weights, remainder, depth + 1
}

func (t *trie) insert(path []rune, weights []uint16) {
if len(path) == 0 {
if t.weights != nil {
panic("duplicate contraction")
}
t.weights = weights
return
}

if t.children == nil {
t.children = make(map[rune]*trie)
}
ch := t.children[path[0]]
if ch == nil {
ch = &trie{}
t.children[path[0]] = ch
}
ch.insert(path[1:], weights)
}

type trieContractor struct {
tr trie
}

func (ctr *trieContractor) insert(c *Contraction) {
if len(c.Path) < 2 {
panic("contraction is too short")
}
if len(c.Weights)%3 != 0 {
panic(fmt.Sprintf("weights are not well-formed: %#v has len=%d", c.Weights, len(c.Weights)))
}
if c.Contextual && len(c.Path) != 2 {
panic("contextual contractions can only span 2 codepoints")
}
ctr.tr.insert(c.Path, c.Weights)
}

func (ctr *trieContractor) Find(cs charset.Charset, cp rune, remainder []byte) ([]uint16, []byte, int) {
if tr := ctr.tr.children[cp]; tr != nil {
return tr.walkCharset(cs, remainder, 0)
}
return nil, nil, 0
}

func (ctr *trieContractor) FindContextual(cp, prev rune) []uint16 {
if tr := ctr.tr.children[cp]; tr != nil {
if trc := tr.children[prev]; trc != nil {
return trc.weights
}
}
return nil
}

func NewTrieContractor(all []Contraction) Contractor {
if len(all) == 0 {
return nil
}
ctr := &trieContractor{}
for _, c := range all {
ctr.insert(&c)
}
return ctr
}

type Contraction struct {
Path []rune
Weights []uint16
Expand Down
30 changes: 0 additions & 30 deletions go/mysql/collations/tools/makecolldata/codegen/tablegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,6 @@ func (tg *TableGenerator) entryForCodepoint(codepoint rune) (*page, *entry) {
return page, entry
}

func (tg *TableGenerator) Add900(codepoint rune, rhs [][3]uint16) {
page, entry := tg.entryForCodepoint(codepoint)
page.entryCount++

for i, weights := range rhs {
if i >= uca.MaxCollationElementsPerCodepoint {
break
}
for _, we := range weights {
entry.weights = append(entry.weights, we)
}
}
}

func (tg *TableGenerator) Add(codepoint rune, weights []uint16) {
page, entry := tg.entryForCodepoint(codepoint)
page.entryCount++
Expand All @@ -248,22 +234,6 @@ func (tg *TableGenerator) Add(codepoint rune, weights []uint16) {
entry.weights = append(entry.weights, weights...)
}

func (tg *TableGenerator) AddFromAllkeys(lhs []rune, rhs [][]int, vars []int) {
if len(lhs) > 1 || lhs[0] > tg.maxChar {
// TODO: support contractions
return
}

var weights [][3]uint16
for _, we := range rhs {
if len(we) != 3 {
panic("non-triplet weight in allkeys.txt")
}
weights = append(weights, [3]uint16{uint16(we[0]), uint16(we[1]), uint16(we[2])})
}
tg.Add900(lhs[0], weights)
}

func (tg *TableGenerator) writePage(g *Generator, p *page, layout uca.Layout) string {
var weights []uint16

Expand Down
21 changes: 0 additions & 21 deletions go/vt/logutil/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,6 @@ func (cl *CallbackLogger) Printf(format string, v ...any) {
})
}

// ChannelLogger is a Logger that sends the logging events through a channel for
// consumption.
type ChannelLogger struct {
CallbackLogger
C chan *logutilpb.Event
}

// NewChannelLogger returns a CallbackLogger which will write the data
// on a channel
func NewChannelLogger(size int) *ChannelLogger {
c := make(chan *logutilpb.Event, size)
return &ChannelLogger{
CallbackLogger: CallbackLogger{
f: func(e *logutilpb.Event) {
c <- e
},
},
C: c,
}
}

// MemoryLogger keeps the logging events in memory.
// All protected by a mutex.
type MemoryLogger struct {
Expand Down
37 changes: 4 additions & 33 deletions go/vt/logutil/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,44 +112,15 @@ func TestMemoryLogger(t *testing.T) {
}
}

func TestChannelLogger(t *testing.T) {
cl := NewChannelLogger(10)
cl.Infof("test %v", 123)
cl.Warningf("test %v", 123)
cl.Errorf("test %v", 123)
cl.Printf("test %v", 123)
close(cl.C)

count := 0
for e := range cl.C {
if got, want := e.Value, "test 123"; got != want {
t.Errorf("e.Value = %q, want %q", got, want)
}
if e.File != "logger_test.go" {
t.Errorf("Invalid file name: %v", e.File)
}
count++
}
if got, want := count, 4; got != want {
t.Errorf("count = %v, want %v", got, want)
}
}

func TestTeeLogger(t *testing.T) {
ml := NewMemoryLogger()
cl := NewChannelLogger(10)
tl := NewTeeLogger(ml, cl)
ml1 := NewMemoryLogger()
ml2 := NewMemoryLogger()
tl := NewTeeLogger(ml1, ml2)

tl.Infof("test infof %v %v", 1, 2)
tl.Warningf("test warningf %v %v", 2, 3)
tl.Errorf("test errorf %v %v", 3, 4)
tl.Printf("test printf %v %v", 4, 5)
close(cl.C)

clEvents := []*logutilpb.Event{}
for e := range cl.C {
clEvents = append(clEvents, e)
}

wantEvents := []*logutilpb.Event{
{Level: logutilpb.Level_INFO, Value: "test infof 1 2"},
Expand All @@ -159,7 +130,7 @@ func TestTeeLogger(t *testing.T) {
}
wantFile := "logger_test.go"

for i, events := range [][]*logutilpb.Event{ml.Events, clEvents} {
for i, events := range [][]*logutilpb.Event{ml1.Events, ml2.Events} {
if got, want := len(events), len(wantEvents); got != want {
t.Fatalf("[%v] len(events) = %v, want %v", i, got, want)
}
Expand Down
Loading
Loading