// newDiskQuotaCacheLocalFromStorage creates a new *DiskQuotaCacheLocal
// with the passed-in storage.Storage interfaces as storage layers for each
// cache.
546116
func newDiskQuotaCacheLocalFromStorage(
	config diskQuotaCacheConfig, quotaStorage storage.Storage) (
	cache *DiskQuotaCacheLocal, err error) {
	log := config.MakeLogger("DQC")
	closers := make([]io.Closer, 0, 1)
	closer := func() {
		for _, c := range closers {
			closeErr := c.Close()
			if closeErr != nil {
				log.Warning("Error closing leveldb or storage: %+v", closeErr)
			}
		}
	}
	defer func() {
		if err != nil {
			err = errors.WithStack(err)
			closer()
		}
	}()
	quotaDbOptions := *leveldbOptions
	quotaDbOptions.CompactionTableSize = defaultQuotaCacheTableSize
	quotaDbOptions.Filter = filter.NewBloomFilter(16)
	db, err := openLevelDBWithOptions(quotaStorage, &quotaDbOptions)
	if err != nil {
		return nil, err
	}
	closers = append(closers, db)

	startedCh := make(chan struct{})
	startErrCh := make(chan struct{})
	cache = &DiskQuotaCacheLocal{
		config:       config,
		hitMeter:     NewCountMeter(),
		missMeter:    NewCountMeter(),
		putMeter:     NewCountMeter(),
		log:          log,
		db:           db,
		quotasCached: make(map[keybase1.UserOrTeamID]bool),
		startedCh:    startedCh,
		startErrCh:   startErrCh,
		shutdownCh:   make(chan struct{}),
		closer:       closer,
	}
	// Sync the quota counts asynchronously so syncing doesn't block init.
	// Since this method blocks, any Get or Put requests to the disk Quota
	// cache will block until this is done. The log will contain the beginning
	// and end of this sync.
	go func() {
		err := cache.syncQuotaCountsFromDb()
		if err != nil {
			close(startErrCh)
			closer()
			log.Warning("Disabling disk quota cache due to error syncing the "+
				"quota counts from DB: %+v", err)
			return
		}
		close(startedCh)
	}()
	return cache, nil
}
32503
func NewGCSStore(gcs *storage.Client, bucket, cachepath string, pagesize int) (*GcsFS, error) {
	err := os.MkdirAll(path.Dir(cachepath), 0775)
	if err != nil {
		return nil, fmt.Errorf("unable to create path. path=%s err=%v", cachepath, err)
	}

	uid := uuid.NewUUID().String()
	uid = strings.Replace(uid, "-", "", -1)

	return &GcsFS{
		gcs:       gcs,
		bucket:    bucket,
		cachepath: cachepath,
		Id:        uid,
		PageSize:  pagesize,
	}, nil
}
610656
func NewDiskstatsCollector() (Collector, error) {
	return &diskstatsCollector{
		rxfer:  typedDesc{readsCompletedDesc, prometheus.CounterValue},
		rbytes: typedDesc{readBytesDesc, prometheus.CounterValue},
		wxfer:  typedDesc{writesCompletedDesc, prometheus.CounterValue},
		wbytes: typedDesc{writtenBytesDesc, prometheus.CounterValue},
		time:   typedDesc{ioTimeSecondsDesc, prometheus.CounterValue},
	}, nil
}
1312907
func NewCCache() *CCache {
	if maxSize == 0 {
		return nil
	}

	cc := &CCache{
		metricCache:   make(map[schema.AMKey]*CCacheMetric),
		metricRawKeys: make(map[schema.MKey]map[schema.Archive]struct{}),
		accnt:         accnt.NewFlatAccnt(maxSize),
		stop:          make(chan interface{}),
		tracer:        opentracing.NoopTracer{},
	}
	go cc.evictLoop()
	return cc
}
289237
func newCache(config CacheConfig) (*diskCache, error) {
	var cfsObjects []*cacheFSObjects
	ctx := logger.SetReqInfo(context.Background(), &logger.ReqInfo{})
	formats, err := loadAndValidateCacheFormat(ctx, config.Drives)
	if err != nil {
		return nil, err
	}
	for i, dir := range config.Drives {
		// skip cacheFSObjects creation for cache drives missing a format.json
		if formats[i] == nil {
			cfsObjects = append(cfsObjects, nil)
			continue
		}
		if err := checkAtimeSupport(dir); err != nil {
			return nil, errors.New("Atime support required for disk caching")
		}
		cache, err := newCacheFSObjects(dir, config.Expiry, config.MaxUse)
		if err != nil {
			return nil, err
		}
		// Start the purging go-routine for entries that have expired
		go cache.purge()

		// Start trash purge routine for deleted buckets.
		go cache.purgeTrash()

		cfsObjects = append(cfsObjects, cache)
	}
	return &diskCache{cfs: cfsObjects}, nil
}
201859
func (m *MockAgentClient) AddPersistentDisk(arg0 string, arg1 interface{}) error {
	ret := m.ctrl.Call(m, "AddPersistentDisk", arg0, arg1)
	ret0, _ := ret[0].(error)
	return ret0
}
943603
func NewAnalyticalStorage(ts influxdb.TaskService, tcs TaskControlService, pw storage.PointsWriter, qs query.QueryService) *AnalyticalStorage {
	return &AnalyticalStorage{
		TaskService:        ts,
		TaskControlService: tcs,
		pw:                 pw,
		qs:                 qs,
	}
}
1201429
func CreateNewDisk() *Disk {
	return &Disk{
		propPlanID:         propPlanID{Plan: DiskPlanSSD},
		propDiskConnection: propDiskConnection{Connection: DiskConnectionVirtio},
		propSizeMB:         propSizeMB{SizeMB: 20480},
	}
}
1074222
func (cache *DiskBlockCacheLocal) decodeBlockCacheEntry(buf []byte) ([]byte,
	kbfscrypto.BlockCryptKeyServerHalf, error) {
	entry := diskBlockCacheEntry{}
	err := cache.config.Codec().Decode(buf, &entry)
	if err != nil {
		return nil, kbfscrypto.BlockCryptKeyServerHalf{}, err
	}
	return entry.Buf, entry.ServerHalf, nil
}
14043
func NewCacheStore(keyFn cache.KeyFunc) cache.Indexer {
	return cache.NewIndexer(keyFn, cache.Indexers{
		"requester": indexNamespaceByRequester,
	})
}
971108
func NewDiskCache(baseDir string) (*DiskCache, error) {
	err := os.MkdirAll(baseDir, 0700)
	if err != nil {
		return nil, err
	}
	return &DiskCache{baseDir: baseDir, fileList: make(map[string]int)}, nil
}
947520
func (st *State) NewBakeryStorage() (bakerystorage.ExpirableStorage, error) {
	return bakerystorage.New(bakerystorage.Config{
		GetCollection: func() (mongo.Collection, func()) {
			return st.db().GetCollection(bakeryStorageItemsC)
		},
		GetStorage: func(rootKeys *mgostorage.RootKeys, coll mongo.Collection, expireAfter time.Duration) bakery.Storage {
			return rootKeys.NewStorage(coll.Writeable().Underlying(), mgostorage.Policy{
				ExpiryDuration: expireAfter,
			})
		},
	})
}
1271022
func NewMockStorageClassInterface(ctrl *gomock.Controller) *MockStorageClassInterface {
	mock := &MockStorageClassInterface{ctrl: ctrl}
	mock.recorder = &MockStorageClassInterfaceMockRecorder{mock}
	return mock
}
18038
func NewEc2Storage(instance, instanceType string, ec2 *ec2.EC2) storageops.Ops {
	return &ec2Ops{
		instance:     instance,
		instanceType: instanceType,
		ec2:          ec2,
	}
}
779996
func NewCache(maxSize uint64) *Cache {
	c := &Cache{
		maxSize:      maxSize,
		store:        emptyStore{},
		lastSnapshot: time.Now(),
		tracker:      newCacheTracker(newCacheMetrics(nil), nil),
	}
	c.initialize.Store(&sync.Once{})
	return c
}
1271076
func (s *supportImpl) GetChaincodeFromLocalStorage(ccname string, ccversion string) (ccprovider.CCPackage, error) {
	return ccprovider.GetChaincodeFromFS(ccname, ccversion)
}
550225
func NewMockStorage(ctrl *gomock.Controller) *MockStorage {
	mock := &MockStorage{ctrl: ctrl}
	mock.recorder = &MockStorageMockRecorder{mock}
	return mock
}