func (udc *UpsideDownCouch) Open() (err error) { // install the merge operator udc.store.SetMergeOperator(&mergeOperator) // now open the kv store err = udc.store.Open() if err != nil { return } // start a writer for the open process 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 } }() var value []byte value, err = kvwriter.Get(VersionKey) if err != nil { return } // init new index OR load schema if value == nil { err = udc.init(kvwriter) if err != nil { return } } else { err = udc.loadSchema(kvwriter) if err != nil { return } } // set doc count udc.m.Lock() udc.docCount, err = udc.countDocs(kvwriter) udc.m.Unlock() return }