func New(mo store.MergeOperator, config map[string]interface{}) (store.KVStore, error) { name, ok := config["kvStoreName_actual"].(string) if !ok || name == "" { return nil, fmt.Errorf("metrics: missing kvStoreName_actual,"+ " config: %#v", config) } if name == Name { return nil, fmt.Errorf("metrics: circular kvStoreName_actual") } ctr := registry.KVStoreConstructorByName(name) if ctr == nil { return nil, fmt.Errorf("metrics: no kv store constructor,"+ " kvStoreName_actual: %s", name) } kvs, err := ctr(mo, config) if err != nil { return nil, err } return &Store{ o: kvs, TimerReaderGet: metrics.NewTimer(), TimerReaderMultiGet: metrics.NewTimer(), TimerReaderPrefixIterator: metrics.NewTimer(), TimerReaderRangeIterator: metrics.NewTimer(), TimerWriterExecuteBatch: metrics.NewTimer(), TimerIteratorSeek: metrics.NewTimer(), TimerIteratorNext: metrics.NewTimer(), TimerBatchMerge: metrics.NewTimer(), errors: list.New(), }, nil }
func (udc *UpsideDownCouch) Open() (err error) { //acquire the write mutex for the duratin of Open() udc.writeMutex.Lock() defer udc.writeMutex.Unlock() // open the kv store storeConstructor := registry.KVStoreConstructorByName(udc.storeName) if storeConstructor == nil { err = index.ErrorUnknownStorageType return } // now open the store udc.store, err = storeConstructor(&mergeOperator, udc.storeConfig) if err != nil { return } // start a reader to look at the index var kvreader store.KVReader kvreader, err = udc.store.Reader() if err != nil { return } var value []byte value, err = kvreader.Get(VersionKey) if err != nil { _ = kvreader.Close() return } if value != nil { err = udc.loadSchema(kvreader) if err != nil { _ = kvreader.Close() return } // set doc count udc.m.Lock() udc.docCount, err = udc.countDocs(kvreader) udc.m.Unlock() err = kvreader.Close() } else { // new index, close the reader and open writer to init err = kvreader.Close() if err != nil { return } var kvwriter store.KVWriter kvwriter, err = udc.store.Writer() if err != nil { return } defer func() { if cerr := kvwriter.Close(); err == nil && cerr != nil { err = cerr } }() // init the index err = udc.init(kvwriter) } return }
func (f *Firestorm) Open() (err error) { // open the kv store storeConstructor := registry.KVStoreConstructorByName(f.storeName) if storeConstructor == nil { err = index.ErrorUnknownStorageType return } // now open the store f.store, err = storeConstructor(&mergeOperator, f.storeConfig) if err != nil { return } // start a reader var kvreader store.KVReader kvreader, err = f.store.Reader() if err != nil { return } // assert correct version, and find out if this is new index var newIndex bool newIndex, err = f.checkVersion(kvreader) if err != nil { return } if !newIndex { // process existing index before opening err = f.warmup(kvreader) if err != nil { return } } err = kvreader.Close() if err != nil { return } if newIndex { // prepare a new index err = f.bootstrap() if err != nil { return } } // start the garbage collector f.garbageCollector.Start() // start the lookuper f.lookuper.Start() // start the dict updater f.dictUpdater.Start() return }