mirror of https://github.com/perkeep/perkeep.git
pkg/serverinit: remove reindex parameter to InstallHandlers
Push it down into the index. Change-Id: I327bfcbc314b652d5f24a457e1b62b138a187db5
This commit is contained in:
parent
89ee36e9ec
commit
8e71a705db
|
@ -49,8 +49,8 @@ func init() {
|
|||
|
||||
type Index struct {
|
||||
*blobserver.NoImplStorage
|
||||
|
||||
s sorted.KeyValue
|
||||
reindex bool // whether "reindex" was set in config (likely via perkeepd flag)
|
||||
s sorted.KeyValue
|
||||
|
||||
KeyFetcher blob.Fetcher // for verifying claims
|
||||
|
||||
|
@ -389,6 +389,7 @@ func newFromConfig(ld blobserver.Loader, config jsonconfig.Obj) (blobserver.Stor
|
|||
}
|
||||
ix, err = New(kv)
|
||||
}
|
||||
ix.reindex = reindex
|
||||
if reindex {
|
||||
ix.hasWiped = true
|
||||
}
|
||||
|
@ -441,6 +442,8 @@ func ReindexMaxProcs() int {
|
|||
return reindexMaxProcs.v
|
||||
}
|
||||
|
||||
func (x *Index) WantsReindex() bool { return x.reindex }
|
||||
|
||||
func (x *Index) Reindex() error {
|
||||
x.Lock()
|
||||
if x.blobSource == nil {
|
||||
|
|
|
@ -68,6 +68,7 @@ type handlerConfig struct {
|
|||
settingUp, setupDone bool
|
||||
}
|
||||
|
||||
// handlerLoader implements blobserver.Loader.
|
||||
type handlerLoader struct {
|
||||
installer HandlerInstaller
|
||||
baseURL string
|
||||
|
@ -76,9 +77,10 @@ type handlerLoader struct {
|
|||
curPrefix string
|
||||
closers []io.Closer
|
||||
prefixStack []string
|
||||
reindex bool
|
||||
}
|
||||
|
||||
var _ blobserver.Loader = (*handlerLoader)(nil)
|
||||
|
||||
// A HandlerInstaller is anything that can register an HTTP Handler at
|
||||
// a prefix path. Both *http.ServeMux and perkeep.org/pkg/webserver.Server
|
||||
// implement HandlerInstaller.
|
||||
|
@ -307,18 +309,14 @@ func (hl *handlerLoader) setupHandler(prefix string) {
|
|||
hl.curPrefix = prefix
|
||||
|
||||
if strings.HasPrefix(h.htype, "storage-") {
|
||||
// Assume a storage interface
|
||||
// Assume a storage interface:
|
||||
stype := strings.TrimPrefix(h.htype, "storage-")
|
||||
if h.htype == "storage-index" && hl.reindex {
|
||||
// Let the indexer know that we're in reindex mode
|
||||
h.conf["reindex"] = true
|
||||
}
|
||||
pstorage, err := blobserver.CreateStorage(stype, hl, h.conf)
|
||||
if err != nil {
|
||||
exitFailure("error instantiating storage for prefix %q, type %q: %v",
|
||||
h.prefix, stype, err)
|
||||
}
|
||||
if ix, ok := pstorage.(*index.Index); ok && hl.reindex {
|
||||
if ix, ok := pstorage.(*index.Index); ok && ix.WantsReindex() {
|
||||
log.Printf("Reindexing %s ...", h.prefix)
|
||||
if err := ix.Reindex(); err != nil {
|
||||
exitFailure("Error reindexing %s: %v", h.prefix, err)
|
||||
|
@ -588,6 +586,28 @@ func (c *Config) checkValidAuth() error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (c *Config) SetReindex(v bool) {
|
||||
prefixes, _ := c.jconf["prefixes"].(map[string]interface{})
|
||||
for prefix, vei := range prefixes {
|
||||
if prefix == "_knownkeys" {
|
||||
continue
|
||||
}
|
||||
pmap, ok := vei.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
pconf := jsonconfig.Obj(pmap)
|
||||
typ, _ := pconf["handler"].(string)
|
||||
if typ != "storage-index" {
|
||||
continue
|
||||
}
|
||||
opts, ok := pconf["handlerArgs"].(map[string]interface{})
|
||||
if ok {
|
||||
opts["reindex"] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// InstallHandlers creates and registers all the HTTP Handlers needed
|
||||
// by config into the provided HandlerInstaller and validates that the
|
||||
// configuration is valid.
|
||||
|
@ -596,7 +616,7 @@ func (c *Config) checkValidAuth() error {
|
|||
//
|
||||
// The returned shutdown value can be used to cleanly shut down the
|
||||
// handlers.
|
||||
func (c *Config) InstallHandlers(hi HandlerInstaller, baseURL string, reindex bool) (shutdown io.Closer, err error) {
|
||||
func (c *Config) InstallHandlers(hi HandlerInstaller, baseURL string) (shutdown io.Closer, err error) {
|
||||
config := c
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
|
@ -629,7 +649,6 @@ func (c *Config) InstallHandlers(hi HandlerInstaller, baseURL string, reindex bo
|
|||
baseURL: baseURL,
|
||||
config: make(map[string]*handlerConfig),
|
||||
handler: make(map[string]interface{}),
|
||||
reindex: reindex,
|
||||
}
|
||||
|
||||
for prefix, vei := range prefixes {
|
||||
|
|
|
@ -434,8 +434,10 @@ func Main() {
|
|||
exitf("Error registering challenge client with Perkeep muxer: %v", err)
|
||||
}
|
||||
|
||||
config.SetReindex(*flagReindex)
|
||||
|
||||
// Finally, install the handlers. This also does the final config validation.
|
||||
shutdownCloser, err := config.InstallHandlers(ws, baseURL, *flagReindex)
|
||||
shutdownCloser, err := config.InstallHandlers(ws, baseURL)
|
||||
if err != nil {
|
||||
exitf("Error parsing config: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue