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

refactor. addkeyrange* -> createkeyrange* #591

Merged
merged 1 commit into from
Apr 2, 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
13 changes: 7 additions & 6 deletions coordinator/provider/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,13 @@ func (qc *qdbCoordinator) watchRouters(ctx context.Context) {
case routerproto.RouterStatus_OPENED:
spqrlog.Zero.Debug().Msg("router is opened")

/* TODO: check router metadata consistency */

/* Mark router as opened in qdb */
err := qc.db.OpenRouter(ctx, internalR.ID)
if err != nil {
return err
}
// TODO: consistency checks
}
return nil
}(); err != nil {
Expand Down Expand Up @@ -423,22 +424,22 @@ func (qc *qdbCoordinator) AddRouter(ctx context.Context, router *topology.Router
}

// TODO : unit tests
func (qc *qdbCoordinator) AddKeyRange(ctx context.Context, keyRange *kr.KeyRange) error {
func (qc *qdbCoordinator) CreateKeyRange(ctx context.Context, keyRange *kr.KeyRange) error {
// add key range to metadb
spqrlog.Zero.Debug().
Bytes("lower-bound", keyRange.LowerBound).
Str("shard-id", keyRange.ShardID).
Str("key-range-id", keyRange.ID).
Msg("add key range")

err := ops.AddKeyRangeWithChecks(ctx, qc.db, keyRange)
err := ops.CreateKeyRangeWithChecks(ctx, qc.db, keyRange)
if err != nil {
return err
}

return qc.traverseRouters(ctx, func(cc *grpc.ClientConn) error {
cl := routerproto.NewKeyRangeServiceClient(cc)
resp, err := cl.AddKeyRange(ctx, &routerproto.AddKeyRangeRequest{
resp, err := cl.CreateKeyRange(ctx, &routerproto.CreateKeyRangeRequest{
KeyRangeInfo: keyRange.ToProto(),
})

Expand Down Expand Up @@ -615,7 +616,7 @@ func (qc *qdbCoordinator) Split(ctx context.Context, req *kr.SplitKeyRange) erro
return err
}

if err := ops.AddKeyRangeWithChecks(ctx, qc.db, krNew); err != nil {
if err := ops.CreateKeyRangeWithChecks(ctx, qc.db, krNew); err != nil {
return spqrerror.Newf(spqrerror.SPQR_KEYRANGE_ERROR, "failed to add a new key range: %s", err.Error())
}

Expand Down Expand Up @@ -926,7 +927,7 @@ func (qc *qdbCoordinator) SyncRouterMetadata(ctx context.Context, qRouter *topol
}

for _, keyRange := range keyRanges {
resp, err := krClient.AddKeyRange(ctx, &routerproto.AddKeyRangeRequest{
resp, err := krClient.CreateKeyRange(ctx, &routerproto.CreateKeyRangeRequest{
KeyRangeInfo: kr.KeyRangeFromDB(keyRange).ToProto(),
})

Expand Down
4 changes: 2 additions & 2 deletions coordinator/provider/keyranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type CoordinatorService struct {
}

// TODO : unit tests
func (c *CoordinatorService) AddKeyRange(ctx context.Context, request *protos.AddKeyRangeRequest) (*protos.ModifyReply, error) {
err := c.impl.AddKeyRange(ctx, kr.KeyRangeFromProto(request.KeyRangeInfo))
func (c *CoordinatorService) CreateKeyRange(ctx context.Context, request *protos.CreateKeyRangeRequest) (*protos.ModifyReply, error) {
err := c.impl.CreateKeyRange(ctx, kr.KeyRangeFromProto(request.KeyRangeInfo))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/clientinteractor/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (pi *PSQLInteractor) KeyRanges(krs []*kr.KeyRange) error {
}

// TODO : unit tests
func (pi *PSQLInteractor) AddKeyRange(ctx context.Context, keyRange *kr.KeyRange) error {
func (pi *PSQLInteractor) CreateKeyRange(ctx context.Context, keyRange *kr.KeyRange) error {
if err := pi.WriteHeader("add key range"); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
Expand Down
5 changes: 3 additions & 2 deletions pkg/coord/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package coord

import (
"context"

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

"github.com/pg-sharding/spqr/pkg/config"
Expand Down Expand Up @@ -90,9 +91,9 @@ func (a *Adapter) ListAllKeyRanges(ctx context.Context) ([]*kr.KeyRange, error)
}

// TODO : unit tests
func (a *Adapter) AddKeyRange(ctx context.Context, kr *kr.KeyRange) error {
func (a *Adapter) CreateKeyRange(ctx context.Context, kr *kr.KeyRange) error {
c := proto.NewKeyRangeServiceClient(a.conn)
_, err := c.AddKeyRange(ctx, &proto.AddKeyRangeRequest{
_, err := c.CreateKeyRange(ctx, &proto.CreateKeyRangeRequest{
KeyRangeInfo: kr.ToProto(),
})
return err
Expand Down
9 changes: 5 additions & 4 deletions pkg/coord/local/clocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package local
import (
"context"
"fmt"
"github.com/pg-sharding/spqr/pkg/models/tasks"
"math/rand"
"sync"

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

"github.com/pg-sharding/spqr/pkg/config"
"github.com/pg-sharding/spqr/pkg/meta"
"github.com/pg-sharding/spqr/pkg/models/datashards"
Expand Down Expand Up @@ -353,7 +354,7 @@ func (qr *LocalCoordinator) Split(ctx context.Context, req *kr.SplitKeyRange) er
return err
}

if err := ops.AddKeyRangeWithChecks(ctx, qr.qdb, krNew); err != nil {
if err := ops.CreateKeyRangeWithChecks(ctx, qr.qdb, krNew); err != nil {
return fmt.Errorf("failed to add a new key range: %w", err)
}

Expand Down Expand Up @@ -447,8 +448,8 @@ func (qr *LocalCoordinator) ListRouters(ctx context.Context) ([]*topology.Router
}}, nil
}

func (qr *LocalCoordinator) AddKeyRange(ctx context.Context, kr *kr.KeyRange) error {
return ops.AddKeyRangeWithChecks(ctx, qr.qdb, kr)
func (qr *LocalCoordinator) CreateKeyRange(ctx context.Context, kr *kr.KeyRange) error {
return ops.CreateKeyRangeWithChecks(ctx, qr.qdb, kr)
}

func (qr *LocalCoordinator) MoveKeyRange(ctx context.Context, kr *kr.KeyRange) error {
Expand Down
5 changes: 3 additions & 2 deletions pkg/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package meta
import (
"context"
"fmt"

"github.com/pg-sharding/spqr/pkg/client"
"github.com/pg-sharding/spqr/pkg/clientinteractor"
"github.com/pg-sharding/spqr/pkg/config"
Expand Down Expand Up @@ -163,11 +164,11 @@ func processCreate(ctx context.Context, astmt spqrparser.Statement, mngr EntityM
return cli.ReportError(spqrerror.ShardingKeysRemoved)
case *spqrparser.KeyRangeDefinition:
req := kr.KeyRangeFromSQL(stmt)
if err := mngr.AddKeyRange(ctx, req); err != nil {
if err := mngr.CreateKeyRange(ctx, req); err != nil {
spqrlog.Zero.Error().Err(err).Msg("Error when adding key range")
return cli.ReportError(err)
}
return cli.AddKeyRange(ctx, req)
return cli.CreateKeyRange(ctx, req)
case *spqrparser.ShardDefinition:
dataShard := datashards.NewDataShard(stmt.Id, &config.Shard{
Hosts: stmt.Hosts,
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/kr/keyrangemgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type KeyRangeMgr interface {
GetKeyRange(ctx context.Context, krId string) (*KeyRange, error)
ListKeyRanges(ctx context.Context, distribution string) ([]*KeyRange, error)
ListAllKeyRanges(ctx context.Context) ([]*KeyRange, error)
AddKeyRange(ctx context.Context, kr *KeyRange) error
CreateKeyRange(ctx context.Context, kr *KeyRange) error
LockKeyRange(ctx context.Context, krid string) (*KeyRange, error)
UnlockKeyRange(ctx context.Context, krid string) error
Split(ctx context.Context, split *SplitKeyRange) error
Expand Down
Loading
Loading