func NewFactory(
	cfg *config.Persistence,
	r resolver.ServiceResolver,
	persistenceMaxQPS dynamicconfig.IntPropertyFn,
	abstractDataStoreFactory AbstractDataStoreFactory,
	clusterName string,
	metricsClient metrics.Client,
	logger log.Logger,
) Factory {
	return NewFactoryImpl(cfg, r, persistenceMaxQPS, abstractDataStoreFactory, clusterName, metricsClient, logger)
}
NewFactory returns an implementation of factory that vends persistence objects based on
specified configuration. This factory takes as input a config.Persistence object
which specifies the datastore to be used for a given type of object. This config
also contains config for individual datastores themselves.

The objects returned by this factory enforce ratelimit and maxconns according to
given configuration. In addition, all objects will emit metrics automatically
package client
import (
	"sync"
	"go.temporal.io/server/common/config"
	"go.temporal.io/server/common/dynamicconfig"
	"go.temporal.io/server/common/log"
	"go.temporal.io/server/common/metrics"
	p "go.temporal.io/server/common/persistence"
	"go.temporal.io/server/common/persistence/cassandra"
	"go.temporal.io/server/common/persistence/sql"
	"go.temporal.io/server/common/quotas"
	"go.temporal.io/server/common/resolver"
)
type (
	Factory interface {
		Close()
		NewTaskManager() (p.TaskManager, error)
		NewShardManager() (p.ShardManager, error)
		NewMetadataManager() (p.MetadataManager, error)
		NewExecutionManager() (p.ExecutionManager, error)
		NewNamespaceReplicationQueue() (p.NamespaceReplicationQueue, error)
		NewClusterMetadataManager() (p.ClusterMetadataManager, error)
		FaultInjection() *FaultInjectionDataStoreFactory
	}
	DataStoreFactory interface {
		Close()
		NewTaskStore() (p.TaskStore, error)
		NewShardStore() (p.ShardStore, error)
		NewMetadataStore() (p.MetadataStore, error)
		NewExecutionStore() (p.ExecutionStore, error)
		NewQueue(queueType p.QueueType) (p.Queue, error)
		NewClusterMetadataStore() (p.ClusterMetadataStore, error)
	}
	AbstractDataStoreFactory interface {
		NewFactory(
			cfg config.CustomDatastoreConfig,
			r resolver.ServiceResolver,
			clusterName string,
			logger log.Logger,
			metricsClient metrics.Client,
		) DataStoreFactory
	}
	Datastore struct {
		factory   DataStoreFactory
		ratelimit quotas.RateLimiter
	}
	factoryImpl struct {
		sync.RWMutex
		config                   *config.Persistence
		abstractDataStoreFactory AbstractDataStoreFactory
		faultInjection           *FaultInjectionDataStoreFactory
		metricsClient            metrics.Client
		logger                   log.Logger
		datastores               map[storeType]Datastore
		clusterName              string
	}
	storeType int
)
const (
	storeTypeHistory storeType = iota + 1
	storeTypeTask
	storeTypeShard
	storeTypeMetadata
	storeTypeExecution
	storeTypeQueue
	storeTypeClusterMetadata
)
var storeTypes = []storeType{
	storeTypeHistory,
	storeTypeTask,
	storeTypeShard,
	storeTypeMetadata,
	storeTypeExecution,
	storeTypeQueue,
	storeTypeClusterMetadata,
}