generic index: untested stat support.

Change-Id: Idff5ff19d7b18ef6581c6c8bc344230470c468ef
This commit is contained in:
Brad Fitzpatrick 2011-11-10 18:58:04 -08:00
parent 0c8284f1af
commit 5c12ac37f3
3 changed files with 32 additions and 1 deletions

View File

@ -17,6 +17,7 @@ limitations under the License.
package index
import (
"fmt"
"os"
"strconv"
"strings"
@ -44,6 +45,20 @@ func (ix *Index) EnumerateBlobs(dest chan<- blobref.SizedBlobRef, after string,
}
func (ix *Index) StatBlobs(dest chan<- blobref.SizedBlobRef, blobs []*blobref.BlobRef, waitSeconds int) os.Error {
panic("TODO")
for _, br := range blobs {
key := "have:" + br.String()
v, err := ix.s.Get(key)
if err == ErrNotFound {
continue
}
if err != nil {
return fmt.Errorf("error looking up key %q: %v", key, err)
}
size, err := strconv.Atoi64(v)
if err != nil {
return fmt.Errorf("invalid size for key %q = %q", key, v)
}
dest <- blobref.SizedBlobRef{br, size}
}
return nil
}

View File

@ -25,7 +25,13 @@ import (
"camli/search"
)
var ErrNotFound = os.NewError("index: key not found")
type IndexStorage interface {
// Get gets the value for the given key. It returns ErrNotFound if the DB
// does not contain the key.
Get(key string) (string, os.Error)
Set(key, value string) os.Error
Delete(key string) os.Error

View File

@ -53,6 +53,16 @@ func (s stringIterator) Value() string {
return string(s.Iterator.Value())
}
func (mk *memKeys) Get(key string) (string, os.Error) {
mk.mu.Lock()
defer mk.mu.Unlock()
k, err := mk.db.Get([]byte(key))
if err == db.ErrNotFound {
return "", ErrNotFound
}
return string(k), err
}
func (mk *memKeys) Find(key string) Iterator {
mk.mu.Lock()
defer mk.mu.Unlock()