From 0956d8b22343e925585279d64f9fa79882913c96 Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Wed, 11 Dec 2013 13:15:51 -0600 Subject: [PATCH] ultra basic webapi --- core/cruncher.go | 12 ++++- db/shard.go | 111 ----------------------------------------------- db/shard_test.go | 20 --------- index/server.go | 3 +- 4 files changed, 13 insertions(+), 133 deletions(-) delete mode 100644 db/shard.go delete mode 100644 db/shard_test.go diff --git a/core/cruncher.go b/core/cruncher.go index 6fe94108d..fceda00a9 100644 --- a/core/cruncher.go +++ b/core/cruncher.go @@ -2,15 +2,25 @@ package core import ( "github.com/davecgh/go-spew/spew" + "pilosa/index" ) type Cruncher struct { + close_chan chan bool } func (cruncher *Cruncher) Run(port int) { - spew.Dump("Cruncher.Run") spew.Dump(port) + web_api:= index.NewFragmentContainer() +// web_api.AddFragment("general", "25", 0, "AAA-BBB-CCC") +// web_api.AddFragment("general", "25", 1, "AAA-BBB-CCC") +// web_api.AddFragment("general", "25", 2, "AAA-BBB-CCC") + +started:= make(chan bool) +go web_api.RunServer(port , cruncher.close_chan ,started ) +<-started +//server is listening and going } diff --git a/db/shard.go b/db/shard.go deleted file mode 100644 index db2508bb6..000000000 --- a/db/shard.go +++ /dev/null @@ -1,111 +0,0 @@ -package db - -import ( - "fmt" - "log" - "github.com/golang/groupcache/lru" - "pilosa/index" -) - -type Request struct { - action interface{} -} - -type IntersectCount struct { - b1 uint64 - b2 uint64 -} - -func (g *IntersectCount) Execute(f *Shard) string { - a := f.Get(g.b1) - b := f.Get(g.b2) - result := index.Intersection(a, b) - c := index.BitCount(result) - return fmt.Sprintf("%d", c) -} - -type UnionCount struct { - b1 uint64 - b2 uint64 -} - -func (g *UnionCount) Execute(f *Shard) string { - b1 := f.Get(g.b1) - b2 := f.Get(g.b2) - result := index.Union(b1, b2) - c := index.BitCount(result) - return fmt.Sprintf("%d", c) -} - -type IdCount struct { - b1 uint64 -} - -func (g *IdCount) Execute(f *Shard) string { - b := f.Get(g.b1) - //c:=index.BitCount(result) - c := b.Count() - return fmt.Sprintf("%d", c) -} - -type Stat struct { - val string -} -type Quit struct { -} - -type Shard struct { - inbound chan Request - done chan bool - bitmap_cache *lru.Cache - shard_key int32 - storage index.Storage -} - -func NewShard(shard_key int32, s index.Storage) *Shard { - f := new(Shard) - f.inbound = make(chan Request, 512) - f.done = make(chan bool) - f.bitmap_cache = lru.New(10000) - f.shard_key = shard_key - f.storage = s - return f - -} - -func (f *Shard) Run() { - for req := range f.inbound { - switch req.action.(type) { - default: - log.Println("Unknown Message") - case IdCount: - action := req.action.(IdCount) - log.Println("IdCount", action.Execute(f)) - case UnionCount: - action := req.action.(UnionCount) - log.Println("UnionCount", action.Execute(f)) - case IntersectCount: - action := req.action.(IntersectCount) - log.Println("IntersectCount", action.Execute(f)) - case Quit: - log.Println("Quit", req) - f.done <- true - } - } -} -func (f *Shard) Get(bitmap_id uint64) index.IBitmap { - bm, ok := f.bitmap_cache.Get(bitmap_id) - if ok { - return bm.(*index.Bitmap) - } - //need to stick it in the cache - bm = f.storage.Fetch(bitmap_id, f.shard_key) - f.bitmap_cache.Add(bitmap_id, bm) - //return umbel.FetchCass(f.db,bitmap_id,f.shard_key) - return bm.(*index.Bitmap) -} -func MakeShardKey(property_id int, shard_id int) int32 { - result := (property_id << 16) | shard_id - return int32(result) -} - diff --git a/db/shard_test.go b/db/shard_test.go deleted file mode 100644 index 4bbdcaa8a..000000000 --- a/db/shard_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package db - -import ( - "testing" - "pilosa/index" - "log" - ) - -func TestShard(t *testing.T) { - f := NewShard(1638400,index.NewMemoryStorage()) - go f.Run() - log.Println("REQUEST") - f. inbound <- Request{IdCount{7812}} - f.inbound <- Request{UnionCount{7812 , 227149}} - f.inbound <- Request{IntersectCount{7812, 227149}} - f.inbound <- Request{Quit{}} - <-f.done - -} - diff --git a/index/server.go b/index/server.go index 4887038e7..1e66d75e9 100644 --- a/index/server.go +++ b/index/server.go @@ -29,8 +29,9 @@ func (a *FragmentContainer) AddFragment(frame string, db string, slice int, frag go f.ServeFragment() } -func (a *FragmentContainer) RunServer(port string, closeChannel chan bool,started chan bool) { +func (a *FragmentContainer) RunServer(porti int, closeChannel chan bool,started chan bool) { http.Handle("/", a) + port := fmt.Sprintf(":%d",porti) s := &http.Server{ Addr: port,