Gorpc service is now a plugin for vttablet/vtocc

This commit is contained in:
Alain Jobart 2014-01-28 15:30:22 -08:00
Родитель 17074aa41a
Коммит 99dad4d1ff
5 изменённых файлов: 85 добавлений и 34 удалений

Просмотреть файл

@ -0,0 +1,11 @@
// Copyright 2013, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
// Imports and register the gorpc queryservice server
import (
_ "github.com/youtube/vitess/go/vt/tabletserver/gorpcqueryservice"
)

Просмотреть файл

@ -0,0 +1,11 @@
// Copyright 2013, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
// Imports and register the gorpc queryservice server
import (
_ "github.com/youtube/vitess/go/vt/tabletserver/gorpcqueryservice"
)

Просмотреть файл

@ -0,0 +1,54 @@
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gorpcqueryservice
import (
mproto "github.com/youtube/vitess/go/mysql/proto"
"github.com/youtube/vitess/go/rpcwrap"
rpcproto "github.com/youtube/vitess/go/rpcwrap/proto"
"github.com/youtube/vitess/go/vt/tabletserver"
"github.com/youtube/vitess/go/vt/tabletserver/proto"
)
type SqlQuery struct {
server *tabletserver.SqlQuery
}
var sqlQuery *SqlQuery
func (sq *SqlQuery) GetSessionId(sessionParams *proto.SessionParams, sessionInfo *proto.SessionInfo) error {
return sq.server.GetSessionId(sessionParams, sessionInfo)
}
func (sq *SqlQuery) Begin(context *rpcproto.Context, session *proto.Session, txInfo *proto.TransactionInfo) error {
return sq.server.Begin(context, session, txInfo)
}
func (sq *SqlQuery) Commit(context *rpcproto.Context, session *proto.Session, noOutput *string) error {
return sq.server.Commit(context, session, noOutput)
}
func (sq *SqlQuery) Rollback(context *rpcproto.Context, session *proto.Session, noOutput *string) error {
return sq.server.Rollback(context, session, noOutput)
}
func (sq *SqlQuery) Execute(context *rpcproto.Context, query *proto.Query, reply *mproto.QueryResult) error {
return sq.server.Execute(context, query, reply)
}
func (sq *SqlQuery) StreamExecute(context *rpcproto.Context, query *proto.Query, sendReply func(reply interface{}) error) error {
return sq.server.StreamExecute(context, query, sendReply)
}
func (sq *SqlQuery) ExecuteBatch(context *rpcproto.Context, queryList *proto.QueryList, reply *proto.QueryResultList) error {
return sq.server.ExecuteBatch(context, queryList, reply)
}
func init() {
tabletserver.SqlQueryRegisterFunctions = append(tabletserver.SqlQueryRegisterFunctions, func(sq *tabletserver.SqlQuery) {
sqlQuery = &SqlQuery{sq}
rpcwrap.RegisterAuthenticated(sqlQuery)
})
}

Просмотреть файл

@ -1,33 +0,0 @@
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package proto
import (
mproto "github.com/youtube/vitess/go/mysql/proto"
"github.com/youtube/vitess/go/rpcwrap"
rpcproto "github.com/youtube/vitess/go/rpcwrap/proto"
)
// defines the RPC services
// the service name to use is 'SqlQuery'
type SqlQuery interface {
GetSessionId(sessionParams *SessionParams, sessionInfo *SessionInfo) error
// FIXME(sugu) Note the client will support both returning an
// int64 or a structure. Using the structure will be rolled
// out after the client is rolled out.
Begin(context *rpcproto.Context, session *Session, txInfo *TransactionInfo) error
Commit(context *rpcproto.Context, session *Session, noOutput *string) error
Rollback(context *rpcproto.Context, session *Session, noOutput *string) error
Execute(context *rpcproto.Context, query *Query, reply *mproto.QueryResult) error
StreamExecute(context *rpcproto.Context, query *Query, sendReply func(reply interface{}) error) error
ExecuteBatch(context *rpcproto.Context, queryList *QueryList, reply *QueryResultList) error
}
// helper method to register the server (does interface checking)
func RegisterAuthenticated(sqlQuery SqlQuery) {
rpcwrap.RegisterAuthenticated(sqlQuery)
}

Просмотреть файл

@ -127,13 +127,21 @@ var qsConfig Config
var SqlQueryRpcService *SqlQuery
// registration service for all server protocols
type SqlQueryRegisterFunction func(*SqlQuery)
var SqlQueryRegisterFunctions []SqlQueryRegisterFunction
func RegisterQueryService() {
if SqlQueryRpcService != nil {
log.Warningf("RPC service already up %v", SqlQueryRpcService)
return
}
SqlQueryRpcService = NewSqlQuery(qsConfig)
proto.RegisterAuthenticated(SqlQueryRpcService)
for _, f := range SqlQueryRegisterFunctions {
f(SqlQueryRpcService)
}
http.HandleFunc("/debug/health", healthCheck)
}