2011-05-09 13:05:58 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-12-04 22:35:26 +00:00
|
|
|
package server
|
2011-05-09 13:05:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2011-05-11 14:07:31 +00:00
|
|
|
"html"
|
2011-05-09 13:05:58 +00:00
|
|
|
"log"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"net/http"
|
2011-05-09 18:08:14 +00:00
|
|
|
"strings"
|
2011-05-11 14:07:31 +00:00
|
|
|
"sync"
|
|
|
|
"time"
|
2011-05-09 13:05:58 +00:00
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
"camlistore.org/pkg/blob"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"camlistore.org/pkg/blobserver"
|
|
|
|
"camlistore.org/pkg/jsonconfig"
|
2013-07-08 04:12:18 +00:00
|
|
|
"camlistore.org/pkg/readerutil"
|
2011-05-09 13:05:58 +00:00
|
|
|
)
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
var queueSyncInterval = 5 * time.Second
|
2012-11-07 17:49:14 +00:00
|
|
|
|
2011-05-11 14:07:31 +00:00
|
|
|
const maxErrors = 20
|
|
|
|
|
2011-05-11 15:29:04 +00:00
|
|
|
// TODO: rate control + tunable
|
|
|
|
// TODO: expose copierPoolSize as tunable
|
2011-05-09 13:05:58 +00:00
|
|
|
type SyncHandler struct {
|
2011-05-11 14:07:31 +00:00
|
|
|
fromName, fromqName, toName string
|
|
|
|
from, fromq, to blobserver.Storage
|
|
|
|
|
2011-05-11 15:29:04 +00:00
|
|
|
copierPoolSize int
|
|
|
|
|
|
|
|
lk sync.Mutex // protects following
|
|
|
|
status string
|
|
|
|
blobStatus map[string]fmt.Stringer // stringer called with lk held
|
|
|
|
recentErrors []timestampedError
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
recentCopyTime time.Time
|
2011-05-11 15:29:04 +00:00
|
|
|
totalCopies int64
|
|
|
|
totalCopyBytes int64
|
2011-05-11 15:49:17 +00:00
|
|
|
totalErrors int64
|
2011-05-11 14:07:31 +00:00
|
|
|
}
|
|
|
|
|
2011-05-30 06:01:29 +00:00
|
|
|
func init() {
|
|
|
|
blobserver.RegisterHandlerConstructor("sync", newSyncFromConfig)
|
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func newSyncFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handler, err error) {
|
2011-05-30 06:01:29 +00:00
|
|
|
from := conf.RequiredString("from")
|
|
|
|
to := conf.RequiredString("to")
|
2012-11-07 21:40:17 +00:00
|
|
|
fullSync := conf.OptionalBool("fullSyncOnStart", false)
|
|
|
|
blockFullSync := conf.OptionalBool("blockingFullSyncOnStart", false)
|
2011-05-30 06:01:29 +00:00
|
|
|
if err = conf.Validate(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fromBs, err := ld.GetStorage(from)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
toBs, err := ld.GetStorage(to)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2011-12-04 23:19:28 +00:00
|
|
|
fromQsc, ok := fromBs.(blobserver.StorageQueueCreator)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("Prefix %s (type %T) does not support being efficient replication source (queueing)", from, fromBs)
|
|
|
|
}
|
|
|
|
synch, err := createSyncHandler(from, to, fromQsc, toBs)
|
2011-05-30 06:01:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2012-11-07 21:40:17 +00:00
|
|
|
|
|
|
|
if fullSync || blockFullSync {
|
|
|
|
didFullSync := make(chan bool, 1)
|
|
|
|
go func() {
|
|
|
|
n := synch.runSync("queue", fromQsc, 0)
|
|
|
|
log.Printf("Queue sync copied %d blobs", n)
|
|
|
|
n = synch.runSync("full", fromBs, 0)
|
|
|
|
log.Printf("Full sync copied %d blobs", n)
|
|
|
|
didFullSync <- true
|
|
|
|
synch.syncQueueLoop()
|
|
|
|
}()
|
|
|
|
if blockFullSync {
|
|
|
|
log.Printf("Blocking startup, waiting for full sync from %q to %q", from, to)
|
|
|
|
<-didFullSync
|
|
|
|
log.Printf("Full sync complete.")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
go synch.syncQueueLoop()
|
|
|
|
}
|
2013-01-11 22:21:56 +00:00
|
|
|
|
|
|
|
rootPrefix, _, err := ld.FindHandlerByType("root")
|
|
|
|
switch err {
|
|
|
|
case blobserver.ErrHandlerTypeNotFound:
|
|
|
|
// ignore; okay to not have a root handler.
|
|
|
|
case nil:
|
|
|
|
h, err := ld.GetHandler(rootPrefix)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
h.(*RootHandler).registerSyncHandler(synch)
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("Error looking for root handler: %v", err)
|
|
|
|
}
|
2011-05-30 06:01:29 +00:00
|
|
|
return synch, nil
|
|
|
|
}
|
|
|
|
|
2011-05-11 14:07:31 +00:00
|
|
|
type timestampedError struct {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
t time.Time
|
|
|
|
err error
|
2011-05-09 13:05:58 +00:00
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func createSyncHandler(fromName, toName string, from blobserver.StorageQueueCreator, to blobserver.Storage) (*SyncHandler, error) {
|
2011-05-09 18:08:14 +00:00
|
|
|
h := &SyncHandler{
|
2011-05-11 15:29:04 +00:00
|
|
|
copierPoolSize: 3,
|
|
|
|
from: from,
|
|
|
|
to: to,
|
|
|
|
fromName: fromName,
|
|
|
|
toName: toName,
|
|
|
|
status: "not started",
|
|
|
|
blobStatus: make(map[string]fmt.Stringer),
|
2011-05-09 13:05:58 +00:00
|
|
|
}
|
2011-05-11 14:07:31 +00:00
|
|
|
h.fromqName = strings.Replace(strings.Trim(toName, "/"), "/", "-", -1)
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
var err error
|
2011-12-04 23:19:28 +00:00
|
|
|
h.fromq, err = from.CreateQueue(h.fromqName)
|
2011-05-09 18:08:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Prefix %s (type %T) failed to create queue %q: %v",
|
2011-05-11 14:07:31 +00:00
|
|
|
fromName, from, h.fromqName, err)
|
2011-05-09 18:08:14 +00:00
|
|
|
}
|
|
|
|
return h, nil
|
2011-05-09 13:05:58 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 22:21:56 +00:00
|
|
|
func (sh *SyncHandler) discoveryMap() map[string]interface{} {
|
|
|
|
// TODO(mpl): more status info
|
|
|
|
return map[string]interface{}{
|
|
|
|
"from": sh.fromName,
|
|
|
|
"to": sh.toName,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-09 13:05:58 +00:00
|
|
|
func (sh *SyncHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
2011-05-11 14:07:31 +00:00
|
|
|
sh.lk.Lock()
|
|
|
|
defer sh.lk.Unlock()
|
2011-05-11 15:29:04 +00:00
|
|
|
|
|
|
|
fmt.Fprintf(rw, "<h1>%s to %s Sync Status</h1><p><b>Current status: </b>%s</p>",
|
|
|
|
sh.fromName, sh.toName, html.EscapeString(sh.status))
|
|
|
|
|
|
|
|
fmt.Fprintf(rw, "<h2>Stats:</h2><ul>")
|
|
|
|
fmt.Fprintf(rw, "<li>Blobs copied: %d</li>", sh.totalCopies)
|
|
|
|
fmt.Fprintf(rw, "<li>Bytes copied: %d</li>", sh.totalCopyBytes)
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
if !sh.recentCopyTime.IsZero() {
|
2011-05-11 15:29:04 +00:00
|
|
|
fmt.Fprintf(rw, "<li>Most recent copy: %s</li>", sh.recentCopyTime.Format(time.RFC3339))
|
|
|
|
}
|
2011-05-11 15:49:17 +00:00
|
|
|
fmt.Fprintf(rw, "<li>Copy errors: %d</li>", sh.totalErrors)
|
2011-05-11 15:29:04 +00:00
|
|
|
fmt.Fprintf(rw, "</ul>")
|
|
|
|
|
|
|
|
if len(sh.blobStatus) > 0 {
|
|
|
|
fmt.Fprintf(rw, "<h2>Current Copies:</h2><ul>")
|
|
|
|
for blobstr, sfn := range sh.blobStatus {
|
|
|
|
fmt.Fprintf(rw, "<li>%s: %s</li>\n",
|
|
|
|
blobstr, html.EscapeString(sfn.String()))
|
|
|
|
}
|
|
|
|
fmt.Fprintf(rw, "</ul>")
|
|
|
|
}
|
|
|
|
|
2011-05-11 14:07:31 +00:00
|
|
|
if len(sh.recentErrors) > 0 {
|
|
|
|
fmt.Fprintf(rw, "<h2>Recent Errors:</h2><ul>")
|
|
|
|
for _, te := range sh.recentErrors {
|
|
|
|
fmt.Fprintf(rw, "<li>%s: %s</li>\n",
|
|
|
|
te.t.Format(time.RFC3339),
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
html.EscapeString(te.err.Error()))
|
2011-05-11 14:07:31 +00:00
|
|
|
}
|
|
|
|
fmt.Fprintf(rw, "</ul>")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sh *SyncHandler) setStatus(s string, args ...interface{}) {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
s = time.Now().UTC().Format(time.RFC3339) + ": " + fmt.Sprintf(s, args...)
|
2011-05-11 14:07:31 +00:00
|
|
|
sh.lk.Lock()
|
|
|
|
defer sh.lk.Unlock()
|
2011-05-11 15:29:04 +00:00
|
|
|
sh.status = s
|
2011-05-11 14:07:31 +00:00
|
|
|
}
|
|
|
|
|
2011-05-11 15:29:04 +00:00
|
|
|
func (sh *SyncHandler) setBlobStatus(blobref string, s fmt.Stringer) {
|
2011-05-11 14:07:31 +00:00
|
|
|
sh.lk.Lock()
|
|
|
|
defer sh.lk.Unlock()
|
2011-05-11 15:29:04 +00:00
|
|
|
if s != nil {
|
|
|
|
sh.blobStatus[blobref] = s
|
|
|
|
} else {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
delete(sh.blobStatus, blobref)
|
2011-05-11 15:29:04 +00:00
|
|
|
}
|
2011-05-11 14:07:31 +00:00
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func (sh *SyncHandler) addErrorToLog(err error) {
|
|
|
|
log.Printf(err.Error())
|
2011-05-11 14:07:31 +00:00
|
|
|
sh.lk.Lock()
|
|
|
|
defer sh.lk.Unlock()
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
sh.recentErrors = append(sh.recentErrors, timestampedError{time.Now().UTC(), err})
|
2011-05-11 14:07:31 +00:00
|
|
|
if len(sh.recentErrors) > maxErrors {
|
|
|
|
// Kinda lame, but whatever. Only for errors, rare.
|
|
|
|
copy(sh.recentErrors[:maxErrors], sh.recentErrors[1:maxErrors+1])
|
|
|
|
sh.recentErrors = sh.recentErrors[:maxErrors]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-11 15:49:17 +00:00
|
|
|
type copyResult struct {
|
2013-08-04 02:54:30 +00:00
|
|
|
sb blob.SizedRef
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
err error
|
2011-05-11 15:49:17 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 21:40:17 +00:00
|
|
|
func (sh *SyncHandler) runSync(srcName string, enumSrc blobserver.Storage, longPollWait time.Duration) int {
|
|
|
|
if longPollWait != 0 {
|
2011-05-11 15:29:04 +00:00
|
|
|
sh.setStatus("Idle; waiting for new blobs")
|
2012-11-07 21:40:17 +00:00
|
|
|
}
|
2013-08-04 02:54:30 +00:00
|
|
|
enumch := make(chan blob.SizedRef)
|
2012-11-07 21:40:17 +00:00
|
|
|
errch := make(chan error, 1)
|
|
|
|
go func() {
|
|
|
|
errch <- enumSrc.EnumerateBlobs(enumch, "", 1000, longPollWait)
|
|
|
|
}()
|
|
|
|
|
|
|
|
nCopied := 0
|
|
|
|
toCopy := 0
|
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
workch := make(chan blob.SizedRef, 1000)
|
2012-11-07 21:40:17 +00:00
|
|
|
resch := make(chan copyResult, 8)
|
|
|
|
for sb := range enumch {
|
|
|
|
toCopy++
|
|
|
|
workch <- sb
|
|
|
|
if toCopy <= sh.copierPoolSize {
|
|
|
|
go sh.copyWorker(resch, workch)
|
2011-05-11 14:07:31 +00:00
|
|
|
}
|
2012-11-07 21:40:17 +00:00
|
|
|
sh.setStatus("Enumerating queued blobs: %d", toCopy)
|
|
|
|
}
|
|
|
|
close(workch)
|
|
|
|
for i := 0; i < toCopy; i++ {
|
|
|
|
sh.setStatus("Copied %d/%d of batch of queued blobs", nCopied, toCopy)
|
|
|
|
res := <-resch
|
|
|
|
nCopied++
|
|
|
|
sh.lk.Lock()
|
|
|
|
if res.err == nil {
|
|
|
|
sh.totalCopies++
|
|
|
|
sh.totalCopyBytes += res.sb.Size
|
|
|
|
sh.recentCopyTime = time.Now().UTC()
|
|
|
|
} else {
|
|
|
|
sh.totalErrors++
|
2011-05-11 15:49:17 +00:00
|
|
|
}
|
2012-11-07 21:40:17 +00:00
|
|
|
sh.lk.Unlock()
|
|
|
|
}
|
2011-05-11 15:29:04 +00:00
|
|
|
|
2012-11-07 21:40:17 +00:00
|
|
|
if err := <-errch; err != nil {
|
|
|
|
sh.addErrorToLog(fmt.Errorf("replication error for source %q, enumerate from source: %v", srcName, err))
|
|
|
|
return nCopied
|
|
|
|
}
|
|
|
|
return nCopied
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sh *SyncHandler) syncQueueLoop() {
|
|
|
|
every(queueSyncInterval, func() {
|
|
|
|
for sh.runSync(sh.fromqName, sh.fromq, queueSyncInterval) > 0 {
|
|
|
|
// Loop, before sleeping.
|
2011-05-11 15:29:04 +00:00
|
|
|
}
|
2011-05-11 14:07:31 +00:00
|
|
|
sh.setStatus("Sleeping briefly before next long poll.")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
func (sh *SyncHandler) copyWorker(res chan<- copyResult, work <-chan blob.SizedRef) {
|
2011-05-11 15:49:17 +00:00
|
|
|
for sb := range work {
|
|
|
|
res <- copyResult{sb, sh.copyBlob(sb)}
|
2011-05-11 15:29:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type statusFunc func() string
|
|
|
|
|
2013-01-01 02:21:50 +00:00
|
|
|
func (sf statusFunc) String() string { return sf() }
|
2011-05-11 15:29:04 +00:00
|
|
|
|
|
|
|
type status string
|
|
|
|
|
2013-01-01 02:21:50 +00:00
|
|
|
func (s status) String() string { return string(s) }
|
2011-05-11 15:29:04 +00:00
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
func (sh *SyncHandler) copyBlob(sb blob.SizedRef) error {
|
|
|
|
key := sb.Ref.String()
|
2011-05-11 15:29:04 +00:00
|
|
|
set := func(s fmt.Stringer) {
|
|
|
|
sh.setBlobStatus(key, s)
|
|
|
|
}
|
|
|
|
defer set(nil)
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
errorf := func(s string, args ...interface{}) error {
|
2011-05-11 15:29:04 +00:00
|
|
|
// TODO: increment error stats
|
2013-08-04 02:54:30 +00:00
|
|
|
pargs := []interface{}{sh.fromqName, sb.Ref}
|
2011-05-11 15:29:04 +00:00
|
|
|
pargs = append(pargs, args...)
|
|
|
|
err := fmt.Errorf("replication error for queue %q, blob %s: "+s, pargs...)
|
|
|
|
sh.addErrorToLog(err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
set(status("sending GET to source"))
|
2013-08-04 02:54:30 +00:00
|
|
|
rc, fromSize, err := sh.from.FetchStreaming(sb.Ref)
|
2011-05-11 15:29:04 +00:00
|
|
|
if err != nil {
|
2011-07-09 21:11:20 +00:00
|
|
|
return errorf("source fetch: %v", err)
|
2011-05-11 15:29:04 +00:00
|
|
|
}
|
2013-01-01 02:21:50 +00:00
|
|
|
defer rc.Close()
|
2011-05-11 15:29:04 +00:00
|
|
|
if fromSize != sb.Size {
|
2011-07-09 21:11:20 +00:00
|
|
|
return errorf("source fetch size mismatch: get=%d, enumerate=%d", fromSize, sb.Size)
|
2011-05-11 15:29:04 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 02:21:50 +00:00
|
|
|
bytesCopied := int64(0) // TODO: data race, accessed without locking in statusFunc below.
|
2011-05-11 15:29:04 +00:00
|
|
|
set(statusFunc(func() string {
|
|
|
|
return fmt.Sprintf("copying: %d/%d bytes", bytesCopied, sb.Size)
|
|
|
|
}))
|
2013-08-04 02:54:30 +00:00
|
|
|
newsb, err := sh.to.ReceiveBlob(sb.Ref, readerutil.CountingReader{rc, &bytesCopied})
|
2011-05-11 15:29:04 +00:00
|
|
|
if err != nil {
|
2011-07-09 21:11:20 +00:00
|
|
|
return errorf("dest write: %v", err)
|
2011-05-11 15:29:04 +00:00
|
|
|
}
|
|
|
|
if newsb.Size != sb.Size {
|
2011-07-09 21:11:20 +00:00
|
|
|
return errorf("write size mismatch: source_read=%d but dest_write=%d", sb.Size, newsb.Size)
|
2011-05-11 15:29:04 +00:00
|
|
|
}
|
|
|
|
set(status("copied; removing from queue"))
|
2013-08-04 02:54:30 +00:00
|
|
|
err = sh.fromq.RemoveBlobs([]blob.Ref{sb.Ref})
|
2011-05-11 15:29:04 +00:00
|
|
|
if err != nil {
|
2011-07-09 21:11:20 +00:00
|
|
|
return errorf("source queue delete: %v", err)
|
2011-05-11 15:29:04 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
func every(interval time.Duration, f func()) {
|
2011-05-11 14:07:31 +00:00
|
|
|
for {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
t1 := time.Now()
|
2011-05-11 14:07:31 +00:00
|
|
|
f()
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
sleepUntil := t1.Add(interval)
|
|
|
|
if sleep := sleepUntil.Sub(time.Now()); sleep > 0 {
|
2011-05-11 14:07:31 +00:00
|
|
|
time.Sleep(sleep)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|