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

fix: escaped sql scripts make database deadlock #954

Merged
merged 9 commits into from
Feb 27, 2023
5 changes: 5 additions & 0 deletions service/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func TestCreateInstance(t *testing.T) {
defer discoverSuit.cleanServiceName(serviceResp.GetName().GetValue(), serviceResp.GetNamespace().GetValue())

t.Run("正常创建实例-服务没有提前创建", func(t *testing.T) {
bc := namingServer.bc
namingServer.bc = nil
defer func() {
namingServer.bc = bc
}()
instanceReq, instanceResp := discoverSuit.createCommonInstance(t, &apiservice.Service{
Name: utils.NewStringValue("test-nocreate-service"),
Namespace: utils.NewStringValue(DefaultNamespace),
Expand Down
3 changes: 0 additions & 3 deletions store/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ type NamespaceStore interface {
// UpdateNamespaceToken Update namespace token
UpdateNamespaceToken(name string, token string) error

// ListNamespaces Query all namespaces under Owner
ListNamespaces(owner string) ([]*model.Namespace, error)

// GetNamespace Get the details of the namespace according to Name
GetNamespace(name string) (*model.Namespace, error)

Expand Down
19 changes: 0 additions & 19 deletions store/boltdb/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,6 @@ func (n *namespaceStore) UpdateNamespaceToken(name string, token string) error {
return n.handler.UpdateValue(tblNameNamespace, name, properties)
}

// ListNamespaces query all namespaces by owner
func (n *namespaceStore) ListNamespaces(owner string) ([]*model.Namespace, error) {
if owner == "" {
return nil, errors.New("store lst namespaces owner is empty")
}
values, err := n.handler.LoadValuesByFilter(
tblNameNamespace, []string{"Owner"}, &model.Namespace{}, func(value map[string]interface{}) bool {
ownerValue, ok := value["Owner"]
if !ok {
return false
}
return strings.Contains(ownerValue.(string), owner)
})
if err != nil {
return nil, err
}
return toNamespaces(values), nil
}

// GetNamespace query namespace by name
func (n *namespaceStore) GetNamespace(name string) (*model.Namespace, error) {
values, err := n.handler.LoadValues(tblNameNamespace, []string{name}, &model.Namespace{})
Expand Down
25 changes: 0 additions & 25 deletions store/boltdb/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,6 @@ func TestNamespaceStore_AddNamespace(t *testing.T) {
}
}

func TestNamespaceStore_ListNamespaces(t *testing.T) {
_ = os.RemoveAll("./table.bolt")
handler, err := NewBoltHandler(&BoltConfig{FileName: "./table.bolt"})
if err != nil {
t.Fatal(err)
}
defer handler.Close()
nsStore := &namespaceStore{handler: handler}

if err := InitNamespaceData(nsStore, nsCount); err != nil {
t.Fatal(err)
}

namespaces, err := nsStore.ListNamespaces(nsOwner)
if err != nil {
t.Fatal(err)
}
for _, namespace := range namespaces {
fmt.Printf("namespace is %+v\n", namespace)
}
if len(namespaces) != nsCount {
t.Fatal(fmt.Sprintf("namespaces count not match, expect %d, got %d", nsCount, len(namespaces)))
}
}

func TestNamespaceStore_GetNamespaces(t *testing.T) {
_ = os.RemoveAll("./table.bolt")
handler, err := NewBoltHandler(&BoltConfig{FileName: "./table.bolt"})
Expand Down
30 changes: 0 additions & 30 deletions store/mock/api_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading