initial storage reorganization

This commit is contained in:
Jimmy Zelinskie 2013-10-03 22:10:46 -04:00
parent 1335a43e7f
commit cf53f9554c
13 changed files with 29 additions and 29 deletions

View file

@ -15,9 +15,9 @@ import (
"github.com/pushrax/chihaya/config" "github.com/pushrax/chihaya/config"
"github.com/pushrax/chihaya/server" "github.com/pushrax/chihaya/server"
_ "github.com/pushrax/chihaya/cache/redis" _ "github.com/pushrax/chihaya/storage/tracker/redis"
_ "github.com/pushrax/chihaya/storage/batter" _ "github.com/pushrax/chihaya/storage/web/batter"
_ "github.com/pushrax/chihaya/storage/gazelle" _ "github.com/pushrax/chihaya/storage/web/gazelle"
) )
var ( var (

View file

@ -17,15 +17,15 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/pushrax/chihaya/cache"
"github.com/pushrax/chihaya/config" "github.com/pushrax/chihaya/config"
"github.com/pushrax/chihaya/models" "github.com/pushrax/chihaya/models"
"github.com/pushrax/chihaya/storage/tracker"
) )
type Server struct { type Server struct {
conf *config.Config conf *config.Config
listener net.Listener listener net.Listener
dbConnPool cache.Pool dbConnPool tracker.Pool
serving bool serving bool
startTime time.Time startTime time.Time
@ -41,7 +41,7 @@ type Server struct {
} }
func New(conf *config.Config) (*Server, error) { func New(conf *config.Config) (*Server, error) {
pool, err := cache.Open(&conf.Cache) pool, err := tracker.Open(&conf.Cache)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -133,7 +133,7 @@ func fail(err error, w http.ResponseWriter, r *http.Request) {
w.(http.Flusher).Flush() w.(http.Flusher).Flush()
} }
func validateUser(tx cache.Tx, dir string) (*models.User, error) { func validateUser(tx tracker.Conn, dir string) (*models.User, error) {
if len(dir) != 34 { if len(dir) != 34 {
return nil, errors.New("Passkey is invalid") return nil, errors.New("Passkey is invalid")
} }

View file

@ -13,8 +13,8 @@ import (
"github.com/pushrax/chihaya/config" "github.com/pushrax/chihaya/config"
_ "github.com/pushrax/chihaya/cache/redis" _ "github.com/pushrax/chihaya/storage/tracker/redis"
_ "github.com/pushrax/chihaya/storage/batter" _ "github.com/pushrax/chihaya/storage/web/batter"
) )
func newTestServer() (*Server, error) { func newTestServer() (*Server, error) {

View file

@ -6,7 +6,7 @@
// //
// This interface is configured by a config.DataStore. // This interface is configured by a config.DataStore.
// To get a handle to this interface, call New on the initialized driver and // To get a handle to this interface, call New on the initialized driver and
// then Get() on returned the cache.Pool. // then Get() on returned the tracker.Pool.
// //
// Torrents, Users, and Peers are all stored in Redis hash types. All Redis // Torrents, Users, and Peers are all stored in Redis hash types. All Redis
// keys can have an optional prefix specified during configuration. // keys can have an optional prefix specified during configuration.
@ -30,9 +30,9 @@ import (
"github.com/garyburd/redigo/redis" "github.com/garyburd/redigo/redis"
"github.com/pushrax/chihaya/cache"
"github.com/pushrax/chihaya/config" "github.com/pushrax/chihaya/config"
"github.com/pushrax/chihaya/models" "github.com/pushrax/chihaya/models"
"github.com/pushrax/chihaya/storage/tracker"
) )
var ( var (
@ -50,8 +50,8 @@ var (
type driver struct{} type driver struct{}
// New creates and returns a cache.Pool. // New creates and returns a tracker.Pool.
func (d *driver) New(conf *config.DataStore) cache.Pool { func (d *driver) New(conf *config.DataStore) tracker.Pool {
return &Pool{ return &Pool{
conf: conf, conf: conf,
pool: redis.Pool{ pool: redis.Pool{
@ -89,7 +89,7 @@ func (p *Pool) Close() error {
return p.pool.Close() return p.pool.Close()
} }
func (p *Pool) Get() (cache.Tx, error) { func (p *Pool) Get() (tracker.Conn, error) {
retTx := &Tx{ retTx := &Tx{
conf: p.conf, conf: p.conf,
done: false, done: false,
@ -685,5 +685,5 @@ func (tx *Tx) DecrementSlots(u *models.User) error {
// init registers the redis driver // init registers the redis driver
func init() { func init() {
cache.Register("redis", &driver{}) tracker.Register("redis", &driver{})
} }

View file

@ -11,17 +11,17 @@ import (
"testing" "testing"
"time" "time"
"github.com/pushrax/chihaya/cache"
"github.com/pushrax/chihaya/config" "github.com/pushrax/chihaya/config"
"github.com/pushrax/chihaya/models" "github.com/pushrax/chihaya/models"
"github.com/pushrax/chihaya/storage/tracker"
) )
func createTestTx() cache.Tx { func createTestTx() tracker.Conn {
testConfig, err := config.Open(os.Getenv("TESTCONFIGPATH")) testConfig, err := config.Open(os.Getenv("TESTCONFIGPATH"))
panicOnErr(err) panicOnErr(err)
conf := &testConfig.Cache conf := &testConfig.Cache
testPool, err := cache.Open(conf) testPool, err := tracker.Open(conf)
panicOnErr(err) panicOnErr(err)
txObj, err := testPool.Get() txObj, err := testPool.Get()

View file

@ -2,9 +2,9 @@
// Use of this source code is governed by the BSD 2-Clause license, // Use of this source code is governed by the BSD 2-Clause license,
// which can be found in the LICENSE file. // which can be found in the LICENSE file.
// Package cache provides a generic interface for manipulating a // Package tracker provides a generic interface for manipulating a
// BitTorrent tracker's fast moving data. // BitTorrent tracker's fast-moving, inconsistent data.
package cache package tracker
import ( import (
"fmt" "fmt"
@ -26,10 +26,10 @@ type Driver interface {
// it panics. // it panics.
func Register(name string, driver Driver) { func Register(name string, driver Driver) {
if driver == nil { if driver == nil {
panic("cache: Register driver is nil") panic("tracker: Register driver is nil")
} }
if _, dup := drivers[name]; dup { if _, dup := drivers[name]; dup {
panic("cache: Register called twice for driver " + name) panic("tracker: Register called twice for driver " + name)
} }
drivers[name] = driver drivers[name] = driver
} }
@ -39,7 +39,7 @@ func Open(conf *config.DataStore) (Pool, error) {
driver, ok := drivers[conf.Driver] driver, ok := drivers[conf.Driver]
if !ok { if !ok {
return nil, fmt.Errorf( return nil, fmt.Errorf(
"cache: unknown driver %q (forgotten import?)", "tracker: unknown driver %q (forgotten import?)",
conf.Driver, conf.Driver,
) )
} }
@ -48,15 +48,15 @@ func Open(conf *config.DataStore) (Pool, error) {
} }
// Pool represents a thread-safe pool of connections to the data store // Pool represents a thread-safe pool of connections to the data store
// that can be used to obtain transactions. // that can be used to safely within concurrent goroutines.
type Pool interface { type Pool interface {
Close() error Close() error
Get() (Tx, error) Get() (Conn, error)
} }
// The transmit object is the interface to add, remove and modify // Conn represents a connection to the data store that can be used
// data in the cache // to make atomic and non-atomic reads/writes.
type Tx interface { type Conn interface {
// Reads // Reads
FindUser(passkey string) (*models.User, bool, error) FindUser(passkey string) (*models.User, bool, error)
FindTorrent(infohash string) (*models.Torrent, bool, error) FindTorrent(infohash string) (*models.Torrent, bool, error)