Skip to content

Commit

Permalink
Fix drop distrib in etcd (#565)
Browse files Browse the repository at this point in the history
* Fix drop distrib in etcd

* Add feature test scenario
  • Loading branch information
reshke authored Mar 21, 2024
1 parent 0e77564 commit 1f360b1
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
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

0 comments on commit 1f360b1

Please sign in to comment.