go/utils/remotesrv: Through DBCache through to http server so we can use WriteTableFile eventually.

This commit is contained in:
Aaron Son
2022-08-31 14:06:55 -07:00
parent 85a46e39de
commit dd4b3e06dc
2 changed files with 12 additions and 7 deletions

View File

@@ -38,7 +38,11 @@ var (
var expectedFiles = make(map[string]*remotesapi.TableFileDetails)
func ServeHTTP(respWr http.ResponseWriter, req *http.Request) {
type filehandler struct {
dbCache *DBCache
}
func (filehandler) ServeHTTP(respWr http.ResponseWriter, req *http.Request) {
logger := getReqLogger("HTTP_"+req.Method, req.RequestURI)
defer func() { logger("finished") }()

View File

@@ -76,30 +76,31 @@ func waitForSignal() {
}
func startServer(httpHost string, httpPort, grpcPort int) (chan interface{}, *sync.WaitGroup) {
dbCache := NewLocalCSCache(filesys.LocalFS)
wg := sync.WaitGroup{}
stopChan := make(chan interface{})
wg.Add(1)
go func() {
defer wg.Done()
httpServer(httpPort, stopChan)
httpServer(dbCache, httpPort, stopChan)
}()
wg.Add(1)
go func() {
defer wg.Done()
grpcServer(httpHost, grpcPort, stopChan)
grpcServer(httpHost, dbCache, grpcPort, stopChan)
}()
return stopChan, &wg
}
func grpcServer(httpHost string, grpcPort int, stopChan chan interface{}) {
func grpcServer(httpHost string, dbCache *DBCache, grpcPort int, stopChan chan interface{}) {
defer func() {
log.Println("exiting grpc Server go routine")
}()
dbCache := NewLocalCSCache(filesys.LocalFS)
chnkSt := NewHttpFSBackedChunkStore(httpHost, dbCache)
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", grpcPort))
@@ -120,14 +121,14 @@ func grpcServer(httpHost string, grpcPort int, stopChan chan interface{}) {
grpcServer.GracefulStop()
}
func httpServer(httpPort int, stopChan chan interface{}) {
func httpServer(dbCache *DBCache, httpPort int, stopChan chan interface{}) {
defer func() {
log.Println("exiting http Server go routine")
}()
server := http.Server{
Addr: fmt.Sprintf(":%d", httpPort),
Handler: http.HandlerFunc(ServeHTTP),
Handler: filehandler{dbCache},
}
go func() {