func New(backendbs blobstore.BlobStore, cachebs blobstore.RandomAccessBlobStore, s *scheduler.Scheduler, flags int, queryVersion version.QueryFunc) (*CachedBlobStore, error) { if fl.IsWriteAllowed(flags) { if fr, ok := backendbs.(fl.FlagsReader); ok { if !fl.IsWriteAllowed(fr.Flags()) { return nil, fmt.Errorf("Writable CachedBlobStore requested, but backendbs doesn't allow writes") } } } if !fl.IsWriteAllowed(cachebs.Flags()) { return nil, fmt.Errorf("CachedBlobStore requested, but cachebs doesn't allow writes") } cbs := &CachedBlobStore{ backendbs: backendbs, cachebs: cachebs, s: s, flags: flags, queryVersion: queryVersion, bever: NewCachedBackendVersion(backendbs, queryVersion), entriesmgr: NewCachedBlobEntriesManager(), usagestats: NewCacheUsageStats(), } if lister, ok := cachebs.(blobstore.BlobLister); ok { bps, err := lister.ListBlobs() if err != nil { return nil, fmt.Errorf("Failed to list blobs to init CacheUsageStats: %v", err) } cbs.usagestats.ImportBlobList(bps) } go cbs.entriesmgr.Run() return cbs, nil }
func WriteVersionedBlobRA(bs blobstore.RandomAccessBlobStore, blobpath string, version byte) error { bh, err := bs.Open(blobpath, flags.O_RDWRCREATE) if err != nil { return fmt.Errorf("Failed to open handle: %v", err) } if err := bh.PWrite([]byte{version}, 0); err != nil { return fmt.Errorf("Failed to blob write: %v", err) } if err := bh.Close(); err != nil { return fmt.Errorf("Failed to close handle: %v", err) } return nil }
func AssertBlobVersionRA(bs blobstore.RandomAccessBlobStore, blobpath string, expected version.Version) error { h, err := bs.Open(blobpath, flags.O_RDONLY) if err != nil { return fmt.Errorf("Failed to open reader: %v", err) } actual, err := TestQueryVersion(&blobstore.OffsetReader{h, 0}) if err != nil { return fmt.Errorf("Failed to query version: %v", err) } if err := h.Close(); err != nil { return fmt.Errorf("Failed to close reader: %v", err) } if actual != expected { return fmt.Errorf("Expected version %d, but got %d", expected, actual) } return nil }
func New(backendbs blobstore.BlobStore, cachebs blobstore.RandomAccessBlobStore, flags int, queryVersion QueryVersionFunc) (*CachedBlobStore, error) { if fl.IsWriteAllowed(flags) { if fr, ok := backendbs.(fl.FlagsReader); ok { if !fl.IsWriteAllowed(fr.Flags()) { return nil, fmt.Errorf("Writable CachedBlobStore requested, but backendbs doesn't allow writes") } } } if !fl.IsWriteAllowed(cachebs.Flags()) { return nil, fmt.Errorf("CachedBlobStore requested, but cachebs doesn't allow writes") } cbs := &CachedBlobStore{ backendbs: backendbs, cachebs: cachebs, flags: flags, queryVersion: queryVersion, bever: NewCachedBackendVersion(backendbs, queryVersion), entriesmgr: NewCachedBlobEntriesManager(), } go cbs.entriesmgr.Run() return cbs, nil }