func (b *Backend) Close() error {
	b.wgMu.Lock()
	close(b.closing)
	b.wgMu.Unlock()
	b.wg.Wait()
	if err := b.Coordinator.Close(); err != nil {
		log.Logger.Error(err)
	}
	if err := b.DB.Close(); err != nil {
		log.Logger.Error(err)
	}
	log.Logger.Infof(
		"backend stoped: id: %s, rpc: %s",
		b.agentInfo.ID,
		b.agentInfo.RPCAddr,
	)
	return nil
}
Close closes all resources of this instance.
package backend
import (
	"os"
	gosync "sync"
	"time"
	"github.com/rs/xid"
	"github.com/yorkie-team/yorkie/internal/log"
	"github.com/yorkie-team/yorkie/pkg/cache"
	"github.com/yorkie-team/yorkie/yorkie/backend/db"
	"github.com/yorkie-team/yorkie/yorkie/backend/db/mongo"
	"github.com/yorkie-team/yorkie/yorkie/backend/sync"
	"github.com/yorkie-team/yorkie/yorkie/backend/sync/etcd"
	"github.com/yorkie-team/yorkie/yorkie/backend/sync/memory"
	"github.com/yorkie-team/yorkie/yorkie/metrics"
)
const authWebhookCacheSize = 5000
type Backend struct {
	Config    *Config
	agentInfo *sync.AgentInfo
	DB               db.DB
	Coordinator      sync.Coordinator
	Metrics          metrics.Metrics
	AuthWebhookCache *cache.LRUExpireCache
	closing chan struct{}
	wgMu gosync.RWMutex
	wg gosync.WaitGroup
}
func New(
	conf *Config,
	mongoConf *mongo.Config,
	etcdConf *etcd.Config,
	rpcAddr string,
	met metrics.Metrics,
) (*Backend, error) {
	hostname, err := os.Hostname()
	if err != nil {
		return nil, err
	}
	agentInfo := &sync.AgentInfo{
		ID:        xid.New().String(),
		Hostname:  hostname,
		RPCAddr:   rpcAddr,
		UpdatedAt: time.Now(),
	}
	mongoClient, err := mongo.Dial(mongoConf)
	if err != nil {
		return nil, err
	}
	var coordinator sync.Coordinator
	if etcdConf != nil {
		etcdClient, err := etcd.Dial(etcdConf, agentInfo)
		if err != nil {
			return nil, err
		}
		if err := etcdClient.Initialize(); err != nil {
			return nil, err
		}
		coordinator = etcdClient
	} else {
		coordinator = memory.NewCoordinator(agentInfo)
	}
	log.Logger.Infof(
		"backend created: id: %s, rpc: %s",
		agentInfo.ID,
		agentInfo.RPCAddr,
	)
	lruCache, err := cache.NewLRUExpireCache(authWebhookCacheSize)
	if err != nil {
		return nil, err
	}
	return &Backend{
		Config:           conf,
		agentInfo:        agentInfo,
		DB:               mongoClient,
		Coordinator:      coordinator,
		Metrics:          met,
		AuthWebhookCache: lruCache,
		closing:          make(chan struct{}),
	}, nil
}