diff --git a/cache_test.go b/cache_test.go index 2a16c95..7f36454 100644 --- a/cache_test.go +++ b/cache_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/dustin/go-couchstore" + "github.com/mschoch/gouchstore" ) func benchCacheSize(b *testing.B, num int) { @@ -17,8 +17,7 @@ func benchCacheSize(b *testing.B, num int) { startTime := time.Now() for i := 0; i < num; i++ { - di := couchstore.NewDocInfo(startTime.Format(time.RFC3339Nano), - 0) + di := gouchstore.NewDocumentInfo(startTime.Format(time.RFC3339Nano)) p.infos = append(p.infos, di) } diff --git a/database.go b/database.go index 662be9d..18497df 100644 --- a/database.go +++ b/database.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/dustin/go-couchstore" + "github.com/mschoch/gouchstore" ) type dbOperation uint8 @@ -34,7 +34,7 @@ type dbWriter struct { dbname string ch chan dbqitem quit chan bool - db *couchstore.Couchstore + db *gouchstore.Gouchstore } var errClosed = errors.New("closed") @@ -71,9 +71,9 @@ func dbBase(n string) string { return n[left:right] } -func dbopen(name string) (*couchstore.Couchstore, error) { +func dbopen(name string) (*gouchstore.Gouchstore, error) { path := dbPath(name) - db, err := couchstore.Open(dbPath(name), false) + db, err := gouchstore.Open(dbPath(name), 0) if err == nil { recordDBConn(path, db) } @@ -81,7 +81,7 @@ func dbopen(name string) (*couchstore.Couchstore, error) { } func dbcreate(path string) error { - db, err := couchstore.Open(path, true) + db, err := gouchstore.Open(path, gouchstore.OPEN_CREATE) if err != nil { return err } @@ -120,8 +120,8 @@ func dblist(root string) []string { return rv } -func dbCompact(dq *dbWriter, bulk couchstore.BulkWriter, queued int, - qi dbqitem) (couchstore.BulkWriter, error) { +func dbCompact(dq *dbWriter, bulk gouchstore.BulkWriter, queued int, + qi dbqitem) (gouchstore.BulkWriter, error) { start := time.Now() if queued > 0 { bulk.Commit() @@ -134,7 +134,7 @@ func dbCompact(dq *dbWriter, bulk couchstore.BulkWriter, queued int, dbn := dbPath(dq.dbname) queued = 0 start = time.Now() - err := dq.db.CompactTo(dbn + ".compact") + err := dq.db.Compact(dbn + ".compact") if err != nil { log.Printf("Error compacting: %v", err) return dq.db.Bulk(), err @@ -186,13 +186,12 @@ func dbWriteLoop(dq *dbWriter) { liveOps++ switch qi.op { case opStoreItem: - bulk.Set(couchstore.NewDocInfo(qi.k, - couchstore.DocIsCompressed), - couchstore.NewDocument(qi.k, qi.data)) + bulk.Set(gouchstore.NewDocumentInfo(qi.k), + gouchstore.NewDocument(qi.k, qi.data)) queued++ case opDeleteItem: queued++ - bulk.Delete(couchstore.NewDocInfo(qi.k, 0)) + bulk.Delete(gouchstore.NewDocumentInfo(qi.k)) case opCompact: var err error bulk, err = dbCompact(dq, bulk, queued, qi) @@ -301,11 +300,11 @@ func dbGetDoc(dbname, id string) ([]byte, error) { } defer closeDBConn(db) - doc, _, err := db.Get(id) + doc, err := db.DocumentById(id) if err != nil { return nil, err } - return doc.Value(), err + return doc.Body, err } func dbwalk(dbname, from, to string, f func(k string, v []byte) error) error { @@ -316,13 +315,9 @@ func dbwalk(dbname, from, to string, f func(k string, v []byte) error) error { } defer closeDBConn(db) - return db.WalkDocs(from, func(d *couchstore.Couchstore, - di *couchstore.DocInfo, doc *couchstore.Document) error { - if to != "" && di.ID() >= to { - return couchstore.StopIteration - } - - return f(di.ID(), doc.Value()) + return db.WalkDocs(from, to, func(d *gouchstore.Gouchstore, + di *gouchstore.DocumentInfo, doc *gouchstore.Document) error { + return f(di.ID, doc.Body) }) } @@ -334,14 +329,9 @@ func dbwalkKeys(dbname, from, to string, f func(k string) error) error { } defer closeDBConn(db) - return db.Walk(from, func(d *couchstore.Couchstore, - di *couchstore.DocInfo) error { - if to != "" && di.ID() >= to { - return couchstore.StopIteration - } - - return f(di.ID()) - }) + return db.AllDocuments(from, to, func(db *gouchstore.Gouchstore, documentInfo *gouchstore.DocumentInfo, userContext interface{}) error { + return f(documentInfo.ID) + }, nil) } func parseKey(s string) int64 { diff --git a/debug.go b/debug.go index 2107954..c48634c 100644 --- a/debug.go +++ b/debug.go @@ -8,7 +8,7 @@ import ( "runtime" "sync" - "github.com/dustin/go-couchstore" + "github.com/mschoch/gouchstore" ) type frameSnap []uintptr @@ -30,9 +30,9 @@ type dbOpenState struct { } var openConnLock = sync.Mutex{} -var openConns = map[*couchstore.Couchstore]dbOpenState{} +var openConns = map[*gouchstore.Gouchstore]dbOpenState{} -func recordDBConn(path string, db *couchstore.Couchstore) { +func recordDBConn(path string, db *gouchstore.Gouchstore) { callers := make([]uintptr, 32) n := runtime.Callers(2, callers) openConnLock.Lock() @@ -40,7 +40,7 @@ func recordDBConn(path string, db *couchstore.Couchstore) { openConnLock.Unlock() } -func closeDBConn(db *couchstore.Couchstore) { +func closeDBConn(db *gouchstore.Gouchstore) { db.Close() openConnLock.Lock() _, ok := openConns[db] diff --git a/handlers.go b/handlers.go index 2a9fbdb..9be2d19 100644 --- a/handlers.go +++ b/handlers.go @@ -12,9 +12,9 @@ import ( "strings" "time" - "github.com/dustin/go-couchstore" "github.com/dustin/go-humanize" "github.com/dustin/gojson" + "github.com/mschoch/gouchstore" ) func serverInfo(parts []string, w http.ResponseWriter, req *http.Request) { @@ -269,7 +269,7 @@ func deleteBulk(args []string, w http.ResponseWriter, req *http.Request) { err = dbwalkKeys(args[0], from, to, func(k string) error { - bulk.Delete(couchstore.NewDocInfo(k, 0)) + bulk.Delete(gouchstore.NewDocumentInfo(k)) deleteCount++ if deleteCount >= commitThreshold { bulk.Commit() @@ -433,11 +433,11 @@ func dbInfo(args []string, w http.ResponseWriter, req *http.Request) { } defer closeDBConn(db) - inf, err := db.Info() + inf, err := db.DatabaseInfo() if err == nil { mustEncode(200, w, map[string]interface{}{ "last_seq": inf.LastSeq, - "doc_count": inf.DocCount, + "doc_count": inf.DocumentCount, "deleted_count": inf.DeletedCount, "space_used": inf.SpaceUsed, "header_pos": inf.HeaderPosition, diff --git a/query.go b/query.go index 543bd49..d13a5b1 100644 --- a/query.go +++ b/query.go @@ -9,15 +9,15 @@ import ( "sync/atomic" "time" - "github.com/dustin/go-couchstore" "github.com/dustin/go-jsonpointer" "github.com/dustin/gojson" + "github.com/mschoch/gouchstore" ) var errTimeout = errors.New("query timed out") type ptrval struct { - di *couchstore.DocInfo + di *gouchstore.DocumentInfo val interface{} included bool } @@ -40,8 +40,8 @@ type processIn struct { cacheKey string dbname string key int64 - infos []*couchstore.DocInfo - nextInfo *couchstore.DocInfo + infos []*gouchstore.DocumentInfo + nextInfo *gouchstore.DocumentInfo ptrs []string reds []string before time.Time @@ -83,7 +83,7 @@ func resolveFetch(j []byte, keys []string) map[string]interface{} { return rv } -func processDoc(di *couchstore.DocInfo, chs []chan ptrval, +func processDoc(di *gouchstore.DocumentInfo, chs []chan ptrval, doc []byte, ptrs []string, filters []string, filtervals []string, included bool) { @@ -130,7 +130,7 @@ func processDoc(di *couchstore.DocInfo, chs []chan ptrval, for i, p := range ptrs { val := fetched[p] if p == "_id" { - val = di.ID() + val = di.ID } switch x := val.(type) { case int, uint, int64, float64, uint64, bool: @@ -174,10 +174,10 @@ func processDocs(pi *processIn) { go func() { defer closeAll(chans) - dodoc := func(di *couchstore.DocInfo, included bool) { - doc, err := db.GetFromDocInfo(di) + dodoc := func(di *gouchstore.DocumentInfo, included bool) { + doc, err := db.DocumentByDocumentInfo(di) if err == nil { - processDoc(di, chans, doc.Value(), pi.ptrs, + processDoc(di, chans, doc.Body, pi.ptrs, pi.filters, pi.filtervals, included) } else { for i := range pi.ptrs { @@ -226,8 +226,8 @@ func docProcessor(ch <-chan *processIn) { } } -func fetchDocs(dbname string, key int64, infos []*couchstore.DocInfo, - nextInfo *couchstore.DocInfo, ptrs []string, reds []string, +func fetchDocs(dbname string, key int64, infos []*gouchstore.DocumentInfo, + nextInfo *gouchstore.DocumentInfo, ptrs []string, reds []string, filters []string, filtervals []string, before time.Time, out chan<- *processOut) { @@ -257,17 +257,13 @@ func runQuery(q *queryIn) { chunk := int64(time.Duration(q.group) * time.Millisecond) - infos := []*couchstore.DocInfo{} + infos := []*gouchstore.DocumentInfo{} g := int64(0) nextg := "" - err = db.Walk(q.from, func(d *couchstore.Couchstore, - di *couchstore.DocInfo) error { - kstr := di.ID() + err = db.AllDocuments(q.from, q.to, func(db *gouchstore.Gouchstore, di *gouchstore.DocumentInfo, userContext interface{}) error { + kstr := di.ID var err error - if q.to != "" && kstr >= q.to { - err = couchstore.StopIteration - } atomic.AddInt32(&q.totalKeys, 1) @@ -278,7 +274,7 @@ func runQuery(q *queryIn) { q.ptrs, q.reds, q.filters, q.filtervals, q.before, q.out) - infos = make([]*couchstore.DocInfo, 0, len(infos)) + infos = make([]*gouchstore.DocumentInfo, 0, len(infos)) } k := parseKey(kstr) @@ -290,7 +286,7 @@ func runQuery(q *queryIn) { infos = append(infos, di) return err - }) + }, nil) if err == nil && len(infos) > 0 { atomic.AddInt32(&q.started, 1) @@ -374,7 +370,7 @@ func convertTofloat64Rate(in chan ptrval) chan float64 { case string: x, err := strconv.ParseFloat(value, 64) if err == nil { - prevts = parseKey(v.di.ID()) + prevts = parseKey(v.di.ID) preval = x break FIND_USABLE } @@ -388,7 +384,7 @@ func convertTofloat64Rate(in chan ptrval) chan float64 { case string: x, err := strconv.ParseFloat(value, 64) if err == nil { - thists := parseKey(v.di.ID()) + thists := parseKey(v.di.ID) val := ((x - preval) / (float64(thists-prevts) / 1e9)) diff --git a/query_test.go b/query_test.go index e96a56d..843dc46 100644 --- a/query_test.go +++ b/query_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/dustin/go-couchstore" + "github.com/mschoch/gouchstore" ) var testInput = []interface{}{} @@ -40,11 +40,11 @@ func streamCollection(s []interface{}) chan ptrval { for _, r := range s { t = t.Add(time.Second) ts := t.Format(time.RFC3339Nano) - ch <- ptrval{couchstore.NewDocInfo(ts, 0), r, true} + ch <- ptrval{gouchstore.NewDocumentInfo(ts), r, true} } t = t.Add(time.Second) ts := t.Format(time.RFC3339Nano) - ch <- ptrval{couchstore.NewDocInfo(ts, 0), nextValue, false} + ch <- ptrval{gouchstore.NewDocumentInfo(ts), nextValue, false} }() return ch } @@ -76,12 +76,12 @@ func TestPairRateConversion(t *testing.T) { tm := time.Now().UTC() val1 := "20" - ch <- ptrval{couchstore.NewDocInfo(tm.Format(time.RFC3339Nano), 0), + ch <- ptrval{gouchstore.NewDocumentInfo(tm.Format(time.RFC3339Nano)), val1, true} tm = tm.Add(5 * time.Second) val2 := "25" - ch <- ptrval{couchstore.NewDocInfo(tm.Format(time.RFC3339Nano), 0), + ch <- ptrval{gouchstore.NewDocumentInfo(tm.Format(time.RFC3339Nano)), val2, false} close(ch) @@ -241,7 +241,7 @@ func TestNilReducers(t *testing.T) { func TestPointers(t *testing.T) { docID := "2013-02-22T16:29:19.750264Z" - di := couchstore.NewDocInfo(docID, 0) + di := gouchstore.NewDocumentInfo(docID) tests := []struct { pointer string exp interface{}