From 38a85571ca4162d3f7d25a5ad36e5ecbb927c4dc Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 2 Mar 2011 21:39:58 -0800 Subject: [PATCH] Add dev-blobserver wrapper; remove run.sh --- clients/go/camsync/camsync.go | 2 +- dev-blobserver | 35 ++++++++++++++++++++++++++++++ dev-camget | 2 +- dev-camput | 2 +- dev-camsync | 2 +- doc/protocol/blob-get-protocol.txt | 8 ++++++- lib/go/blobserver/handlers/get.go | 3 +++ lib/go/client/get.go | 7 +++--- server/go/blobserver/run.sh | 11 ---------- 9 files changed, 52 insertions(+), 20 deletions(-) create mode 100755 dev-blobserver delete mode 100755 server/go/blobserver/run.sh diff --git a/clients/go/camsync/camsync.go b/clients/go/camsync/camsync.go index 363e41b08..b19c23ae6 100644 --- a/clients/go/camsync/camsync.go +++ b/clients/go/camsync/camsync.go @@ -132,7 +132,7 @@ func main() { } } else { go func() { - destErr <- sc.EnumerateBlobs(destBlobs) + destErr <- dc.EnumerateBlobs(destBlobs) }() // Merge sort srcBlobs and destBlobs diff --git a/dev-blobserver b/dev-blobserver new file mode 100755 index 000000000..6b05177b3 --- /dev/null +++ b/dev-blobserver @@ -0,0 +1,35 @@ +#!/usr/bin/perl + +use strict; +use FindBin; +use Getopt::Long; + +sub usage { + die "Usage: dev-blobserver [--wipe] -- [other_camlistored_opts]"; +} + +my $opt_wipe; +GetOptions("wipe" => \$opt_wipe) + or usage(); + +my $port = shift || "3179"; +usage() unless $port =~ /^\d+$/; + +system("./build.pl", "server/go/blobserver") and die "Failed to build.\n"; + +my $root = "/tmp/camliroot/port$port/"; +if ($opt_wipe && -d $root) { + print "Wiping $root\n"; + system("rm", "-rf", $root) and die "Failed to wipe $root.\n"; +} +unless (-d $root) { + system("mkdir", "-p", $root) and die "Failed to create $root.\n"; +} + +print "Starting blobserver on http://localhost:$port/ in $root\n"; + +$ENV{CAMLI_PASSWORD} = "pass$port"; +exec("$FindBin::Bin/server/go/blobserver/camlistored", + "-root=$root", + "-listen=:$port", + @ARGV); diff --git a/dev-camget b/dev-camget index 339998556..a923221b9 100755 --- a/dev-camget +++ b/dev-camget @@ -1,4 +1,4 @@ #!/bin/sh ./build.pl camget && \ - clients/go/camget/camget --verbose --blobserver=localhost:3179 --password=foo $@ + clients/go/camget/camget --verbose --blobserver=localhost:3179 --password=pass3179 $@ diff --git a/dev-camput b/dev-camput index 75328136b..df1fb114a 100755 --- a/dev-camput +++ b/dev-camput @@ -1,4 +1,4 @@ #!/bin/sh ./build.pl camput && \ - clients/go/camput/camput --verbose --blobserver=localhost:3179 --password=foo $@ + clients/go/camput/camput --verbose --blobserver=localhost:3179 --password=pass3179 $@ diff --git a/dev-camsync b/dev-camsync index a449ef4aa..d46de203c 100755 --- a/dev-camsync +++ b/dev-camsync @@ -1,4 +1,4 @@ #!/bin/sh ./build.pl camsync && \ - clients/go/camsync/camsync --verbose --src=http://localhost:3179 --srcpassword=foo $@ + clients/go/camsync/camsync --verbose --src=http://localhost:3179 --srcpassword=pass3179 $@ diff --git a/doc/protocol/blob-get-protocol.txt b/doc/protocol/blob-get-protocol.txt index 0e8d52934..9f0978421 100644 --- a/doc/protocol/blob-get-protocol.txt +++ b/doc/protocol/blob-get-protocol.txt @@ -1,7 +1,13 @@ The /camli/ endpoint returns a blob the server knows about. -A request with the GET verb will return 200 and the blob contents if present, 404 if not. A request with the HEAD verb will return 200 and the blob meta data (i.e., content-length), or 404 if the blob is not present. +A request with the GET verb will return 200 and the blob contents if +present, 404 if not. A request with the HEAD verb will return 200 and +the blob meta data (i.e., content-length), or 404 if the blob is not +present. +The response must include an explicit Content-Length, even with HTTP/1.1. +(The one piece of metadata a blobserver keeps on a blob is its length, + which is used in both enumerate-blobs bodies and responses to blob GETs.) Get the blob: diff --git a/lib/go/blobserver/handlers/get.go b/lib/go/blobserver/handlers/get.go index 07a506d28..a26dda8d4 100644 --- a/lib/go/blobserver/handlers/get.go +++ b/lib/go/blobserver/handlers/get.go @@ -31,6 +31,7 @@ import ( "json" "log" "regexp" + "strconv" "strings" "time" ) @@ -208,6 +209,8 @@ func handleGet(conn http.ResponseWriter, req *http.Request, fetcher blobref.Fetc } } input = bufReader + + conn.SetHeader("Content-Length", strconv.Itoa64(size)) } conn.SetHeader("Content-Type", contentType) diff --git a/lib/go/client/get.go b/lib/go/client/get.go index e1ed769cc..1447b043d 100644 --- a/lib/go/client/get.go +++ b/lib/go/client/get.go @@ -23,7 +23,6 @@ import ( "http" "io" "os" - "strconv" ) func (c *Client) newRequest(method, url string) *http.Request { @@ -68,9 +67,9 @@ func (c *Client) FetchVia(b *blobref.BlobRef, v []*blobref.BlobRef) (blobref.Rea return nil, 0, err } - var size int64 - if s := resp.Header.Get("Content-Length"); s != "" { - size, _ = strconv.Atoi64(s) + size := resp.ContentLength + if size == -1 { + return nil, 0, os.NewError("blobserver didn't return a Content-Length for blob") } return nopSeeker{resp.Body}, size, nil diff --git a/server/go/blobserver/run.sh b/server/go/blobserver/run.sh deleted file mode 100755 index 6ab909334..000000000 --- a/server/go/blobserver/run.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -Bin=$(dirname $( readlink -f $0)) - -ROOT=/tmp/camliroot -if [ ! -d $ROOT ]; then - mkdir $ROOT -fi -export CAMLI_PASSWORD=foo - -$Bin/../../../build.pl server/go/blobserver && $Bin/camlistored -root=$ROOT -listen=:3179 "$@"