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 drop distrib in etcd #565

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion coordinator/provider/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
"crypto/tls"
"fmt"
"github.com/pg-sharding/spqr/pkg/models/distributions"
"net"
"time"

"github.com/pg-sharding/spqr/pkg/models/distributions"

"github.com/pg-sharding/spqr/pkg/models/spqrerror"

"github.com/google/uuid"
Expand Down
19 changes: 18 additions & 1 deletion qdb/etcdqdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,13 +919,30 @@ func (q *EtcdQDB) DropDistribution(ctx context.Context, id string) error {
case 0:
return spqrerror.New(spqrerror.SPQR_SHARDING_RULE_ERROR, "no such distribution present in qdb")
case 1:

var distrib *Distribution
if err := json.Unmarshal(resp.Kvs[0].Value, &distrib); err != nil {
return err
}

resp, err := q.cli.Delete(ctx, distributionNodePath(id))

spqrlog.Zero.Debug().
Interface("response", resp).
Msg("etcdqdb: drop distribution")

return err
if err != nil {
return err
}

for _, r := range distrib.Relations {
_, err := q.cli.Delete(ctx, relationMappingNodePath(r.Name))
if err != nil {
return err
}
}

return nil
default:
return spqrerror.Newf(spqrerror.SPQR_SHARDING_RULE_ERROR, "too much distributions matched: %d", len(resp.Kvs))
}
Expand Down
66 changes: 66 additions & 0 deletions test/feature/features/coordinator.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,72 @@ Feature: Coordinator test
"""
Then command return code should be "0"


Scenario: Add/Remove distribution works
When I run SQL on host "coordinator"
"""
CREATE DISTRIBUTION ds1_test COLUMN TYPES integer;
CREATE KEY RANGE krid11 FROM 0 ROUTE TO sh1 FOR DISTRIBUTION ds1_test;
CREATE KEY RANGE krid22 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1_test;
ALTER DISTRIBUTION ds1_test ATTACH RELATION test1 DISTRIBUTION KEY id;
"""
Then command return code should be "0"

When I run SQL on host "coordinator"
"""
SHOW distributions;
"""
Then SQL result should match json
"""
[
{
"Distribution ID":"ds1_test",
"Column types":"integer"
}
]
"""

When I run SQL on host "coordinator"
"""
DROP DISTRIBUTION ds1_test CASCADE
"""
Then command return code should be "0"


When I run SQL on host "coordinator"
"""
SHOW distributions;
"""
Then SQL result should match json
"""
[]
"""

When I run SQL on host "coordinator"
"""
CREATE DISTRIBUTION ds1_test COLUMN TYPES integer;
CREATE KEY RANGE krid11 FROM 0 ROUTE TO sh1 FOR DISTRIBUTION ds1_test;
CREATE KEY RANGE krid22 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1_test;
ALTER DISTRIBUTION ds1_test ATTACH RELATION test1 DISTRIBUTION KEY id;
"""
Then command return code should be "0"


When I run SQL on host "coordinator"
"""
SHOW distributions;
"""
Then SQL result should match json
"""
[
{
"Distribution ID":"ds1_test",
"Column types":"integer"
}
]
"""


Scenario: Add/Remove router works
When I run SQL on host "coordinator"
"""
Expand Down
Loading