Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c5beff4b8c
Fetching contributors…

Cannot retrieve contributors at this time

file 83 lines (75 sloc) 1.869 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
package main

import (
"flag"
"fmt"
"github.com/couchbaselabs/go-couchbase"
"log"
"strconv"
"time"
)

func maybeFatal(err error) {
if err != nil {
log.Fatalf("Error: %v", err)
}
}

func doOps(b *couchbase.Bucket) {
fmt.Printf("Doing some ops on %s\n", b.Name)
start := time.Now()
total := 2048
for i := 0; i < total; i++ {
k := fmt.Sprintf("k%d", i)
maybeFatal(b.Set(k, 0, []string{"a", "b", "c"}))
rv := make([]string, 0, 10)
maybeFatal(b.Get(k, &rv))
if fmt.Sprintf("%#v", rv) != `[]string{"a", "b", "c"}` {
log.Fatalf("Expected %#v, got %#v",
[]string{"a", "b", "c"}, rv)
}
maybeFatal(b.Delete(k))
}
fmt.Printf("Did %d ops in %s\n",
total*3, time.Now().Sub(start).String())
}

func exploreBucket(bucket *couchbase.Bucket) {
fmt.Printf(" %v uses %s\n", bucket.Name,
bucket.VBucketServerMap.HashAlgorithm)
for pos, server := range bucket.VBucketServerMap.ServerList {
vbs := make([]string, 0, 1024)
for vb, a := range bucket.VBucketServerMap.VBucketMap {
if a[0] == pos {
vbs = append(vbs, strconv.Itoa(vb))
}
}
fmt.Printf(" %s: %v\n", server, vbs)
}

doOps(bucket)

}

func explorePool(pool couchbase.Pool) {
for _, n := range pool.Nodes {
fmt.Printf(" %v\n", n.Hostname)
}
fmt.Printf(" Buckets:\n")
for n, _ := range pool.BucketMap {
bucket, err := pool.GetBucket(n)
if err != nil {
log.Fatalf("Error getting bucket: %v\n", err)
}
exploreBucket(bucket)
}
}

func main() {
flag.Parse()
c, err := couchbase.Connect(flag.Arg(0))
if err != nil {
log.Fatalf("Error connecting: %v", err)
}
fmt.Printf("Connected to ver=%s\n", c.Info.ImplementationVersion)
for _, pn := range c.Info.Pools {
fmt.Printf("Found pool: %s -> %s\n", pn.Name, pn.URI)
p, err := c.GetPool(pn.Name)
if err != nil {
log.Fatalf("Can't get pool: %v", err)
}
explorePool(p)
}
}
Something went wrong with that request. Please try again.