Skip to content

Commit

Permalink
add memstore for in memory schema read at schema handler (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jian Shen authored Mar 6, 2020
1 parent 95d3565 commit 42e7331
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
23 changes: 10 additions & 13 deletions api/schema_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package api

import (
"encoding/json"
memCom "github.com/uber/aresdb/memstore/common"
"github.com/uber/aresdb/metastore"
"net/http"

Expand All @@ -30,12 +31,14 @@ import (
type SchemaHandler struct {
// all write requests will go to metaStore.
metaStore metaCom.MetaStore
schemaReader memCom.TableSchemaReader
}

// NewSchemaHandler will create a new SchemaHandler with memStore and metaStore.
func NewSchemaHandler(metaStore metaCom.MetaStore) *SchemaHandler {
func NewSchemaHandler(metaStore metaCom.MetaStore, schemaReader memCom.TableSchemaReader) *SchemaHandler {
return &SchemaHandler{
metaStore: metaStore,
schemaReader: schemaReader,
}
}

Expand Down Expand Up @@ -72,12 +75,8 @@ func (handler *SchemaHandler) ListTables(w *utils.ResponseWriter, r *http.Reques

response := apiCom.NewStringArrayResponse()

tables, err := handler.metaStore.ListTables()
if err != nil {
w.WriteError(err)
return
}
for _, tableName := range tables {
allTables := handler.schemaReader.GetSchemas()
for tableName := range allTables {
response.Body = append(response.Body, tableName)
}

Expand Down Expand Up @@ -106,14 +105,12 @@ func (handler *SchemaHandler) GetTable(w *utils.ResponseWriter, r *http.Request)
return
}

table, err := handler.metaStore.GetTable(getTableRequest.TableName)
schema, err := handler.schemaReader.GetSchema(getTableRequest.TableName)
if err != nil {
if err.Error() == metaCom.ErrTableDoesNotExist.Error() {
w.WriteErrorWithCode(http.StatusNotFound, err)
return
}
w.WriteErrorWithCode(http.StatusNotFound, ErrTableDoesNotExist)
return
}
getTableResponse.JSONBuffer, err = json.Marshal(table)
getTableResponse.JSONBuffer, err = json.Marshal(schema.Schema)
w.WriteJSONBytes(getTableResponse.JSONBuffer, err)
}

Expand Down
2 changes: 1 addition & 1 deletion api/schema_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ = ginkgo.Describe("SchemaHandler", func() {

ginkgo.BeforeEach(func() {
testMemStore = CreateMemStore(&testTableSchema, 0, nil, nil)
schemaHandler = NewSchemaHandler(testMetaStore)
schemaHandler = NewSchemaHandler(testMetaStore, testMemStore)
testRouter := mux.NewRouter()
schemaHandler.Register(testRouter.PathPrefix("/schema").Subrouter())
testServer = httptest.NewUnstartedServer(WithPanicHandling(testRouter))
Expand Down
2 changes: 1 addition & 1 deletion cmd/aresd/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (aresd *AresD) start(cfg common.AresServerConfig, logger common.Logger, que
}

// create schema handler
schemaHandler := api.NewSchemaHandler(metaStore)
schemaHandler := api.NewSchemaHandler(metaStore, memStore)

// create enum handler
enumHandler := api.NewEnumHandler(memStore, metaStore)
Expand Down
2 changes: 1 addition & 1 deletion datanode/datanode.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ func newDatanodeMetrics(scope tally.Scope) datanodeMetrics {
func (d *dataNode) newHandlers() datanodeHandlers {
healthCheckHandler := api.NewHealthCheckHandler()
return datanodeHandlers{
schemaHandler: api.NewSchemaHandler(d.metaStore),
schemaHandler: api.NewSchemaHandler(d.metaStore, d.memStore),
enumHandler: api.NewEnumHandler(d.memStore, d.metaStore),
queryHandler: api.NewQueryHandler(d.memStore, d, d.opts.ServerConfig().Query, d.opts.ServerConfig().HTTP.MaxQueryConnections),
dataHandler: api.NewDataHandler(d.memStore, d.opts.ServerConfig().HTTP.MaxIngestionConnections),
Expand Down

0 comments on commit 42e7331

Please sign in to comment.