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

namespace isolation: http interface and classifier #747

Merged
merged 23 commits into from
Sep 25, 2017

Conversation

dantin
Copy link
Contributor

@dantin dantin commented Sep 12, 2017

  • Configure namespace related info through pd-ctl/api
  • Add table_namespace_classifier to return namespace name for region/store based on the namespace configuration

@sre-bot
Copy link
Contributor

sre-bot commented Sep 12, 2017

Hi contributor, thanks for your PR.

This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically.

@dantin dantin changed the title [WIP] resource isolation namespace isolation: http interface demo Sep 15, 2017
@ming535 ming535 changed the title namespace isolation: http interface demo namespace isolation: http interface and classifier Sep 19, 2017
"github.com/spf13/cobra"
"net/http"
"strconv"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please 3rd-part packages from standard packages and leave a blank line between them. We prefer the default output of goimports tool.

func NewAppendTableIDCommand() *cobra.Command {
c := &cobra.Command{
Use: "append <name> <table_id>",
Short: "add table id in namespace",
Copy link
Contributor

Choose a reason for hiding this comment

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

in -> to.

return
}
if _, err := strconv.Atoi(args[1]); err != nil {
fmt.Println("table_id shoud be a number")
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove extra space.


// Get list namespace mapping
func (h *namespaceHandler) Get(w http.ResponseWriter, r *http.Request) {
//TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove redundant line.

}
}

// Get list namespace mapping
Copy link
Contributor

Choose a reason for hiding this comment

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

list -> lists.

@@ -0,0 +1,101 @@
// Copyright 2016 PingCAP, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

2016->2017.

func (c tableNamespaceClassifier) GetRegionNamespace(regionInfo *core.RegionInfo) string {
for name, ns := range c.nsInfo.namespaces {
startTable := c.tableIDDecoder.DecodeTableID(regionInfo.StartKey)
endTable := c.tableIDDecoder.DecodeTableID(regionInfo.EndKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

We can move the 2 lines out of for loop. Also we can check if start == end before the loop, if they are not equal, we can return defaultNamespace directly.

}

func (c tableNamespaceClassifier) GetAllNamespaces() []string {
nsList := []string{}
Copy link
Contributor

Choose a reason for hiding this comment

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

nsList := make([]string, 0, len(c.nsInfo.namespaces))

"encoding/binary"
"github.com/juju/errors"
)

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we can add some references to the table codec implementation on tidb.

Copy link
Contributor

Choose a reason for hiding this comment

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

@siddontang any comments on this?

// 1. relation between a name and several tables
// 2. relation between a name and several stores
// It is used to bind tables with stores
type Namespace struct {
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 moving it to server/table_namespace_classifier.go? Since it is only used by server and server/api package.

@ming535 ming535 force-pushed the dantin/namespace branch 2 times, most recently from ede8762 to ae256aa Compare September 20, 2017 10:05
// 1. relation between a Name and several tables
// 2. relation between a Name and several stores
// It is used to bind tables with stores
type Namespace struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seem it is TableNamespace, not a Namespace.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will there be other namespace? How about change table_namespace_classifier.go to namespace_classifier.go?

Copy link
Contributor

Choose a reason for hiding this comment

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

We may have other namespace implementation later. So we can't assume there is only one table namespace.

}
}

func (c tableNamespaceClassifier) GetAllNamespaces() []string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we call this function frequently?
/cc @disksing

Copy link
Contributor

Choose a reason for hiding this comment

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

Now it is called every time we call scheduler.Schedule().

Copy link
Contributor

Choose a reason for hiding this comment

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

Seem this is not effective.


type defaultTableIDDecoder struct{}

var tablePrefix = []byte{'t'}
Copy link
Contributor

Choose a reason for hiding this comment

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

seem we should also consider table index.

@disksing

Copy link
Contributor

Choose a reason for hiding this comment

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

Just table prefix is ok. We have no plan to separate rows and indexes into different namespaces.

* new GetRegionNamespace Method, checking both StartKey and EndKey

* go fmt server/table_namespace_classifier.go

* go fmt server/core/tablecodec.go
@disksing
Copy link
Contributor

LGTM.

@disksing
Copy link
Contributor

PTAL @nolouch @siddontang

Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

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

LGTM

@disksing disksing merged commit d5f6a6f into namespace Sep 25, 2017
@disksing disksing deleted the dantin/namespace branch September 25, 2017 05:28
@sre-bot sre-bot added the contribution Indicates that the PR was contributed by an external member. label Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution Indicates that the PR was contributed by an external member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants