2011-03-02 02:02:01 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
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/blobref"
|
|
|
|
"camlistore.org/pkg/client"
|
|
|
|
"errors"
|
2011-03-02 02:02:01 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Things that can be uploaded. (at most one of these)
|
2011-03-05 17:53:51 +00:00
|
|
|
var flagLoop = flag.Bool("loop", false, "sync in a loop once done; requires --removesrc")
|
2011-03-02 02:02:01 +00:00
|
|
|
var flagVerbose = flag.Bool("verbose", false, "be verbose")
|
|
|
|
|
2011-03-05 17:53:51 +00:00
|
|
|
var flagSrc = flag.String("src", "", "Source blobserver prefix (generally a mirrored queue partition)")
|
2011-03-03 04:03:09 +00:00
|
|
|
var flagSrcPass = flag.String("srcpassword", "", "Source password")
|
|
|
|
var flagDest = flag.String("dest", "", "Destination blobserver, or 'stdout' to just enumerate the --src blobs to stdout")
|
|
|
|
var flagDestPass = flag.String("destpassword", "", "Destination password")
|
2011-03-02 02:02:01 +00:00
|
|
|
|
2011-03-05 17:53:51 +00:00
|
|
|
var flagRemoveSource = flag.Bool("removesrc", false,
|
|
|
|
"remove each blob from the source after syncing to the destination; for queue processing")
|
|
|
|
|
2011-06-14 15:09:15 +00:00
|
|
|
type SyncStats struct {
|
2011-07-02 16:09:50 +00:00
|
|
|
BlobsCopied int
|
|
|
|
BytesCopied int64
|
|
|
|
ErrorCount int
|
2011-06-14 15:09:15 +00:00
|
|
|
}
|
|
|
|
|
2011-03-02 02:02:01 +00:00
|
|
|
func usage(err string) {
|
|
|
|
if err != "" {
|
2011-03-05 17:53:51 +00:00
|
|
|
fmt.Fprintf(os.Stderr, "Error: %s\n\nUsage:\n", err)
|
2011-03-02 02:02:01 +00:00
|
|
|
}
|
|
|
|
flag.PrintDefaults()
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2011-03-03 04:03:09 +00:00
|
|
|
if *flagSrc == "" {
|
2011-03-05 17:53:51 +00:00
|
|
|
usage("No --src specified.")
|
2011-03-02 02:02:01 +00:00
|
|
|
}
|
2011-03-03 04:03:09 +00:00
|
|
|
if *flagDest == "" {
|
2011-03-05 17:53:51 +00:00
|
|
|
usage("No --dest specified.")
|
|
|
|
}
|
|
|
|
if *flagLoop && !*flagRemoveSource {
|
|
|
|
usage("Can't use --loop without --removesrc")
|
2011-03-02 02:02:01 +00:00
|
|
|
}
|
|
|
|
|
2011-11-16 10:41:38 +00:00
|
|
|
// TODO(mpl): adapt to the userpass scheme once it has settled
|
|
|
|
sc := client.New(*flagSrc)
|
|
|
|
sc.SetupAuth()
|
|
|
|
dc := client.New(*flagDest)
|
|
|
|
dc.SetupAuth()
|
2011-03-02 02:02:01 +00:00
|
|
|
|
|
|
|
var logger *log.Logger = nil
|
|
|
|
if *flagVerbose {
|
|
|
|
logger = log.New(os.Stderr, "", 0)
|
|
|
|
}
|
|
|
|
sc.SetLogger(logger)
|
|
|
|
dc.SetLogger(logger)
|
|
|
|
|
2011-03-05 17:53:51 +00:00
|
|
|
passNum := 0
|
|
|
|
for {
|
|
|
|
passNum++
|
2011-06-14 15:09:15 +00:00
|
|
|
stats, err := doPass(sc, dc, passNum)
|
|
|
|
if err != nil {
|
2011-03-05 17:53:51 +00:00
|
|
|
log.Fatalf("sync failed: %v", err)
|
|
|
|
}
|
2011-06-14 15:09:15 +00:00
|
|
|
if *flagVerbose {
|
|
|
|
log.Printf("sync stats - pass: %d, blobs: %d, bytes %d\n", passNum, stats.BlobsCopied, stats.BytesCopied)
|
|
|
|
}
|
2011-03-05 17:53:51 +00:00
|
|
|
if !*flagLoop {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 doPass(sc, dc *client.Client, passNum int) (stats SyncStats, retErr error) {
|
2011-05-10 23:13:37 +00:00
|
|
|
srcBlobs := make(chan blobref.SizedBlobRef, 100)
|
|
|
|
destBlobs := make(chan blobref.SizedBlobRef, 100)
|
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
|
|
|
srcErr := make(chan error)
|
|
|
|
destErr := make(chan error)
|
2011-03-05 17:53:51 +00:00
|
|
|
|
2011-03-02 02:02:01 +00:00
|
|
|
go func() {
|
2012-10-09 14:47:43 +00:00
|
|
|
srcErr <- sc.SimpleEnumerateBlobs(srcBlobs)
|
2011-03-02 02:02:01 +00:00
|
|
|
}()
|
2011-03-05 17:53:51 +00:00
|
|
|
checkSourceError := func() {
|
|
|
|
if err := <-srcErr; err != 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
|
|
|
retErr = errors.New(fmt.Sprintf("Enumerate error from source: %v", err))
|
2011-03-05 17:53:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-03 04:03:09 +00:00
|
|
|
if *flagDest == "stdout" {
|
|
|
|
for sb := range srcBlobs {
|
|
|
|
fmt.Printf("%s %d\n", sb.BlobRef, sb.Size)
|
|
|
|
}
|
2011-03-05 17:53:51 +00:00
|
|
|
checkSourceError()
|
|
|
|
return
|
2011-03-02 02:02:01 +00:00
|
|
|
}
|
|
|
|
|
2011-03-05 17:53:51 +00:00
|
|
|
go func() {
|
2012-10-09 14:47:43 +00:00
|
|
|
destErr <- dc.SimpleEnumerateBlobs(destBlobs)
|
2011-03-05 17:53:51 +00:00
|
|
|
}()
|
|
|
|
checkDestError := func() {
|
2011-03-03 04:03:09 +00:00
|
|
|
if err := <-destErr; err != 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
|
|
|
retErr = errors.New(fmt.Sprintf("Enumerate error from destination: %v", err))
|
2011-03-05 17:53:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-10 23:13:37 +00:00
|
|
|
destNotHaveBlobs := make(chan blobref.SizedBlobRef, 100)
|
2011-03-05 17:53:51 +00:00
|
|
|
go client.ListMissingDestinationBlobs(destNotHaveBlobs, srcBlobs, destBlobs)
|
|
|
|
for sb := range destNotHaveBlobs {
|
|
|
|
fmt.Printf("Destination needs blob: %s\n", sb)
|
|
|
|
|
2011-05-11 11:59:45 +00:00
|
|
|
blobReader, size, err := sc.FetchStreaming(sb.BlobRef)
|
2011-03-05 17:53:51 +00:00
|
|
|
if err != nil {
|
2011-06-14 15:09:15 +00:00
|
|
|
stats.ErrorCount++
|
2011-03-05 17:53:51 +00:00
|
|
|
log.Printf("Error fetching %s: %v", sb.BlobRef, err)
|
|
|
|
continue
|
2011-03-03 04:03:09 +00:00
|
|
|
}
|
2011-03-05 17:53:51 +00:00
|
|
|
if size != sb.Size {
|
2011-06-14 15:09:15 +00:00
|
|
|
stats.ErrorCount++
|
2011-03-05 17:53:51 +00:00
|
|
|
log.Printf("Source blobserver's enumerate size of %d for blob %s doesn't match its Get size of %d",
|
|
|
|
sb.Size, sb.BlobRef, size)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
uh := &client.UploadHandle{BlobRef: sb.BlobRef, Size: size, Contents: blobReader}
|
|
|
|
pr, err := dc.Upload(uh)
|
|
|
|
if err != nil {
|
2011-06-14 15:09:15 +00:00
|
|
|
stats.ErrorCount++
|
2011-03-05 17:53:51 +00:00
|
|
|
log.Printf("Upload of %s to destination blobserver failed: %v", sb.BlobRef, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !pr.Skipped {
|
2011-06-14 15:09:15 +00:00
|
|
|
stats.BlobsCopied++
|
|
|
|
stats.BytesCopied += pr.Size
|
2011-03-05 17:53:51 +00:00
|
|
|
}
|
|
|
|
if *flagRemoveSource {
|
2011-03-05 20:46:28 +00:00
|
|
|
if err = sc.RemoveBlob(sb.BlobRef); err != nil {
|
2011-06-14 15:09:15 +00:00
|
|
|
stats.ErrorCount++
|
2011-03-05 19:34:12 +00:00
|
|
|
log.Printf("Failed to delete %s from source: %v", sb.BlobRef, err)
|
|
|
|
}
|
2011-03-05 17:53:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkSourceError()
|
|
|
|
checkDestError()
|
2011-06-14 15:09:15 +00:00
|
|
|
if retErr == nil && stats.ErrorCount > 0 {
|
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
|
|
|
retErr = errors.New(fmt.Sprintf("%d errors during sync", stats.ErrorCount))
|
2011-03-03 04:03:09 +00:00
|
|
|
}
|
2011-06-14 15:09:15 +00:00
|
|
|
return stats, retErr
|
2011-03-02 02:02:01 +00:00
|
|
|
}
|