Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
flike committed Nov 15, 2015
1 parent 361f903 commit 8b35bba
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 269 deletions.
24 changes: 0 additions & 24 deletions mysql/result.go

This file was deleted.

9 changes: 9 additions & 0 deletions mysql/resultset.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ func (p RowData) ParseBinary(f []*Field) ([]interface{}, error) {
return data, nil
}

type Result struct {
Status uint16

InsertId uint64
AffectedRows uint64

*Resultset
}

type Resultset struct {
Fields []*Field
FieldNames map[string]int
Expand Down
221 changes: 0 additions & 221 deletions proxy/router/key.go

This file was deleted.

35 changes: 11 additions & 24 deletions proxy/router/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package router

import (
"bytes"
"encoding/binary"
"fmt"
"hash/crc32"
"strconv"
Expand All @@ -44,6 +46,15 @@ func handleError(err *error) {
}
}

// Uint64Key is a uint64 that can be converted into a KeyspaceId.
type Uint64Key uint64

func (i Uint64Key) String() string {
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, uint64(i))
return buf.String()
}

func EncodeValue(value interface{}) string {
switch val := value.(type) {
case int:
Expand Down Expand Up @@ -144,30 +155,6 @@ func (s *NumRangeShard) EqualStop(key interface{}, index int) bool {
return s.Shards[index].End == v
}

type KeyRangeShard struct {
Shards []KeyRange
}

func (s *KeyRangeShard) FindForKey(key interface{}) (int, error) {
v := KeyspaceId(EncodeValue(key))
for i, r := range s.Shards {
if r.Contains(v) {
return i, nil
}
}

return -1, errors.ErrKeyOutOfRange
}

func (s *KeyRangeShard) EqualStart(key interface{}, index int) bool {
v := KeyspaceId(EncodeValue(key)) //KeyspaceId type is string
return s.Shards[index].Start == v
}
func (s *KeyRangeShard) EqualStop(key interface{}, index int) bool {
v := KeyspaceId(EncodeValue(key))
return s.Shards[index].End == v
}

type DefaultShard struct {
}

Expand Down

0 comments on commit 8b35bba

Please sign in to comment.