mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 17:15:56 +00:00
ultra basic webapi
This commit is contained in:
parent
c6e1a6875d
commit
0956d8b223
4 changed files with 13 additions and 133 deletions
|
|
@ -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
|
||||
|
||||
}
|
||||
|
|
|
|||
111
db/shard.go
111
db/shard.go
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue