From 4acc10e6e46ae1f975160432cf51396295d1fbd2 Mon Sep 17 00:00:00 2001 From: mpl Date: Tue, 20 Aug 2013 20:11:37 +0200 Subject: [PATCH] serverconfig: idle synchandler when no localdisk as primary storage Because no localdisk means either s3 or google is the primary, and none of them support efficient replication. 1) Added a dummy synchandler constructor for when config has "idle" 2) Set "idle" for synchandler config when no localdisk 3) fixed corresponding tests Also: - added error (and test) when no localdisk and both s3 and google in config - added s3 + mysql test http://camlistore.org/issue/201 Change-Id: I861fdca0c203bc0181ab6d548adab501ed98d2f0 --- pkg/server/sync.go | 23 ++++ pkg/serverconfig/genconfig.go | 32 +++-- .../testdata/google_nolocaldisk-want.json | 3 +- .../testdata/s3_google_nolocaldisk.err | 1 + .../testdata/s3_google_nolocaldisk.json | 13 ++ .../testdata/s3_nolocaldisk-want.json | 3 +- .../testdata/s3_nolocaldisk_mysql-want.json | 115 ++++++++++++++++++ .../testdata/s3_nolocaldisk_mysql.json | 13 ++ 8 files changed, 194 insertions(+), 9 deletions(-) create mode 100644 pkg/serverconfig/testdata/s3_google_nolocaldisk.err create mode 100644 pkg/serverconfig/testdata/s3_google_nolocaldisk.json create mode 100644 pkg/serverconfig/testdata/s3_nolocaldisk_mysql-want.json create mode 100644 pkg/serverconfig/testdata/s3_nolocaldisk_mysql.json diff --git a/pkg/server/sync.go b/pkg/server/sync.go index 05c893b21..6bdb8ad37 100644 --- a/pkg/server/sync.go +++ b/pkg/server/sync.go @@ -41,6 +41,8 @@ type SyncHandler struct { fromName, fromqName, toName string from, fromq, to blobserver.Storage + idle bool // if true, the handler does nothing other than providing the discovery. + copierPoolSize int lk sync.Mutex // protects following @@ -62,9 +64,17 @@ func newSyncFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handle to := conf.RequiredString("to") fullSync := conf.OptionalBool("fullSyncOnStart", false) blockFullSync := conf.OptionalBool("blockingFullSyncOnStart", false) + idle := conf.OptionalBool("idle", false) if err = conf.Validate(); err != nil { return } + if idle { + synch, err := createIdleSyncHandler(from, to) + if err != nil { + return nil, err + } + return synch, nil + } fromBs, err := ld.GetStorage(from) if err != nil { return @@ -142,6 +152,16 @@ func createSyncHandler(fromName, toName string, from blobserver.StorageQueueCrea return h, nil } +func createIdleSyncHandler(fromName, toName string) (*SyncHandler, error) { + h := &SyncHandler{ + fromName: fromName, + toName: toName, + idle: true, + status: "disabled", + } + return h, nil +} + func (sh *SyncHandler) discoveryMap() map[string]interface{} { // TODO(mpl): more status info return map[string]interface{}{ @@ -156,6 +176,9 @@ func (sh *SyncHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { fmt.Fprintf(rw, "

%s to %s Sync Status

Current status: %s

", sh.fromName, sh.toName, html.EscapeString(sh.status)) + if sh.idle { + return + } fmt.Fprintf(rw, "

Stats: