src/server/pfs/server/obj_block_api_server.go
func newObjBlockAPIServer(dir string, cacheBytes int64, etcdAddress string, objClient obj.Client, test bool) (*objBlockAPIServer, error) {
	// defensive measure to make sure storage is working and error early if it's not
	// this is where we'll find out if the credentials have been misconfigured
	if err := obj.TestStorage(context.Background(), objClient); err != nil {
		return nil, err
	}
	oneCacheShare := cacheBytes / (objectCacheShares + tagCacheShares + objectInfoCacheShares + blockCacheShares)
	s := &objBlockAPIServer{
		Logger:           log.NewLogger("pfs.BlockAPI.Obj"),
		dir:              dir,
		objClient:        objClient,
		objectIndexes:    make(map[string]*pfsclient.ObjectIndex),
		objectCacheBytes: oneCacheShare * objectCacheShares,
	}

	objectGroupName := "object"
	tagGroupName := "tag"
	objectInfoGroupName := "objectInfo"
	blockGroupName := "block"

	if test {
		uuid := uuid.New()
		objectGroupName += uuid
		tagGroupName += uuid
		objectInfoGroupName += uuid
		blockGroupName += uuid
	}

	s.objectCache = groupcache.NewGroup(objectGroupName, oneCacheShare*objectCacheShares, groupcache.GetterFunc(s.objectGetter))
	s.tagCache = groupcache.NewGroup(tagGroupName, oneCacheShare*tagCacheShares, groupcache.GetterFunc(s.tagGetter))
	s.objectInfoCache = groupcache.NewGroup(objectInfoGroupName, oneCacheShare*objectInfoCacheShares, groupcache.GetterFunc(s.objectInfoGetter))
	s.blockCache = groupcache.NewGroup(blockGroupName, oneCacheShare*blockCacheShares, groupcache.GetterFunc(s.blockGetter))

	if !test {
		RegisterCacheStats("tag", &s.tagCache.Stats)
		RegisterCacheStats("object", &s.objectCache.Stats)
		RegisterCacheStats("object_info", &s.objectInfoCache.Stats)
	}

	go s.watchGC(etcdAddress)
	return s, nil
}
func newObjBlockAPIServer(dir string, cacheBytes int64, etcdAddress string, objClient obj.Client, test bool) (*objBlockAPIServer, error) {
	// defensive measure to make sure storage is working and error early if it's not
	// this is where we'll find out if the credentials have been misconfigured
	if err := obj.TestStorage(context.Background(), objClient); err != nil {
		return nil, err
	}
	oneCacheShare := cacheBytes / (objectCacheShares + tagCacheShares + objectInfoCacheShares + blockCacheShares)
	s := &objBlockAPIServer{
		Logger:           log.NewLogger("pfs.BlockAPI.Obj"),
		dir:              dir,
		objClient:        objClient,
		objectIndexes:    make(map[string]*pfsclient.ObjectIndex),
		objectCacheBytes: oneCacheShare * objectCacheShares,
	}

	objectGroupName := "object"
	tagGroupName := "tag"
	objectInfoGroupName := "objectInfo"
	blockGroupName := "block"

	if test {
		uuid := uuid.New()
		objectGroupName += uuid
		tagGroupName += uuid
		objectInfoGroupName += uuid
		blockGroupName += uuid
	}

	s.objectCache = groupcache.NewGroup(objectGroupName, oneCacheShare*objectCacheShares, groupcache.GetterFunc(s.objectGetter))
	s.tagCache = groupcache.NewGroup(tagGroupName, oneCacheShare*tagCacheShares, groupcache.GetterFunc(s.tagGetter))
	s.objectInfoCache = groupcache.NewGroup(objectInfoGroupName, oneCacheShare*objectInfoCacheShares, groupcache.GetterFunc(s.objectInfoGetter))
	s.blockCache = groupcache.NewGroup(blockGroupName, oneCacheShare*blockCacheShares, groupcache.GetterFunc(s.blockGetter))

	if !test {
		RegisterCacheStats("tag", &s.tagCache.Stats)
		RegisterCacheStats("object", &s.objectCache.Stats)
		RegisterCacheStats("object_info", &s.objectInfoCache.Stats)
	}

	go s.watchGC(etcdAddress)
	return s, nil
}
func newObjBlockAPIServer ( dir string , cacheBytes int64 , etcdAddress string , objClient obj . Client , test bool ) ( * objBlockAPIServer , error ) { // defensive measure to make sure storage is working and error early if it's not // this is where we'll find out if the credentials have been misconfigured if err := obj . TestStorage ( context . Background ( ) , objClient ) ; err != nil { return nil , err } oneCacheShare := cacheBytes / ( objectCacheShares + tagCacheShares + objectInfoCacheShares + blockCacheShares ) s := & objBlockAPIServer { Logger : log . NewLogger ( " " ) , dir : dir , objClient : objClient , objectIndexes : make ( map [ string ] * pfsclient . ObjectIndex ) , objectCacheBytes : oneCacheShare * objectCacheShares , } objectGroupName := " " tagGroupName := " " objectInfoGroupName := " " blockGroupName := " " if test { uuid := uuid . New ( ) objectGroupName += uuid tagGroupName += uuid objectInfoGroupName += uuid blockGroupName += uuid } s . objectCache = groupcache . NewGroup ( objectGroupName , oneCacheShare * objectCacheShares , groupcache . GetterFunc ( s . objectGetter ) ) s . tagCache = groupcache . NewGroup ( tagGroupName , oneCacheShare * tagCacheShares , groupcache . GetterFunc ( s . tagGetter ) ) s . objectInfoCache = groupcache . NewGroup ( objectInfoGroupName , oneCacheShare * objectInfoCacheShares , groupcache . GetterFunc ( s . objectInfoGetter ) ) s . blockCache = groupcache . NewGroup ( blockGroupName , oneCacheShare * blockCacheShares , groupcache . GetterFunc ( s . blockGetter ) ) if ! test { RegisterCacheStats ( " " , & s . tagCache . Stats ) RegisterCacheStats ( " " , & s . objectCache . Stats ) RegisterCacheStats ( " " , & s . objectInfoCache . Stats ) } go s . watchGC ( etcdAddress ) return s , nil }
// In test mode, we use unique names for cache groups, since we might want
// to run multiple block servers locally, which would conflict if groups
// had the same name. We also do not report stats to prometheus
In test mode we use unique names for cache groups since we might want to run multiple block servers locally which would conflict if groups had the same name . We also do not report stats to prometheus