2011-02-28 00:18:17 +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 localdisk
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2011-05-09 16:11:18 +00:00
|
|
|
|
2013-08-04 02:54:30 +00:00
|
|
|
"camlistore.org/pkg/blob"
|
2013-09-12 15:04:10 +00:00
|
|
|
"camlistore.org/pkg/syncutil"
|
2014-01-28 20:46:52 +00:00
|
|
|
"camlistore.org/pkg/types"
|
2011-02-28 00:18:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const maxParallelStats = 20
|
|
|
|
|
2013-10-05 07:43:15 +00:00
|
|
|
var statGate = syncutil.NewGate(maxParallelStats)
|
|
|
|
|
2013-08-21 20:57:28 +00:00
|
|
|
func (ds *DiskStorage) StatBlobs(dest chan<- blob.SizedRef, blobs []blob.Ref) error {
|
2011-02-28 00:18:17 +00:00
|
|
|
if len(blobs) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-08-21 20:57:28 +00:00
|
|
|
statSend := func(ref blob.Ref) error {
|
Get rid of QueueCreator and all its associated complexity.
Previous TODO entry was:
-- Get rid of QueueCreator entirely. Plan:
-- sync handler still has a source and dest (one pair) but
instead of calling CreateQueue on the source, it instead
has an index.Storage (configured via a RequiredObject
so it can be a kvfile, leveldb, mysql, postgres etc)
-- make all the index.Storage types be instantiable
from a jsonconfig Object, perhaps with constructors keyed
on a "type" field.
-- make sync handler support blobserver.Receiver (or StatReceiver)
like indexes, so it can receive blobs. but all it needs to
do to acknowledge the ReceiveBlob is write and flush to its
index.Storage. the syncing is async by default. (otherwise callers
could just use "replica" if they wanted sync replication).
But maybe for ease of configuration switching, we could also
support a sync mode. when it needs to replicate a blob,
it uses the source.
-- future option: sync mirror to an alternate path on ReceiveBlob
that can delete. e.g. you're uploading to s3 and google,
but don't want to upload to both at once, so you use the localdisk
as a buffer to spread out your upstream bandwidth.
-- end result: no more hardlinks or queue creator.
Change-Id: I6244fc4f3a655f08470ae3160502659399f468ed
2013-11-22 22:33:31 +00:00
|
|
|
fi, err := os.Stat(ds.blobPath(ref))
|
2011-02-28 00:18:17 +00:00
|
|
|
switch {
|
2013-08-21 20:57:28 +00:00
|
|
|
case err == nil && fi.Mode().IsRegular():
|
2014-01-28 20:46:52 +00:00
|
|
|
dest <- blob.SizedRef{Ref: ref, Size: types.U32(fi.Size())}
|
2013-08-21 20:57:28 +00:00
|
|
|
return nil
|
2012-11-07 19:02:34 +00:00
|
|
|
case err != nil && !os.IsNotExist(err):
|
2011-02-28 00:18:17 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(blobs) == 1 {
|
2013-08-21 20:57:28 +00:00
|
|
|
return statSend(blobs[0])
|
2011-02-28 00:18:17 +00:00
|
|
|
}
|
|
|
|
|
2013-10-05 07:43:15 +00:00
|
|
|
var wg syncutil.Group
|
2013-08-21 20:57:28 +00:00
|
|
|
for _, ref := range blobs {
|
2013-10-11 05:54:23 +00:00
|
|
|
ref := ref
|
2013-10-05 07:43:15 +00:00
|
|
|
statGate.Start()
|
|
|
|
wg.Go(func() error {
|
|
|
|
defer statGate.Done()
|
|
|
|
return statSend(ref)
|
|
|
|
})
|
2011-02-28 00:18:17 +00:00
|
|
|
}
|
2013-10-05 07:43:15 +00:00
|
|
|
return wg.Err()
|
2011-02-28 00:18:17 +00:00
|
|
|
}
|