Exemple #1
0
func New(logger log.Logger, kvStore client.KvStorer, blobStore client.BlobStorer) *DocStoreExt {
	indexPath := filepath.Join(pathutil.VarDir(), "docstore.bleve")
	index, err := openIndex(indexPath)
	if err != nil {
		// TODO(tsileo): returns an error instead
		panic(err)
	}
	logger.Debug("Bleve index init", "index-path", indexPath)
	return &DocStoreExt{
		kvStore:   kvStore,
		blobStore: blobStore,
		index:     index,
		logger:    logger,
	}
}
Exemple #2
0
func New(conf map[string]interface{}) *Server {
	if conf == nil {
		conf = DefaultConf
	}
	vardir := pathutil.VarDir()
	// if dpath, ok := conf["data_path"].(string); ok {
	// 	vardir = dpath
	// }
	os.MkdirAll(vardir, 0700)
	db, err := vkv.New(filepath.Join(vardir, "vkv.db"))
	if err != nil {
		panic(err)
	}
	nsdb, err := nsdb.New(filepath.Join(vardir, "ns.db"))
	if err != nil {
		panic(err)
	}
	server := &Server{
		Router:   router.New(conf["router"].([]interface{})),
		Backends: map[string]backend.BlobHandler{},
		DB:       db,
		NsDB:     nsdb,
		KvUpdate: make(chan *vkv.KeyValue),
		ready:    make(chan struct{}, 1),
		shutdown: make(chan struct{}, 1),
		stop:     make(chan struct{}),
		blobs:    make(chan *router.Blob),
		resync:   conf["resync"].(bool),
		port:     conf["port"].(int),
		Log:      logger.Log,
		watchHub: hub.NewHub(),
	}
	backends := conf["backends"].(map[string]interface{})
	for _, b := range server.Router.ResolveBackends() {
		server.Backends[b] = config.NewFromConfig(backends[b].(map[string]interface{}))
		server.Router.Backends[b] = server.Backends[b]
	}
	server.metaHandler = meta.New(server.Router, server.DB, server.NsDB)
	return server
}
Exemple #3
0
func New(dir string, maxBlobsFileSize int64, compression, writeOnly bool) *BlobsFileBackend {
	dir = strings.Replace(dir, "$VAR", pathutil.VarDir(), -1)
	os.MkdirAll(dir, 0700)
	var reindex bool
	if _, err := os.Stat(filepath.Join(dir, "blobs-index")); os.IsNotExist(err) {
		reindex = true
	}
	index, err := NewIndex(dir)
	if err != nil {
		panic(err)
	}
	if maxBlobsFileSize == 0 {
		maxBlobsFileSize = defaultMaxBlobsFileSize
	}
	backend := &BlobsFileBackend{
		Directory:         dir,
		snappyCompression: compression,
		index:             index,
		files:             make(map[int]*os.File),
		writeOnly:         writeOnly,
		maxBlobsFileSize:  maxBlobsFileSize,
		reindexMode:       reindex,
	}
	backend.log = logger.Log.New("backend", backend.String())
	backend.log.Debug("Started")
	loader := backend.load
	if backend.writeOnly {
		loader = backend.loadWriteOnly
	}
	if err := loader(); err != nil {
		panic(fmt.Errorf("Error loading %T: %v", backend, err))
	}
	if backend.snappyCompression {
		backend.log.Debug("snappy compression enabled")
	}
	return backend
}
Exemple #4
0
	log2 "gopkg.in/inconshreveable/log15.v2"
)

var Version = "0.0.0"

var DefaultConf = map[string]interface{}{
	"backends": map[string]interface{}{
		"blobs": map[string]interface{}{
			"backend-type": "blobsfile",
			"backend-args": map[string]interface{}{
				"path": "$VAR/blobs",
			},
		},
	},
	"router":    []interface{}{[]interface{}{"default", "blobs"}},
	"data_path": pathutil.VarDir(),
}

// FIXME(ts) create ext interface with io.Closer and store them in a map as server attribute.

type Server struct {
	Log         log2.Logger
	Router      *router.Router
	Backends    map[string]backend.BlobHandler
	DB          *vkv.DB
	NsDB        *nsdb.DB
	metaHandler *meta.MetaHandler

	syncer *synctable.SyncTable

	KvUpdate chan *vkv.KeyValue