Skip to content

Commit

Permalink
*: fix key prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuyesuifeng committed Dec 8, 2015
1 parent 8f0ff0c commit 44819de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ type Table struct {
writableColumns []*column.Col
indices []*column.IndexedCol
recordPrefix string
encRecordPrefix []byte
indexPrefix string
encIndexPrefix []byte
alloc autoid.Allocator
state model.SchemaState
}
Expand Down Expand Up @@ -101,6 +103,9 @@ func NewTable(tableID int64, tableName string, cols []*column.Col, alloc autoid.
state: model.StatePublic,
}

t.encRecordPrefix, _ = kv.EncodeValue(t.recordPrefix)
t.encIndexPrefix, _ = kv.EncodeValue(t.indexPrefix)

t.publicColumns = t.Cols()
t.writableColumns = t.writableCols()
return t
Expand Down Expand Up @@ -237,20 +242,20 @@ func (t *Table) flatten(data interface{}) (interface{}, error) {

// KeyPrefix implements table.Table KeyPrefix interface.
func (t *Table) KeyPrefix() string {
return t.recordPrefix
return string(t.encRecordPrefix)
}

// IndexPrefix implements table.Table IndexPrefix interface.
func (t *Table) IndexPrefix() string {
return t.indexPrefix
return string(t.encRecordPrefix)
}

// RecordKey implements table.Table RecordKey interface.
func (t *Table) RecordKey(h int64, col *column.Col) []byte {
if col != nil {
return util.EncodeRecordKey(t.KeyPrefix(), h, col.ID)
return util.EncodeRecordKey(t.recordPrefix, h, col.ID)
}
return util.EncodeRecordKey(t.KeyPrefix(), h, 0)
return util.EncodeRecordKey(t.recordPrefix, h, 0)
}

// FirstKey implements table.Table FirstKey interface.
Expand Down
2 changes: 1 addition & 1 deletion util/codec/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const (
encPad = byte(0x0)
)

// Refer: https://github.com/facebook/mysql-5.6/wiki/MyRocks-record-format#memcomparable-format
// EncodeBytes guarantees the encoded value is in ascending order for comparison,
// encoding with the following rule:
// [group1][marker1]...[groupN][markerN]
Expand All @@ -39,6 +38,7 @@ const (
// [1, 2, 3] -> [1 1 2 3 0 0 0 0 0 250]
// [1, 2, 3, 0] -> [1 1 2 3 0 0 0 0 0 251]
// [1, 2, 3, 4, 5, 6, 7, 8] -> [1 1 2 3 4 5 6 7 8 255 0 0 0 0 0 0 0 0 247]
// Refer: https://github.com/facebook/mysql-5.6/wiki/MyRocks-record-format#memcomparable-format
func EncodeBytes(b []byte, data []byte) []byte {
// Allocate more space to avoid unnecessary slice growing.
// Assume that the byte slice size is about 20*8 = 160 bytes.
Expand Down

0 comments on commit 44819de

Please sign in to comment.