-
Notifications
You must be signed in to change notification settings - Fork 726
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
*: fix table namespace classifier. #808
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
11557b2
fix a bug.
disksing a78c8ab
decode key.
disksing 94b5e92
Update codec.go
disksing 03ec9cd
address comment.
disksing f79e4dd
Merge branch 'master' into namespace
disksing 7c9d610
Merge branch 'master' into namespace
ngaut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2017 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package table | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/pingcap/check" | ||
) | ||
|
||
func TestTable(t *testing.T) { | ||
TestingT(t) | ||
} | ||
|
||
var pads = make([]byte, encGroupSize) | ||
|
||
var _ = Suite(&testCodecSuite{}) | ||
|
||
type testCodecSuite struct{} | ||
|
||
func encodeBytes(data []byte) Key { | ||
// Allocate more space to avoid unnecessary slice growing. | ||
// Assume that the byte slice size is about `(len(data) / encGroupSize + 1) * (encGroupSize + 1)` bytes, | ||
// that is `(len(data) / 8 + 1) * 9` in our implement. | ||
dLen := len(data) | ||
result := make([]byte, 0, (dLen/encGroupSize+1)*(encGroupSize+1)) | ||
for idx := 0; idx <= dLen; idx += encGroupSize { | ||
remain := dLen - idx | ||
padCount := 0 | ||
if remain >= encGroupSize { | ||
result = append(result, data[idx:idx+encGroupSize]...) | ||
} else { | ||
padCount = encGroupSize - remain | ||
result = append(result, data[idx:]...) | ||
result = append(result, pads[:padCount]...) | ||
} | ||
|
||
marker := encMarker - byte(padCount) | ||
result = append(result, marker) | ||
} | ||
return result | ||
} | ||
|
||
func (s *testCodecSuite) TestDecodeBytes(c *C) { | ||
key := "abcdefghijklmnopqrstuvwxyz" | ||
for i := 0; i < len(key); i++ { | ||
_, k, err := decodeBytes(encodeBytes([]byte(key[:i]))) | ||
c.Assert(err, IsNil) | ||
c.Assert(string(k), Equals, key[:i]) | ||
} | ||
} | ||
|
||
func (s *testCodecSuite) TestTableID(c *C) { | ||
key := encodeBytes([]byte("t\x80\x00\x00\x00\x00\x00\x00\xff")) | ||
c.Assert(DefaultIDDecoder.DecodeTableID(key), Equals, int64(0xff)) | ||
c.Assert(IsPureTableID(key), IsTrue) | ||
|
||
key = encodeBytes([]byte("t\x80\x00\x00\x00\x00\x00\x00\xff_i\x01\x02")) | ||
c.Assert(DefaultIDDecoder.DecodeTableID(key), Equals, int64(0xff)) | ||
c.Assert(IsPureTableID(key), IsFalse) | ||
|
||
key = []byte("t\x80\x00\x00\x00\x00\x00\x00\xff") | ||
c.Assert(DefaultIDDecoder.DecodeTableID(key), Equals, int64(0)) | ||
|
||
key = encodeBytes([]byte("T\x00\x00\x00\x00\x00\x00\x00\xff")) | ||
c.Assert(DefaultIDDecoder.DecodeTableID(key), Equals, int64(0)) | ||
|
||
key = encodeBytes([]byte("t\x80\x00\x00\x00\x00\x00\xff")) | ||
c.Assert(DefaultIDDecoder.DecodeTableID(key), Equals, int64(0)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,7 @@ func (c *tableNamespaceClassifier) GetAllNamespaces() []string { | |
for name := range c.nsInfo.namespaces { | ||
nsList = append(nsList, name) | ||
} | ||
nsList = append(nsList, namespace.DefaultNamespace) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to check duplicated default here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe forbid creating namespace using |
||
return nsList | ||
} | ||
|
||
|
@@ -213,6 +214,10 @@ func (c *tableNamespaceClassifier) CreateNamespace(name string) error { | |
return errors.New("Name should be 0-9, a-z or A-Z") | ||
} | ||
|
||
if name == namespace.DefaultNamespace { | ||
return errors.Errorf("%s is reserved as default namespace", name) | ||
} | ||
|
||
if n := c.nsInfo.getNamespaceByName(name); n != nil { | ||
return errors.New("Duplicate namespace Name") | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add test