diff --git a/Makefile b/Makefile index bd2891b8f..4c5f35bec 100644 --- a/Makefile +++ b/Makefile @@ -147,18 +147,20 @@ gogen: protos/* mockgen: - mockgen -source=pkg/datatransfers/data_transfers.go -destination=pkg/mock/pgx/mock_pgxconn_iface.go -package=mock - mockgen -source=pkg/datatransfers/pgx_tx_iface.go -destination=pkg/mock/pgx/mock_pgx_tx.go -package=mock + mockgen -source=./pkg/datatransfers/data_transfers.go -destination=./pkg/mock/pgx/mock_pgxconn_iface.go -package=mock + mockgen -source=./pkg/datatransfers/pgx_tx_iface.go -destination=./pkg/mock/pgx/mock_pgx_tx.go -package=mock mockgen -source=./pkg/conn/raw.go -destination=./pkg/mock/conn/raw_mock.go -package=mock - mockgen -source=./router/server/server.go -destination=router/mock/server/mock_server.go -package=mock - mockgen -source=./pkg/conn/instance.go -destination=pkg/mock/conn/mock_instance.go -package=mock - mockgen -source=./pkg/shard/shard.go -destination=pkg/mock/shard/mock_shard.go -package=mock - mockgen -source=./pkg/pool/pool.go -destination=pkg/mock/pool/mock_pool.go -package=mock + mockgen -source=./router/server/server.go -destination=./router/mock/server/mock_server.go -package=mock + mockgen -source=./pkg/conn/instance.go -destination=./pkg/mock/conn/mock_instance.go -package=mock + mockgen -source=./pkg/shard/shard.go -destination=./pkg/mock/shard/mock_shard.go -package=mock + mockgen -source=./pkg/pool/pool.go -destination=./pkg/mock/pool/mock_pool.go -package=mock mockgen -source=./router/client/client.go -destination=./router/mock/client/mock_client.go -package=mock mockgen -source=./router/poolmgr/pool_mgr.go -destination=./router/mock/poolmgr/mock_pool_mgr.go -package=mock mockgen -source=./router/qrouter/qrouter.go -destination=./router/mock/qrouter/mock_qrouter.go -package=mock - mockgen -source=./pkg/clientinteractor/interactor.go -destination=pkg/mock/clientinteractor/mock_interactor.go -package=mock - mockgen -source=qdb/qdb.go -destination=qdb/mock/qdb.go -package=mock + mockgen -source=./pkg/clientinteractor/interactor.go -destination=./pkg/mock/clientinteractor/mock_interactor.go -package=mock + mockgen -source=./qdb/qdb.go -destination=./qdb/mock/mock_qdb.go -package=mock + mockgen -source=./router/relay/relay.go -destination=./router/mock/relay/mock_relay.go -package=mock + mockgen -source=./pkg/meta/meta.go -destination=./pkg/mock/meta/mock_meta.go -package=mock yaccgen: make -C ./yacc/console gen diff --git a/pkg/mock/meta/mock_meta.go b/pkg/mock/meta/mock_meta.go new file mode 100644 index 000000000..360dfef36 --- /dev/null +++ b/pkg/mock/meta/mock_meta.go @@ -0,0 +1,543 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./pkg/meta/meta.go + +// Package mock is a generated GoMock package. +package mock + +import ( + context "context" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + datashards "github.com/pg-sharding/spqr/pkg/models/datashards" + distributions "github.com/pg-sharding/spqr/pkg/models/distributions" + kr "github.com/pg-sharding/spqr/pkg/models/kr" + tasks "github.com/pg-sharding/spqr/pkg/models/tasks" + topology "github.com/pg-sharding/spqr/pkg/models/topology" + qdb "github.com/pg-sharding/spqr/qdb" +) + +// MockEntityMgr is a mock of EntityMgr interface. +type MockEntityMgr struct { + ctrl *gomock.Controller + recorder *MockEntityMgrMockRecorder +} + +// MockEntityMgrMockRecorder is the mock recorder for MockEntityMgr. +type MockEntityMgrMockRecorder struct { + mock *MockEntityMgr +} + +// NewMockEntityMgr creates a new mock instance. +func NewMockEntityMgr(ctrl *gomock.Controller) *MockEntityMgr { + mock := &MockEntityMgr{ctrl: ctrl} + mock.recorder = &MockEntityMgrMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEntityMgr) EXPECT() *MockEntityMgrMockRecorder { + return m.recorder +} + +// AddDataShard mocks base method. +func (m *MockEntityMgr) AddDataShard(ctx context.Context, shard *datashards.DataShard) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddDataShard", ctx, shard) + ret0, _ := ret[0].(error) + return ret0 +} + +// AddDataShard indicates an expected call of AddDataShard. +func (mr *MockEntityMgrMockRecorder) AddDataShard(ctx, shard interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddDataShard", reflect.TypeOf((*MockEntityMgr)(nil).AddDataShard), ctx, shard) +} + +// AddWorldShard mocks base method. +func (m *MockEntityMgr) AddWorldShard(ctx context.Context, shard *datashards.DataShard) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddWorldShard", ctx, shard) + ret0, _ := ret[0].(error) + return ret0 +} + +// AddWorldShard indicates an expected call of AddWorldShard. +func (mr *MockEntityMgrMockRecorder) AddWorldShard(ctx, shard interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddWorldShard", reflect.TypeOf((*MockEntityMgr)(nil).AddWorldShard), ctx, shard) +} + +// AlterDistributionAttach mocks base method. +func (m *MockEntityMgr) AlterDistributionAttach(ctx context.Context, id string, rels []*distributions.DistributedRelation) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AlterDistributionAttach", ctx, id, rels) + ret0, _ := ret[0].(error) + return ret0 +} + +// AlterDistributionAttach indicates an expected call of AlterDistributionAttach. +func (mr *MockEntityMgrMockRecorder) AlterDistributionAttach(ctx, id, rels interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AlterDistributionAttach", reflect.TypeOf((*MockEntityMgr)(nil).AlterDistributionAttach), ctx, id, rels) +} + +// AlterDistributionDetach mocks base method. +func (m *MockEntityMgr) AlterDistributionDetach(ctx context.Context, id, relName string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AlterDistributionDetach", ctx, id, relName) + ret0, _ := ret[0].(error) + return ret0 +} + +// AlterDistributionDetach indicates an expected call of AlterDistributionDetach. +func (mr *MockEntityMgrMockRecorder) AlterDistributionDetach(ctx, id, relName interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AlterDistributionDetach", reflect.TypeOf((*MockEntityMgr)(nil).AlterDistributionDetach), ctx, id, relName) +} + +// CreateDistribution mocks base method. +func (m *MockEntityMgr) CreateDistribution(ctx context.Context, ds *distributions.Distribution) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateDistribution", ctx, ds) + ret0, _ := ret[0].(error) + return ret0 +} + +// CreateDistribution indicates an expected call of CreateDistribution. +func (mr *MockEntityMgrMockRecorder) CreateDistribution(ctx, ds interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateDistribution", reflect.TypeOf((*MockEntityMgr)(nil).CreateDistribution), ctx, ds) +} + +// CreateKeyRange mocks base method. +func (m *MockEntityMgr) CreateKeyRange(ctx context.Context, kr *kr.KeyRange) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateKeyRange", ctx, kr) + ret0, _ := ret[0].(error) + return ret0 +} + +// CreateKeyRange indicates an expected call of CreateKeyRange. +func (mr *MockEntityMgrMockRecorder) CreateKeyRange(ctx, kr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateKeyRange", reflect.TypeOf((*MockEntityMgr)(nil).CreateKeyRange), ctx, kr) +} + +// DropDistribution mocks base method. +func (m *MockEntityMgr) DropDistribution(ctx context.Context, id string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DropDistribution", ctx, id) + ret0, _ := ret[0].(error) + return ret0 +} + +// DropDistribution indicates an expected call of DropDistribution. +func (mr *MockEntityMgrMockRecorder) DropDistribution(ctx, id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DropDistribution", reflect.TypeOf((*MockEntityMgr)(nil).DropDistribution), ctx, id) +} + +// DropKeyRange mocks base method. +func (m *MockEntityMgr) DropKeyRange(ctx context.Context, krid string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DropKeyRange", ctx, krid) + ret0, _ := ret[0].(error) + return ret0 +} + +// DropKeyRange indicates an expected call of DropKeyRange. +func (mr *MockEntityMgrMockRecorder) DropKeyRange(ctx, krid interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DropKeyRange", reflect.TypeOf((*MockEntityMgr)(nil).DropKeyRange), ctx, krid) +} + +// DropKeyRangeAll mocks base method. +func (m *MockEntityMgr) DropKeyRangeAll(ctx context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DropKeyRangeAll", ctx) + ret0, _ := ret[0].(error) + return ret0 +} + +// DropKeyRangeAll indicates an expected call of DropKeyRangeAll. +func (mr *MockEntityMgrMockRecorder) DropKeyRangeAll(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DropKeyRangeAll", reflect.TypeOf((*MockEntityMgr)(nil).DropKeyRangeAll), ctx) +} + +// DropShard mocks base method. +func (m *MockEntityMgr) DropShard(ctx context.Context, id string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DropShard", ctx, id) + ret0, _ := ret[0].(error) + return ret0 +} + +// DropShard indicates an expected call of DropShard. +func (mr *MockEntityMgrMockRecorder) DropShard(ctx, id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DropShard", reflect.TypeOf((*MockEntityMgr)(nil).DropShard), ctx, id) +} + +// GetCoordinator mocks base method. +func (m *MockEntityMgr) GetCoordinator(ctx context.Context) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetCoordinator", ctx) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetCoordinator indicates an expected call of GetCoordinator. +func (mr *MockEntityMgrMockRecorder) GetCoordinator(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCoordinator", reflect.TypeOf((*MockEntityMgr)(nil).GetCoordinator), ctx) +} + +// GetDistribution mocks base method. +func (m *MockEntityMgr) GetDistribution(ctx context.Context, id string) (*distributions.Distribution, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetDistribution", ctx, id) + ret0, _ := ret[0].(*distributions.Distribution) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetDistribution indicates an expected call of GetDistribution. +func (mr *MockEntityMgrMockRecorder) GetDistribution(ctx, id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDistribution", reflect.TypeOf((*MockEntityMgr)(nil).GetDistribution), ctx, id) +} + +// GetKeyRange mocks base method. +func (m *MockEntityMgr) GetKeyRange(ctx context.Context, krId string) (*kr.KeyRange, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetKeyRange", ctx, krId) + ret0, _ := ret[0].(*kr.KeyRange) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetKeyRange indicates an expected call of GetKeyRange. +func (mr *MockEntityMgrMockRecorder) GetKeyRange(ctx, krId interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetKeyRange", reflect.TypeOf((*MockEntityMgr)(nil).GetKeyRange), ctx, krId) +} + +// GetRelationDistribution mocks base method. +func (m *MockEntityMgr) GetRelationDistribution(ctx context.Context, relation_name string) (*distributions.Distribution, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetRelationDistribution", ctx, relation_name) + ret0, _ := ret[0].(*distributions.Distribution) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetRelationDistribution indicates an expected call of GetRelationDistribution. +func (mr *MockEntityMgrMockRecorder) GetRelationDistribution(ctx, relation_name interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRelationDistribution", reflect.TypeOf((*MockEntityMgr)(nil).GetRelationDistribution), ctx, relation_name) +} + +// GetShard mocks base method. +func (m *MockEntityMgr) GetShard(ctx context.Context, shardID string) (*datashards.DataShard, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetShard", ctx, shardID) + ret0, _ := ret[0].(*datashards.DataShard) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetShard indicates an expected call of GetShard. +func (mr *MockEntityMgrMockRecorder) GetShard(ctx, shardID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetShard", reflect.TypeOf((*MockEntityMgr)(nil).GetShard), ctx, shardID) +} + +// GetTaskGroup mocks base method. +func (m *MockEntityMgr) GetTaskGroup(ctx context.Context) (*tasks.TaskGroup, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTaskGroup", ctx) + ret0, _ := ret[0].(*tasks.TaskGroup) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetTaskGroup indicates an expected call of GetTaskGroup. +func (mr *MockEntityMgrMockRecorder) GetTaskGroup(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTaskGroup", reflect.TypeOf((*MockEntityMgr)(nil).GetTaskGroup), ctx) +} + +// ListAllKeyRanges mocks base method. +func (m *MockEntityMgr) ListAllKeyRanges(ctx context.Context) ([]*kr.KeyRange, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListAllKeyRanges", ctx) + ret0, _ := ret[0].([]*kr.KeyRange) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListAllKeyRanges indicates an expected call of ListAllKeyRanges. +func (mr *MockEntityMgrMockRecorder) ListAllKeyRanges(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAllKeyRanges", reflect.TypeOf((*MockEntityMgr)(nil).ListAllKeyRanges), ctx) +} + +// ListDistributions mocks base method. +func (m *MockEntityMgr) ListDistributions(ctx context.Context) ([]*distributions.Distribution, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListDistributions", ctx) + ret0, _ := ret[0].([]*distributions.Distribution) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListDistributions indicates an expected call of ListDistributions. +func (mr *MockEntityMgrMockRecorder) ListDistributions(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListDistributions", reflect.TypeOf((*MockEntityMgr)(nil).ListDistributions), ctx) +} + +// ListKeyRanges mocks base method. +func (m *MockEntityMgr) ListKeyRanges(ctx context.Context, distribution string) ([]*kr.KeyRange, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListKeyRanges", ctx, distribution) + ret0, _ := ret[0].([]*kr.KeyRange) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListKeyRanges indicates an expected call of ListKeyRanges. +func (mr *MockEntityMgrMockRecorder) ListKeyRanges(ctx, distribution interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListKeyRanges", reflect.TypeOf((*MockEntityMgr)(nil).ListKeyRanges), ctx, distribution) +} + +// ListRouters mocks base method. +func (m *MockEntityMgr) ListRouters(ctx context.Context) ([]*topology.Router, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListRouters", ctx) + ret0, _ := ret[0].([]*topology.Router) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListRouters indicates an expected call of ListRouters. +func (mr *MockEntityMgrMockRecorder) ListRouters(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListRouters", reflect.TypeOf((*MockEntityMgr)(nil).ListRouters), ctx) +} + +// ListShards mocks base method. +func (m *MockEntityMgr) ListShards(ctx context.Context) ([]*datashards.DataShard, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ListShards", ctx) + ret0, _ := ret[0].([]*datashards.DataShard) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListShards indicates an expected call of ListShards. +func (mr *MockEntityMgrMockRecorder) ListShards(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListShards", reflect.TypeOf((*MockEntityMgr)(nil).ListShards), ctx) +} + +// LockKeyRange mocks base method. +func (m *MockEntityMgr) LockKeyRange(ctx context.Context, krid string) (*kr.KeyRange, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LockKeyRange", ctx, krid) + ret0, _ := ret[0].(*kr.KeyRange) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LockKeyRange indicates an expected call of LockKeyRange. +func (mr *MockEntityMgrMockRecorder) LockKeyRange(ctx, krid interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LockKeyRange", reflect.TypeOf((*MockEntityMgr)(nil).LockKeyRange), ctx, krid) +} + +// Move mocks base method. +func (m *MockEntityMgr) Move(ctx context.Context, move *kr.MoveKeyRange) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Move", ctx, move) + ret0, _ := ret[0].(error) + return ret0 +} + +// Move indicates an expected call of Move. +func (mr *MockEntityMgrMockRecorder) Move(ctx, move interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Move", reflect.TypeOf((*MockEntityMgr)(nil).Move), ctx, move) +} + +// QDB mocks base method. +func (m *MockEntityMgr) QDB() qdb.QDB { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QDB") + ret0, _ := ret[0].(qdb.QDB) + return ret0 +} + +// QDB indicates an expected call of QDB. +func (mr *MockEntityMgrMockRecorder) QDB() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QDB", reflect.TypeOf((*MockEntityMgr)(nil).QDB)) +} + +// RegisterRouter mocks base method. +func (m *MockEntityMgr) RegisterRouter(ctx context.Context, r *topology.Router) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RegisterRouter", ctx, r) + ret0, _ := ret[0].(error) + return ret0 +} + +// RegisterRouter indicates an expected call of RegisterRouter. +func (mr *MockEntityMgrMockRecorder) RegisterRouter(ctx, r interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterRouter", reflect.TypeOf((*MockEntityMgr)(nil).RegisterRouter), ctx, r) +} + +// RemoveTaskGroup mocks base method. +func (m *MockEntityMgr) RemoveTaskGroup(ctx context.Context) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RemoveTaskGroup", ctx) + ret0, _ := ret[0].(error) + return ret0 +} + +// RemoveTaskGroup indicates an expected call of RemoveTaskGroup. +func (mr *MockEntityMgrMockRecorder) RemoveTaskGroup(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveTaskGroup", reflect.TypeOf((*MockEntityMgr)(nil).RemoveTaskGroup), ctx) +} + +// ShareKeyRange mocks base method. +func (m *MockEntityMgr) ShareKeyRange(id string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ShareKeyRange", id) + ret0, _ := ret[0].(error) + return ret0 +} + +// ShareKeyRange indicates an expected call of ShareKeyRange. +func (mr *MockEntityMgrMockRecorder) ShareKeyRange(id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ShareKeyRange", reflect.TypeOf((*MockEntityMgr)(nil).ShareKeyRange), id) +} + +// Split mocks base method. +func (m *MockEntityMgr) Split(ctx context.Context, split *kr.SplitKeyRange) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Split", ctx, split) + ret0, _ := ret[0].(error) + return ret0 +} + +// Split indicates an expected call of Split. +func (mr *MockEntityMgrMockRecorder) Split(ctx, split interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Split", reflect.TypeOf((*MockEntityMgr)(nil).Split), ctx, split) +} + +// SyncRouterCoordinatorAddress mocks base method. +func (m *MockEntityMgr) SyncRouterCoordinatorAddress(ctx context.Context, router *topology.Router) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SyncRouterCoordinatorAddress", ctx, router) + ret0, _ := ret[0].(error) + return ret0 +} + +// SyncRouterCoordinatorAddress indicates an expected call of SyncRouterCoordinatorAddress. +func (mr *MockEntityMgrMockRecorder) SyncRouterCoordinatorAddress(ctx, router interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SyncRouterCoordinatorAddress", reflect.TypeOf((*MockEntityMgr)(nil).SyncRouterCoordinatorAddress), ctx, router) +} + +// SyncRouterMetadata mocks base method. +func (m *MockEntityMgr) SyncRouterMetadata(ctx context.Context, router *topology.Router) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SyncRouterMetadata", ctx, router) + ret0, _ := ret[0].(error) + return ret0 +} + +// SyncRouterMetadata indicates an expected call of SyncRouterMetadata. +func (mr *MockEntityMgrMockRecorder) SyncRouterMetadata(ctx, router interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SyncRouterMetadata", reflect.TypeOf((*MockEntityMgr)(nil).SyncRouterMetadata), ctx, router) +} + +// Unite mocks base method. +func (m *MockEntityMgr) Unite(ctx context.Context, unite *kr.UniteKeyRange) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Unite", ctx, unite) + ret0, _ := ret[0].(error) + return ret0 +} + +// Unite indicates an expected call of Unite. +func (mr *MockEntityMgrMockRecorder) Unite(ctx, unite interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unite", reflect.TypeOf((*MockEntityMgr)(nil).Unite), ctx, unite) +} + +// UnlockKeyRange mocks base method. +func (m *MockEntityMgr) UnlockKeyRange(ctx context.Context, krid string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnlockKeyRange", ctx, krid) + ret0, _ := ret[0].(error) + return ret0 +} + +// UnlockKeyRange indicates an expected call of UnlockKeyRange. +func (mr *MockEntityMgrMockRecorder) UnlockKeyRange(ctx, krid interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnlockKeyRange", reflect.TypeOf((*MockEntityMgr)(nil).UnlockKeyRange), ctx, krid) +} + +// UnregisterRouter mocks base method. +func (m *MockEntityMgr) UnregisterRouter(ctx context.Context, id string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnregisterRouter", ctx, id) + ret0, _ := ret[0].(error) + return ret0 +} + +// UnregisterRouter indicates an expected call of UnregisterRouter. +func (mr *MockEntityMgrMockRecorder) UnregisterRouter(ctx, id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnregisterRouter", reflect.TypeOf((*MockEntityMgr)(nil).UnregisterRouter), ctx, id) +} + +// UpdateCoordinator mocks base method. +func (m *MockEntityMgr) UpdateCoordinator(ctx context.Context, address string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateCoordinator", ctx, address) + ret0, _ := ret[0].(error) + return ret0 +} + +// UpdateCoordinator indicates an expected call of UpdateCoordinator. +func (mr *MockEntityMgrMockRecorder) UpdateCoordinator(ctx, address interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateCoordinator", reflect.TypeOf((*MockEntityMgr)(nil).UpdateCoordinator), ctx, address) +} + +// WriteTaskGroup mocks base method. +func (m *MockEntityMgr) WriteTaskGroup(ctx context.Context, taskGroup *tasks.TaskGroup) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WriteTaskGroup", ctx, taskGroup) + ret0, _ := ret[0].(error) + return ret0 +} + +// WriteTaskGroup indicates an expected call of WriteTaskGroup. +func (mr *MockEntityMgrMockRecorder) WriteTaskGroup(ctx, taskGroup interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WriteTaskGroup", reflect.TypeOf((*MockEntityMgr)(nil).WriteTaskGroup), ctx, taskGroup) +} diff --git a/pkg/mock/pgx/mock_pgx_tx.go b/pkg/mock/pgx/mock_pgx_tx.go index 7d5f3739d..472991f80 100644 --- a/pkg/mock/pgx/mock_pgx_tx.go +++ b/pkg/mock/pgx/mock_pgx_tx.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: pkg/datatransfers/pgx_tx_iface.go +// Source: ./pkg/datatransfers/pgx_tx_iface.go // Package mock is a generated GoMock package. package mock diff --git a/pkg/mock/pgx/mock_pgxconn_iface.go b/pkg/mock/pgx/mock_pgxconn_iface.go index 1cd437c10..9e6051973 100644 --- a/pkg/mock/pgx/mock_pgxconn_iface.go +++ b/pkg/mock/pgx/mock_pgxconn_iface.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: pkg/datatransfers/data_transfers.go +// Source: ./pkg/datatransfers/data_transfers.go // Package mock is a generated GoMock package. package mock diff --git a/pkg/models/kr/keyrange.go b/pkg/models/kr/keyrange.go index 10a9bf7a9..e20495ff7 100644 --- a/pkg/models/kr/keyrange.go +++ b/pkg/models/kr/keyrange.go @@ -3,6 +3,7 @@ package kr import ( "encoding/binary" "fmt" + "strconv" "strings" "github.com/pg-sharding/spqr/pkg/models/distributions" @@ -93,6 +94,24 @@ func (kr *KeyRange) SendFunc(attribInd int) string { } } +func (kr *KeyRange) RecvFunc(attribInd int, val string) { + switch kr.ColumnTypes[attribInd] { + case qdb.ColumnTypeInteger: + n, _ := strconv.ParseInt(val, 10, 64) + kr.LowerBound[attribInd] = n + case qdb.ColumnTypeVarcharHashed: + fallthrough + case qdb.ColumnTypeUinteger: + /* TODO: fix */ + n, _ := strconv.ParseUint(val, 10, 64) + kr.LowerBound[attribInd] = uint64(n) + case qdb.ColumnTypeVarcharDeprecated: + fallthrough + case qdb.ColumnTypeVarchar: + kr.LowerBound[attribInd] = val + } +} + func (kr *KeyRange) Raw() [][]byte { res := make([][]byte, len(kr.ColumnTypes)) @@ -318,6 +337,22 @@ func KeyRangeFromBytes(val [][]byte, colTypes []string) *KeyRange { return kr } +// Convert key from its string representation +func KeyRangeFromString(val []string, colTypes []string) *KeyRange { + + kr := &KeyRange{ + ColumnTypes: colTypes, + + LowerBound: make(KeyRangeBound, len(colTypes)), + } + + for i := 0; i < len(colTypes); i++ { + kr.RecvFunc(i, val[i]) + } + + return kr +} + // KeyRangeFromProto converts a protobuf KeyRangeInfo to a KeyRange object. // If the input KeyRangeInfo is nil, it returns nil. // Otherwise, it creates a new KeyRange object with the values from the KeyRangeInfo object and returns a pointer to it. diff --git a/qdb/mock/qdb.go b/qdb/mock/mock_qdb.go similarity index 99% rename from qdb/mock/qdb.go rename to qdb/mock/mock_qdb.go index 64ffbb131..7fd7c40cf 100644 --- a/qdb/mock/qdb.go +++ b/qdb/mock/mock_qdb.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: qdb/qdb.go +// Source: ./qdb/qdb.go // Package mock is a generated GoMock package. package mock diff --git a/router/mock/relay/mock_relay.go b/router/mock/relay/mock_relay.go new file mode 100644 index 000000000..26db625f6 --- /dev/null +++ b/router/mock/relay/mock_relay.go @@ -0,0 +1,656 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./router/relay/relay.go + +// Package mock is a generated GoMock package. +package mock + +import ( + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + pgproto3 "github.com/jackc/pgx/v5/pgproto3" + config "github.com/pg-sharding/spqr/pkg/config" + kr "github.com/pg-sharding/spqr/pkg/models/kr" + shard "github.com/pg-sharding/spqr/pkg/shard" + txstatus "github.com/pg-sharding/spqr/pkg/txstatus" + client "github.com/pg-sharding/spqr/router/client" + parser "github.com/pg-sharding/spqr/router/parser" + poolmgr "github.com/pg-sharding/spqr/router/poolmgr" + qrouter "github.com/pg-sharding/spqr/router/qrouter" + routingstate "github.com/pg-sharding/spqr/router/routingstate" + server "github.com/pg-sharding/spqr/router/server" +) + +// MockRelayStateMgr is a mock of RelayStateMgr interface. +type MockRelayStateMgr struct { + ctrl *gomock.Controller + recorder *MockRelayStateMgrMockRecorder +} + +// MockRelayStateMgrMockRecorder is the mock recorder for MockRelayStateMgr. +type MockRelayStateMgrMockRecorder struct { + mock *MockRelayStateMgr +} + +// NewMockRelayStateMgr creates a new mock instance. +func NewMockRelayStateMgr(ctrl *gomock.Controller) *MockRelayStateMgr { + mock := &MockRelayStateMgr{ctrl: ctrl} + mock.recorder = &MockRelayStateMgrMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockRelayStateMgr) EXPECT() *MockRelayStateMgrMockRecorder { + return m.recorder +} + +// ActiveShards mocks base method. +func (m *MockRelayStateMgr) ActiveShards() []kr.ShardKey { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ActiveShards") + ret0, _ := ret[0].([]kr.ShardKey) + return ret0 +} + +// ActiveShards indicates an expected call of ActiveShards. +func (mr *MockRelayStateMgrMockRecorder) ActiveShards() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ActiveShards", reflect.TypeOf((*MockRelayStateMgr)(nil).ActiveShards)) +} + +// ActiveShardsReset mocks base method. +func (m *MockRelayStateMgr) ActiveShardsReset() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "ActiveShardsReset") +} + +// ActiveShardsReset indicates an expected call of ActiveShardsReset. +func (mr *MockRelayStateMgrMockRecorder) ActiveShardsReset() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ActiveShardsReset", reflect.TypeOf((*MockRelayStateMgr)(nil).ActiveShardsReset)) +} + +// AddExtendedProtocMessage mocks base method. +func (m *MockRelayStateMgr) AddExtendedProtocMessage(q pgproto3.FrontendMessage) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddExtendedProtocMessage", q) +} + +// AddExtendedProtocMessage indicates an expected call of AddExtendedProtocMessage. +func (mr *MockRelayStateMgrMockRecorder) AddExtendedProtocMessage(q interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddExtendedProtocMessage", reflect.TypeOf((*MockRelayStateMgr)(nil).AddExtendedProtocMessage), q) +} + +// AddQuery mocks base method. +func (m *MockRelayStateMgr) AddQuery(q pgproto3.FrontendMessage) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddQuery", q) +} + +// AddQuery indicates an expected call of AddQuery. +func (mr *MockRelayStateMgrMockRecorder) AddQuery(q interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddQuery", reflect.TypeOf((*MockRelayStateMgr)(nil).AddQuery), q) +} + +// AddSilentQuery mocks base method. +func (m *MockRelayStateMgr) AddSilentQuery(q pgproto3.FrontendMessage) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "AddSilentQuery", q) +} + +// AddSilentQuery indicates an expected call of AddSilentQuery. +func (mr *MockRelayStateMgrMockRecorder) AddSilentQuery(q interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddSilentQuery", reflect.TypeOf((*MockRelayStateMgr)(nil).AddSilentQuery), q) +} + +// Client mocks base method. +func (m *MockRelayStateMgr) Client() client.RouterClient { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Client") + ret0, _ := ret[0].(client.RouterClient) + return ret0 +} + +// Client indicates an expected call of Client. +func (mr *MockRelayStateMgrMockRecorder) Client() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Client", reflect.TypeOf((*MockRelayStateMgr)(nil).Client)) +} + +// Close mocks base method. +func (m *MockRelayStateMgr) Close() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Close") + ret0, _ := ret[0].(error) + return ret0 +} + +// Close indicates an expected call of Close. +func (mr *MockRelayStateMgrMockRecorder) Close() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockRelayStateMgr)(nil).Close)) +} + +// CompleteRelay mocks base method. +func (m *MockRelayStateMgr) CompleteRelay(replyCl bool) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CompleteRelay", replyCl) + ret0, _ := ret[0].(error) + return ret0 +} + +// CompleteRelay indicates an expected call of CompleteRelay. +func (mr *MockRelayStateMgrMockRecorder) CompleteRelay(replyCl interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CompleteRelay", reflect.TypeOf((*MockRelayStateMgr)(nil).CompleteRelay), replyCl) +} + +// ConnMgr mocks base method. +func (m *MockRelayStateMgr) ConnMgr() poolmgr.PoolMgr { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ConnMgr") + ret0, _ := ret[0].(poolmgr.PoolMgr) + return ret0 +} + +// ConnMgr indicates an expected call of ConnMgr. +func (mr *MockRelayStateMgrMockRecorder) ConnMgr() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConnMgr", reflect.TypeOf((*MockRelayStateMgr)(nil).ConnMgr)) +} + +// CurrentRoutes mocks base method. +func (m *MockRelayStateMgr) CurrentRoutes() []*routingstate.DataShardRoute { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CurrentRoutes") + ret0, _ := ret[0].([]*routingstate.DataShardRoute) + return ret0 +} + +// CurrentRoutes indicates an expected call of CurrentRoutes. +func (mr *MockRelayStateMgrMockRecorder) CurrentRoutes() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CurrentRoutes", reflect.TypeOf((*MockRelayStateMgr)(nil).CurrentRoutes)) +} + +// DataPending mocks base method. +func (m *MockRelayStateMgr) DataPending() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DataPending") + ret0, _ := ret[0].(bool) + return ret0 +} + +// DataPending indicates an expected call of DataPending. +func (mr *MockRelayStateMgrMockRecorder) DataPending() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DataPending", reflect.TypeOf((*MockRelayStateMgr)(nil).DataPending)) +} + +// Flush mocks base method. +func (m *MockRelayStateMgr) Flush() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Flush") +} + +// Flush indicates an expected call of Flush. +func (mr *MockRelayStateMgrMockRecorder) Flush() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Flush", reflect.TypeOf((*MockRelayStateMgr)(nil).Flush)) +} + +// Parse mocks base method. +func (m *MockRelayStateMgr) Parse(query string) (parser.ParseState, string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Parse", query) + ret0, _ := ret[0].(parser.ParseState) + ret1, _ := ret[1].(string) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// Parse indicates an expected call of Parse. +func (mr *MockRelayStateMgrMockRecorder) Parse(query interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Parse", reflect.TypeOf((*MockRelayStateMgr)(nil).Parse), query) +} + +// PgprotoDebug mocks base method. +func (m *MockRelayStateMgr) PgprotoDebug() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PgprotoDebug") + ret0, _ := ret[0].(bool) + return ret0 +} + +// PgprotoDebug indicates an expected call of PgprotoDebug. +func (mr *MockRelayStateMgrMockRecorder) PgprotoDebug() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PgprotoDebug", reflect.TypeOf((*MockRelayStateMgr)(nil).PgprotoDebug)) +} + +// PrepareRelayStep mocks base method. +func (m *MockRelayStateMgr) PrepareRelayStep(cmngr poolmgr.PoolMgr) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PrepareRelayStep", cmngr) + ret0, _ := ret[0].(error) + return ret0 +} + +// PrepareRelayStep indicates an expected call of PrepareRelayStep. +func (mr *MockRelayStateMgrMockRecorder) PrepareRelayStep(cmngr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareRelayStep", reflect.TypeOf((*MockRelayStateMgr)(nil).PrepareRelayStep), cmngr) +} + +// PrepareRelayStepOnAnyRoute mocks base method. +func (m *MockRelayStateMgr) PrepareRelayStepOnAnyRoute(cmngr poolmgr.PoolMgr) (func() error, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PrepareRelayStepOnAnyRoute", cmngr) + ret0, _ := ret[0].(func() error) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PrepareRelayStepOnAnyRoute indicates an expected call of PrepareRelayStepOnAnyRoute. +func (mr *MockRelayStateMgrMockRecorder) PrepareRelayStepOnAnyRoute(cmngr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareRelayStepOnAnyRoute", reflect.TypeOf((*MockRelayStateMgr)(nil).PrepareRelayStepOnAnyRoute), cmngr) +} + +// PrepareRelayStepOnHintRoute mocks base method. +func (m *MockRelayStateMgr) PrepareRelayStepOnHintRoute(cmngr poolmgr.PoolMgr, route *routingstate.DataShardRoute) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PrepareRelayStepOnHintRoute", cmngr, route) + ret0, _ := ret[0].(error) + return ret0 +} + +// PrepareRelayStepOnHintRoute indicates an expected call of PrepareRelayStepOnHintRoute. +func (mr *MockRelayStateMgrMockRecorder) PrepareRelayStepOnHintRoute(cmngr, route interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareRelayStepOnHintRoute", reflect.TypeOf((*MockRelayStateMgr)(nil).PrepareRelayStepOnHintRoute), cmngr, route) +} + +// PrepareStatement mocks base method. +func (m *MockRelayStateMgr) PrepareStatement(hash uint64, d server.PrepStmtDesc) (*shard.PreparedStatementDescriptor, pgproto3.BackendMessage, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PrepareStatement", hash, d) + ret0, _ := ret[0].(*shard.PreparedStatementDescriptor) + ret1, _ := ret[1].(pgproto3.BackendMessage) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// PrepareStatement indicates an expected call of PrepareStatement. +func (mr *MockRelayStateMgrMockRecorder) PrepareStatement(hash, d interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareStatement", reflect.TypeOf((*MockRelayStateMgr)(nil).PrepareStatement), hash, d) +} + +// ProcCommand mocks base method. +func (m *MockRelayStateMgr) ProcCommand(query pgproto3.FrontendMessage, waitForResp, replyCl bool) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProcCommand", query, waitForResp, replyCl) + ret0, _ := ret[0].(error) + return ret0 +} + +// ProcCommand indicates an expected call of ProcCommand. +func (mr *MockRelayStateMgrMockRecorder) ProcCommand(query, waitForResp, replyCl interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProcCommand", reflect.TypeOf((*MockRelayStateMgr)(nil).ProcCommand), query, waitForResp, replyCl) +} + +// ProcCopy mocks base method. +func (m *MockRelayStateMgr) ProcCopy(query pgproto3.FrontendMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProcCopy", query) + ret0, _ := ret[0].(error) + return ret0 +} + +// ProcCopy indicates an expected call of ProcCopy. +func (mr *MockRelayStateMgrMockRecorder) ProcCopy(query interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProcCopy", reflect.TypeOf((*MockRelayStateMgr)(nil).ProcCopy), query) +} + +// ProcCopyComplete mocks base method. +func (m *MockRelayStateMgr) ProcCopyComplete(query *pgproto3.FrontendMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProcCopyComplete", query) + ret0, _ := ret[0].(error) + return ret0 +} + +// ProcCopyComplete indicates an expected call of ProcCopyComplete. +func (mr *MockRelayStateMgrMockRecorder) ProcCopyComplete(query interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProcCopyComplete", reflect.TypeOf((*MockRelayStateMgr)(nil).ProcCopyComplete), query) +} + +// ProcQuery mocks base method. +func (m *MockRelayStateMgr) ProcQuery(query pgproto3.FrontendMessage, waitForResp, replyCl bool) (txstatus.TXStatus, []pgproto3.BackendMessage, bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProcQuery", query, waitForResp, replyCl) + ret0, _ := ret[0].(txstatus.TXStatus) + ret1, _ := ret[1].([]pgproto3.BackendMessage) + ret2, _ := ret[2].(bool) + ret3, _ := ret[3].(error) + return ret0, ret1, ret2, ret3 +} + +// ProcQuery indicates an expected call of ProcQuery. +func (mr *MockRelayStateMgrMockRecorder) ProcQuery(query, waitForResp, replyCl interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProcQuery", reflect.TypeOf((*MockRelayStateMgr)(nil).ProcQuery), query, waitForResp, replyCl) +} + +// ProcessExtendedBuffer mocks base method. +func (m *MockRelayStateMgr) ProcessExtendedBuffer(cmngr poolmgr.PoolMgr) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProcessExtendedBuffer", cmngr) + ret0, _ := ret[0].(error) + return ret0 +} + +// ProcessExtendedBuffer indicates an expected call of ProcessExtendedBuffer. +func (mr *MockRelayStateMgrMockRecorder) ProcessExtendedBuffer(cmngr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProcessExtendedBuffer", reflect.TypeOf((*MockRelayStateMgr)(nil).ProcessExtendedBuffer), cmngr) +} + +// ProcessMessage mocks base method. +func (m *MockRelayStateMgr) ProcessMessage(msg pgproto3.FrontendMessage, waitForResp, replyCl bool, cmngr poolmgr.PoolMgr) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProcessMessage", msg, waitForResp, replyCl, cmngr) + ret0, _ := ret[0].(error) + return ret0 +} + +// ProcessMessage indicates an expected call of ProcessMessage. +func (mr *MockRelayStateMgrMockRecorder) ProcessMessage(msg, waitForResp, replyCl, cmngr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProcessMessage", reflect.TypeOf((*MockRelayStateMgr)(nil).ProcessMessage), msg, waitForResp, replyCl, cmngr) +} + +// ProcessMessageBuf mocks base method. +func (m *MockRelayStateMgr) ProcessMessageBuf(waitForResp, replyCl, completeRelay bool, cmngr poolmgr.PoolMgr) (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ProcessMessageBuf", waitForResp, replyCl, completeRelay, cmngr) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ProcessMessageBuf indicates an expected call of ProcessMessageBuf. +func (mr *MockRelayStateMgrMockRecorder) ProcessMessageBuf(waitForResp, replyCl, completeRelay, cmngr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProcessMessageBuf", reflect.TypeOf((*MockRelayStateMgr)(nil).ProcessMessageBuf), waitForResp, replyCl, completeRelay, cmngr) +} + +// QueryRouter mocks base method. +func (m *MockRelayStateMgr) QueryRouter() qrouter.QueryRouter { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryRouter") + ret0, _ := ret[0].(qrouter.QueryRouter) + return ret0 +} + +// QueryRouter indicates an expected call of QueryRouter. +func (mr *MockRelayStateMgrMockRecorder) QueryRouter() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryRouter", reflect.TypeOf((*MockRelayStateMgr)(nil).QueryRouter)) +} + +// RelayRunCommand mocks base method. +func (m *MockRelayStateMgr) RelayRunCommand(msg pgproto3.FrontendMessage, waitForResp, replyCl bool) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RelayRunCommand", msg, waitForResp, replyCl) + ret0, _ := ret[0].(error) + return ret0 +} + +// RelayRunCommand indicates an expected call of RelayRunCommand. +func (mr *MockRelayStateMgrMockRecorder) RelayRunCommand(msg, waitForResp, replyCl interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RelayRunCommand", reflect.TypeOf((*MockRelayStateMgr)(nil).RelayRunCommand), msg, waitForResp, replyCl) +} + +// RelayStep mocks base method. +func (m *MockRelayStateMgr) RelayStep(msg pgproto3.FrontendMessage, waitForResp, replyCl bool) (txstatus.TXStatus, []pgproto3.BackendMessage, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RelayStep", msg, waitForResp, replyCl) + ret0, _ := ret[0].(txstatus.TXStatus) + ret1, _ := ret[1].([]pgproto3.BackendMessage) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// RelayStep indicates an expected call of RelayStep. +func (mr *MockRelayStateMgrMockRecorder) RelayStep(msg, waitForResp, replyCl interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RelayStep", reflect.TypeOf((*MockRelayStateMgr)(nil).RelayStep), msg, waitForResp, replyCl) +} + +// RequestData mocks base method. +func (m *MockRelayStateMgr) RequestData() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RequestData") +} + +// RequestData indicates an expected call of RequestData. +func (mr *MockRelayStateMgrMockRecorder) RequestData() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RequestData", reflect.TypeOf((*MockRelayStateMgr)(nil).RequestData)) +} + +// Reroute mocks base method. +func (m *MockRelayStateMgr) Reroute() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Reroute") + ret0, _ := ret[0].(error) + return ret0 +} + +// Reroute indicates an expected call of Reroute. +func (mr *MockRelayStateMgrMockRecorder) Reroute() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reroute", reflect.TypeOf((*MockRelayStateMgr)(nil).Reroute)) +} + +// RerouteToRandomRoute mocks base method. +func (m *MockRelayStateMgr) RerouteToRandomRoute() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RerouteToRandomRoute") + ret0, _ := ret[0].(error) + return ret0 +} + +// RerouteToRandomRoute indicates an expected call of RerouteToRandomRoute. +func (mr *MockRelayStateMgrMockRecorder) RerouteToRandomRoute() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RerouteToRandomRoute", reflect.TypeOf((*MockRelayStateMgr)(nil).RerouteToRandomRoute)) +} + +// RerouteToTargetRoute mocks base method. +func (m *MockRelayStateMgr) RerouteToTargetRoute(route *routingstate.DataShardRoute) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RerouteToTargetRoute", route) + ret0, _ := ret[0].(error) + return ret0 +} + +// RerouteToTargetRoute indicates an expected call of RerouteToTargetRoute. +func (mr *MockRelayStateMgrMockRecorder) RerouteToTargetRoute(route interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RerouteToTargetRoute", reflect.TypeOf((*MockRelayStateMgr)(nil).RerouteToTargetRoute), route) +} + +// Reset mocks base method. +func (m *MockRelayStateMgr) Reset() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Reset") + ret0, _ := ret[0].(error) + return ret0 +} + +// Reset indicates an expected call of Reset. +func (mr *MockRelayStateMgrMockRecorder) Reset() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reset", reflect.TypeOf((*MockRelayStateMgr)(nil).Reset)) +} + +// RouterMode mocks base method. +func (m *MockRelayStateMgr) RouterMode() config.RouterMode { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "RouterMode") + ret0, _ := ret[0].(config.RouterMode) + return ret0 +} + +// RouterMode indicates an expected call of RouterMode. +func (mr *MockRelayStateMgrMockRecorder) RouterMode() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouterMode", reflect.TypeOf((*MockRelayStateMgr)(nil).RouterMode)) +} + +// SetTxStatus mocks base method. +func (m *MockRelayStateMgr) SetTxStatus(status txstatus.TXStatus) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetTxStatus", status) +} + +// SetTxStatus indicates an expected call of SetTxStatus. +func (mr *MockRelayStateMgrMockRecorder) SetTxStatus(status interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTxStatus", reflect.TypeOf((*MockRelayStateMgr)(nil).SetTxStatus), status) +} + +// ShouldRetry mocks base method. +func (m *MockRelayStateMgr) ShouldRetry(err error) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ShouldRetry", err) + ret0, _ := ret[0].(bool) + return ret0 +} + +// ShouldRetry indicates an expected call of ShouldRetry. +func (mr *MockRelayStateMgrMockRecorder) ShouldRetry(err interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ShouldRetry", reflect.TypeOf((*MockRelayStateMgr)(nil).ShouldRetry), err) +} + +// StartTrace mocks base method. +func (m *MockRelayStateMgr) StartTrace() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "StartTrace") +} + +// StartTrace indicates an expected call of StartTrace. +func (mr *MockRelayStateMgrMockRecorder) StartTrace() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartTrace", reflect.TypeOf((*MockRelayStateMgr)(nil).StartTrace)) +} + +// Sync mocks base method. +func (m *MockRelayStateMgr) Sync(waitForResp, replyCl bool, cmngr poolmgr.PoolMgr) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Sync", waitForResp, replyCl, cmngr) + ret0, _ := ret[0].(error) + return ret0 +} + +// Sync indicates an expected call of Sync. +func (mr *MockRelayStateMgrMockRecorder) Sync(waitForResp, replyCl, cmngr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sync", reflect.TypeOf((*MockRelayStateMgr)(nil).Sync), waitForResp, replyCl, cmngr) +} + +// SyncCount mocks base method. +func (m *MockRelayStateMgr) SyncCount() int64 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SyncCount") + ret0, _ := ret[0].(int64) + return ret0 +} + +// SyncCount indicates an expected call of SyncCount. +func (mr *MockRelayStateMgrMockRecorder) SyncCount() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SyncCount", reflect.TypeOf((*MockRelayStateMgr)(nil).SyncCount)) +} + +// TxActive mocks base method. +func (m *MockRelayStateMgr) TxActive() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TxActive") + ret0, _ := ret[0].(bool) + return ret0 +} + +// TxActive indicates an expected call of TxActive. +func (mr *MockRelayStateMgrMockRecorder) TxActive() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TxActive", reflect.TypeOf((*MockRelayStateMgr)(nil).TxActive)) +} + +// TxStatus mocks base method. +func (m *MockRelayStateMgr) TxStatus() txstatus.TXStatus { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TxStatus") + ret0, _ := ret[0].(txstatus.TXStatus) + return ret0 +} + +// TxStatus indicates an expected call of TxStatus. +func (mr *MockRelayStateMgrMockRecorder) TxStatus() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TxStatus", reflect.TypeOf((*MockRelayStateMgr)(nil).TxStatus)) +} + +// UnRouteWithError mocks base method. +func (m *MockRelayStateMgr) UnRouteWithError(shkey []kr.ShardKey, errmsg error) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnRouteWithError", shkey, errmsg) + ret0, _ := ret[0].(error) + return ret0 +} + +// UnRouteWithError indicates an expected call of UnRouteWithError. +func (mr *MockRelayStateMgrMockRecorder) UnRouteWithError(shkey, errmsg interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnRouteWithError", reflect.TypeOf((*MockRelayStateMgr)(nil).UnRouteWithError), shkey, errmsg) +} + +// Unroute mocks base method. +func (m *MockRelayStateMgr) Unroute(shkey []kr.ShardKey) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Unroute", shkey) + ret0, _ := ret[0].(error) + return ret0 +} + +// Unroute indicates an expected call of Unroute. +func (mr *MockRelayStateMgrMockRecorder) Unroute(shkey interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Unroute", reflect.TypeOf((*MockRelayStateMgr)(nil).Unroute), shkey) +} + +// UnrouteRoutes mocks base method. +func (m *MockRelayStateMgr) UnrouteRoutes(routes []*routingstate.DataShardRoute) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UnrouteRoutes", routes) + ret0, _ := ret[0].(error) + return ret0 +} + +// UnrouteRoutes indicates an expected call of UnrouteRoutes. +func (mr *MockRelayStateMgrMockRecorder) UnrouteRoutes(routes interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnrouteRoutes", reflect.TypeOf((*MockRelayStateMgr)(nil).UnrouteRoutes), routes) +} diff --git a/router/relay/qstate.go b/router/relay/qstate.go index 81b65ccab..8e63d82e6 100644 --- a/router/relay/qstate.go +++ b/router/relay/qstate.go @@ -9,6 +9,7 @@ import ( "github.com/jackc/pgx/v5/pgproto3" "github.com/pg-sharding/lyx/lyx" "github.com/pg-sharding/spqr/pkg/config" + "github.com/pg-sharding/spqr/pkg/models/kr" "github.com/pg-sharding/spqr/pkg/models/spqrerror" "github.com/pg-sharding/spqr/pkg/session" "github.com/pg-sharding/spqr/pkg/spqrlog" @@ -23,27 +24,40 @@ func AdvancedPoolModeNeeded(rst RelayStateMgr) bool { return rst.Client().Rule().PoolMode == config.PoolModeTransaction && rst.Client().Rule().PoolPreparedStatement || rst.RouterMode() == config.ProxyMode } +func DeparseRouteHintBound(ctx context.Context, + rst RelayStateMgr, params map[string]string, val string, dsId string) ([]interface{}, error) { + spqrlog.Zero.Debug().Str("sharding key", val).Msg("checking hint key") + + distr, err := rst.QueryRouter().Mgr().GetDistribution(ctx, dsId) + if err != nil { + return nil, err + } + + // TODO: fix this naming. + + return kr.KeyRangeFromString([]string{val}, distr.ColTypes).LowerBound, nil +} + func deparseRouteHint(rst RelayStateMgr, params map[string]string) (routehint.RouteHint, error) { if _, ok := params[session.SPQR_SCATTER_QUERY]; ok { return &routehint.ScatterRouteHint{}, nil } if val, ok := params[session.SPQR_SHARDING_KEY]; ok { - spqrlog.Zero.Debug().Str("sharding key", val).Msg("checking hint key") + ctx := context.TODO() dsId := "" + var ok bool if dsId, ok = params[session.SPQR_DISTRIBUTION]; !ok { return nil, spqrerror.New(spqrerror.SPQR_NO_DISTRIBUTION, "got sharding key in comment without distribution") } - - ctx := context.TODO() - krs, err := rst.QueryRouter().Mgr().ListKeyRanges(ctx, dsId) + compositeKey, err := DeparseRouteHintBound(ctx, rst, params, val, dsId) if err != nil { return nil, err } - // TODO: fix this - compositeKey := []interface{}{ - val, + krs, err := rst.QueryRouter().Mgr().ListKeyRanges(ctx, dsId) + if err != nil { + return nil, err } ds, err := rst.QueryRouter().DeparseKeyWithRangesInternal(context.TODO(), compositeKey, krs) diff --git a/router/relay/qstate_test.go b/router/relay/qstate_test.go new file mode 100644 index 000000000..f718a02f8 --- /dev/null +++ b/router/relay/qstate_test.go @@ -0,0 +1,50 @@ +package relay_test + +import ( + "context" + "testing" + + "github.com/golang/mock/gomock" + meta_mock "github.com/pg-sharding/spqr/pkg/mock/meta" + "github.com/pg-sharding/spqr/pkg/models/distributions" + "github.com/pg-sharding/spqr/qdb" + mockqr "github.com/pg-sharding/spqr/router/mock/qrouter" + relay_mock "github.com/pg-sharding/spqr/router/mock/relay" + "github.com/pg-sharding/spqr/router/relay" + "github.com/stretchr/testify/assert" +) + +func TestRoutingHint(t *testing.T) { + + assert := assert.New(t) + + ctx := context.TODO() + + ctrl := gomock.NewController(t) + rst := relay_mock.NewMockRelayStateMgr(ctrl) + + qr := mockqr.NewMockQueryRouter(ctrl) + + rst.EXPECT().QueryRouter().Return(qr) + + emgr := meta_mock.NewMockEntityMgr(ctrl) + + qr.EXPECT().Mgr().Return(emgr) + + dsId := "ds1" + + ds := &distributions.Distribution{ + Id: dsId, + ColTypes: []string{ + qdb.ColumnTypeInteger, + }, + } + + emgr.EXPECT().GetDistribution(gomock.Any(), dsId).Return(ds, nil) + + bnd, err := relay.DeparseRouteHintBound(ctx, rst, map[string]string{}, "30", dsId) + + assert.Equal(bnd, []interface{}{int64(30)}) + + assert.NoError(err) +} diff --git a/test/regress/tests/router/expected/routing_hint.out b/test/regress/tests/router/expected/routing_hint.out index 87036d2a4..8f5a29861 100644 --- a/test/regress/tests/router/expected/routing_hint.out +++ b/test/regress/tests/router/expected/routing_hint.out @@ -36,11 +36,11 @@ CREATE TABLE test(id int, age int); NOTICE: send query to shard(s) : sh1,sh2 -- TODO: specify distribution as well as sharding_key INSERT INTO test(id, age) VALUES (1210, 16) /*__spqr__sharding_key: 1, __spqr__distribution: ds1 */; -NOTICE: send query to shard(s) : sh1 -INSERT INTO test(id, age) VALUES (10, 16) /*__spqr__sharding_key: 30, __spqr__distribution: ds1 */; NOTICE: send query to shard(s) : sh2 +INSERT INTO test(id, age) VALUES (10, 16) /*__spqr__sharding_key: 30, __spqr__distribution: ds1 */; +NOTICE: send query to shard(s) : sh1 INSERT INTO test(id, age) VALUES (10, 16) /*__spqr__sharding_key: 3000, __spqr__distribution: ds1 */; -NOTICE: send query to shard(s) : sh2 +NOTICE: send query to shard(s) : sh1 DROP TABLE test; NOTICE: send query to shard(s) : sh1,sh2 \c spqr-console