From 1defe7b297e3620701a889a5f6f14d26ef1118e3 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 28 Nov 2013 11:09:16 -0800 Subject: [PATCH] serverconfig: add 'memoryIndex' bool option to high-level config Change-Id: If5edb272858f186931eeb57579e221bde3efb07c --- pkg/serverconfig/genconfig.go | 31 +++--- pkg/serverconfig/testdata/memindex-want.json | 103 +++++++++++++++++++ pkg/serverconfig/testdata/memindex.json | 11 ++ 3 files changed, 133 insertions(+), 12 deletions(-) create mode 100644 pkg/serverconfig/testdata/memindex-want.json create mode 100644 pkg/serverconfig/testdata/memindex.json diff --git a/pkg/serverconfig/genconfig.go b/pkg/serverconfig/genconfig.go index 46e103066..f00007fdd 100644 --- a/pkg/serverconfig/genconfig.go +++ b/pkg/serverconfig/genconfig.go @@ -46,6 +46,7 @@ type configPrefixesParams struct { searchOwner blob.Ref shareHandlerPath string flickr string + memoryIndex bool } var ( @@ -506,12 +507,16 @@ func genLowLevelPrefixes(params *configPrefixesParams, ownerName string) (m json }, } - m["/my-search/"] = map[string]interface{}{ - "handler": "search", - "handlerArgs": map[string]interface{}{ + searchArgs := map[string]interface{}{ "index": params.indexerPath, "owner": params.searchOwner.String(), - }, + } + if params.memoryIndex { + searchArgs["slurpToMemory"] = true + } + m["/my-search/"] = map[string]interface{}{ + "handler": "search", + "handlerArgs": searchArgs, } } @@ -543,14 +548,15 @@ func genLowLevelConfig(conf *Config) (lowLevelConf *Config, err error) { shareHandlerPath = conf.OptionalString("shareHandlerPath", "") // Index options - runIndex = conf.OptionalBool("runIndex", true) // if false: no search, no UI, etc. - dbname = conf.OptionalString("dbname", "") // for mysql, postgres, mongo - mysql = conf.OptionalString("mysql", "") - postgres = conf.OptionalString("postgres", "") - memIndex = conf.OptionalBool("memIndex", false) - mongo = conf.OptionalString("mongo", "") - sqliteFile = conf.OptionalString("sqlite", "") - kvFile = conf.OptionalString("kvIndexFile", "") + memoryIndex = conf.OptionalBool("memoryIndex", false) + runIndex = conf.OptionalBool("runIndex", true) // if false: no search, no UI, etc. + dbname = conf.OptionalString("dbname", "") // for mysql, postgres, mongo + mysql = conf.OptionalString("mysql", "") + postgres = conf.OptionalString("postgres", "") + memIndex = conf.OptionalBool("memIndex", false) + mongo = conf.OptionalString("mongo", "") + sqliteFile = conf.OptionalString("sqlite", "") + kvFile = conf.OptionalString("kvIndexFile", "") // Importer options flickr = conf.OptionalString("flickr", "") @@ -665,6 +671,7 @@ func genLowLevelConfig(conf *Config) (lowLevelConf *Config, err error) { searchOwner: blob.SHA1FromString(armoredPublicKey), shareHandlerPath: shareHandlerPath, flickr: flickr, + memoryIndex: memoryIndex, } prefixes := genLowLevelPrefixes(prefixesParams, ownerName) diff --git a/pkg/serverconfig/testdata/memindex-want.json b/pkg/serverconfig/testdata/memindex-want.json new file mode 100644 index 000000000..b36211b87 --- /dev/null +++ b/pkg/serverconfig/testdata/memindex-want.json @@ -0,0 +1,103 @@ +{ + "auth": "userpass:camlistore:pass3179", + "https": false, + "listen": "localhost:3179", + "prefixes": { + "/": { + "handler": "root", + "handlerArgs": { + "blobRoot": "/bs-and-maybe-also-index/", + "ownerName": "Alice", + "searchRoot": "/my-search/", + "statusRoot": "/status/", + "stealth": false + } + }, + "/bs-and-index/": { + "handler": "storage-replica", + "handlerArgs": { + "backends": [ + "/bs/", + "/index-kv/" + ] + } + }, + "/bs-and-maybe-also-index/": { + "handler": "storage-cond", + "handlerArgs": { + "read": "/bs/", + "write": { + "else": "/bs/", + "if": "isSchema", + "then": "/bs-and-index/" + } + } + }, + "/bs/": { + "handler": "storage-filesystem", + "handlerArgs": { + "path": "/tmp/blobs" + } + }, + "/cache/": { + "handler": "storage-filesystem", + "handlerArgs": { + "path": "/tmp/blobs/cache" + } + }, + "/index-kv/": { + "handler": "storage-kvfileindexer", + "handlerArgs": { + "blobSource": "/bs/", + "file": "/path/to/indexkv.db" + } + }, + "/my-search/": { + "handler": "search", + "handlerArgs": { + "index": "/index-kv/", + "owner": "sha1-f2b0b7da718b97ce8c31591d8ed4645c777f3ef4", + "slurpToMemory": true + } + }, + "/setup/": { + "handler": "setup" + }, + "/share/": { + "handler": "share", + "handlerArgs": { + "blobRoot": "/bs/" + } + }, + "/sighelper/": { + "handler": "jsonsign", + "handlerArgs": { + "keyId": "26F5ABDA", + "publicKeyDest": "/bs-and-index/", + "secretRing": "/path/to/secring" + } + }, + "/status/": { + "handler": "status" + }, + "/sync/": { + "handler": "sync", + "handlerArgs": { + "from": "/bs/", + "queue": { + "file": "/tmp/blobs/sync-to-index-queue.kv", + "type": "kv" + }, + "to": "/index-kv/" + } + }, + "/ui/": { + "handler": "ui", + "handlerArgs": { + "cache": "/cache/", + "jsonSignRoot": "/sighelper/", + "scaledImage": "lrucache" + } + } + } +} diff --git a/pkg/serverconfig/testdata/memindex.json b/pkg/serverconfig/testdata/memindex.json new file mode 100644 index 000000000..7d8db9fd1 --- /dev/null +++ b/pkg/serverconfig/testdata/memindex.json @@ -0,0 +1,11 @@ +{ + "listen": "localhost:3179", + "auth": "userpass:camlistore:pass3179", + "blobPath": "/tmp/blobs", + "kvIndexFile": "/path/to/indexkv.db", + "memoryIndex": true, + "identity": "26F5ABDA", + "identitySecretRing": "/path/to/secring", + "ownerName": "Alice", + "shareHandlerPath": "/share/" +}