mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-20 11:22:31 -05:00
go/libraries/doltcore/remotesrv: Pass server arguments in ServerArgs struct.
This commit is contained in:
@@ -40,20 +40,20 @@ import (
|
||||
)
|
||||
|
||||
type RemoteChunkStore struct {
|
||||
HttpHost string
|
||||
csCache DBCache
|
||||
bucket string
|
||||
fs filesys.Filesys
|
||||
lgr *logrus.Entry
|
||||
HttpHost string
|
||||
csCache DBCache
|
||||
bucket string
|
||||
fs filesys.Filesys
|
||||
lgr *logrus.Entry
|
||||
remotesapi.UnimplementedChunkStoreServiceServer
|
||||
}
|
||||
|
||||
func NewHttpFSBackedChunkStore(lgr *logrus.Entry, httpHost string, csCache DBCache, fs filesys.Filesys) *RemoteChunkStore {
|
||||
return &RemoteChunkStore{
|
||||
HttpHost: httpHost,
|
||||
csCache: csCache,
|
||||
bucket: "",
|
||||
fs: fs,
|
||||
HttpHost: httpHost,
|
||||
csCache: csCache,
|
||||
bucket: "",
|
||||
fs: fs,
|
||||
lgr: lgr.WithFields(logrus.Fields{
|
||||
"service": "dolt.services.remotesapi.v1alpha1.ChunkStoreServiceServer",
|
||||
}),
|
||||
@@ -246,8 +246,8 @@ func (rs *RemoteChunkStore) getDownloadUrl(logger *logrus.Entry, md metadata.MD,
|
||||
host := rs.getHost(md)
|
||||
return (&url.URL{
|
||||
Scheme: "http",
|
||||
Host: host,
|
||||
Path: path,
|
||||
Host: host,
|
||||
Path: path,
|
||||
}).String(), nil
|
||||
}
|
||||
|
||||
@@ -313,10 +313,10 @@ func (rs *RemoteChunkStore) getUploadUrl(logger *logrus.Entry, md metadata.MD, o
|
||||
params.Add("content_length", strconv.Itoa(int(tfd.ContentLength)))
|
||||
params.Add("content_hash", base64.RawURLEncoding.EncodeToString(tfd.ContentHash))
|
||||
return (&url.URL{
|
||||
Scheme: "http",
|
||||
Host: rs.getHost(md),
|
||||
Path: fmt.Sprintf("%s/%s/%s", org, repoName, fileID),
|
||||
RawQuery: params.Encode(),
|
||||
Scheme: "http",
|
||||
Host: rs.getHost(md),
|
||||
Path: fmt.Sprintf("%s/%s/%s", org, repoName, fileID),
|
||||
RawQuery: params.Encode(),
|
||||
}).String(), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -42,10 +42,10 @@ var (
|
||||
)
|
||||
|
||||
type filehandler struct {
|
||||
dbCache DBCache
|
||||
fs filesys.Filesys
|
||||
readOnly bool
|
||||
lgr *logrus.Entry
|
||||
dbCache DBCache
|
||||
fs filesys.Filesys
|
||||
readOnly bool
|
||||
lgr *logrus.Entry
|
||||
}
|
||||
|
||||
func newFileHandler(lgr *logrus.Entry, dbCache DBCache, fs filesys.Filesys, readOnly bool) filehandler {
|
||||
|
||||
@@ -46,29 +46,43 @@ func (s *Server) GracefulStop() {
|
||||
s.wg.Wait()
|
||||
}
|
||||
|
||||
func NewServer(lgr *logrus.Entry, httpHost string, httpPort, grpcPort int, fs filesys.Filesys, dbCache DBCache, readOnly bool) *Server {
|
||||
type ServerArgs struct {
|
||||
Logger *logrus.Entry
|
||||
HttpHost string
|
||||
HttpPort int
|
||||
GrpcPort int
|
||||
FS filesys.Filesys
|
||||
DBCache DBCache
|
||||
ReadOnly bool
|
||||
}
|
||||
|
||||
func NewServer(args ServerArgs) *Server {
|
||||
if args.Logger == nil {
|
||||
args.Logger = logrus.NewEntry(logrus.StandardLogger())
|
||||
}
|
||||
|
||||
s := new(Server)
|
||||
s.stopChan = make(chan struct{})
|
||||
|
||||
s.wg.Add(2)
|
||||
s.grpcPort = grpcPort
|
||||
s.grpcPort = args.GrpcPort
|
||||
s.grpcSrv = grpc.NewServer(grpc.MaxRecvMsgSize(128 * 1024 * 1024))
|
||||
var chnkSt remotesapi.ChunkStoreServiceServer = NewHttpFSBackedChunkStore(lgr, httpHost, dbCache, fs)
|
||||
if readOnly {
|
||||
var chnkSt remotesapi.ChunkStoreServiceServer = NewHttpFSBackedChunkStore(args.Logger, args.HttpHost, args.DBCache, args.FS)
|
||||
if args.ReadOnly {
|
||||
chnkSt = ReadOnlyChunkStore{chnkSt}
|
||||
}
|
||||
remotesapi.RegisterChunkStoreServiceServer(s.grpcSrv, chnkSt)
|
||||
|
||||
var handler http.Handler = newFileHandler(lgr, dbCache, fs, readOnly)
|
||||
if httpPort == grpcPort {
|
||||
var handler http.Handler = newFileHandler(args.Logger, args.DBCache, args.FS, args.ReadOnly)
|
||||
if args.HttpPort == args.GrpcPort {
|
||||
handler = grpcMultiplexHandler(s.grpcSrv, handler)
|
||||
} else {
|
||||
s.wg.Add(2)
|
||||
}
|
||||
|
||||
s.httpPort = httpPort
|
||||
s.httpPort = args.HttpPort
|
||||
s.httpSrv = http.Server{
|
||||
Addr: fmt.Sprintf(":%d", httpPort),
|
||||
Addr: fmt.Sprintf(":%d", args.HttpPort),
|
||||
Handler: handler,
|
||||
}
|
||||
|
||||
|
||||
@@ -53,5 +53,12 @@ func (s remotesrvStore) Get(org, repo, nbfVerStr string) (remotesrv.RemoteSrvSto
|
||||
|
||||
func NewRemoteSrvServer(lgr *logrus.Entry, ctx *sql.Context, port int) *remotesrv.Server {
|
||||
sess := dsess.DSessFromSess(ctx.Session)
|
||||
return remotesrv.NewServer(lgr, "", port, port, sess.Provider().FileSystem(), remotesrvStore{ctx}, true)
|
||||
return remotesrv.NewServer(remotesrv.ServerArgs{
|
||||
Logger: lgr,
|
||||
HttpPort: port,
|
||||
GrpcPort: port,
|
||||
FS: sess.Provider().FileSystem(),
|
||||
DBCache: remotesrvStore{ctx},
|
||||
ReadOnly: true,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/remotesrv"
|
||||
@@ -82,7 +80,14 @@ func main() {
|
||||
dbCache = NewLocalCSCache(fs)
|
||||
}
|
||||
|
||||
server := remotesrv.NewServer(logrus.NewEntry(logrus.StandardLogger()), *httpHostParam, *httpPortParam, *grpcPortParam, fs, dbCache, *readOnlyParam)
|
||||
server := remotesrv.NewServer(remotesrv.ServerArgs{
|
||||
HttpHost: *httpHostParam,
|
||||
HttpPort: *httpPortParam,
|
||||
GrpcPort: *grpcPortParam,
|
||||
FS: fs,
|
||||
DBCache: dbCache,
|
||||
ReadOnly: *readOnlyParam,
|
||||
})
|
||||
listeners, err := server.Listeners()
|
||||
if err != nil {
|
||||
log.Fatalf("error starting remotesrv Server listeners: %v\n", err)
|
||||
|
||||
Reference in New Issue
Block a user