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/server"
_ "github.com/pushrax/chihaya/cache/redis"
_ "github.com/pushrax/chihaya/storage/batter"
_ "github.com/pushrax/chihaya/storage/gazelle"
_ "github.com/pushrax/chihaya/storage/tracker/redis"
_ "github.com/pushrax/chihaya/storage/web/batter"
_ "github.com/pushrax/chihaya/storage/web/gazelle"
)
var (

View file

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

View file

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

View file

@ -6,7 +6,7 @@
//
// This interface is configured by a config.DataStore.
// 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
// keys can have an optional prefix specified during configuration.
@ -30,9 +30,9 @@ import (
"github.com/garyburd/redigo/redis"
"github.com/pushrax/chihaya/cache"
"github.com/pushrax/chihaya/config"
"github.com/pushrax/chihaya/models"
"github.com/pushrax/chihaya/storage/tracker"
)
var (
@ -50,8 +50,8 @@ var (
type driver struct{}
// New creates and returns a cache.Pool.
func (d *driver) New(conf *config.DataStore) cache.Pool {
// New creates and returns a tracker.Pool.
func (d *driver) New(conf *config.DataStore) tracker.Pool {
return &Pool{
conf: conf,
pool: redis.Pool{
@ -89,7 +89,7 @@ func (p *Pool) Close() error {
return p.pool.Close()
}
func (p *Pool) Get() (cache.Tx, error) {
func (p *Pool) Get() (tracker.Conn, error) {
retTx := &Tx{
conf: p.conf,
done: false,
@ -685,5 +685,5 @@ func (tx *Tx) DecrementSlots(u *models.User) error {
// init registers the redis driver
func init() {
cache.Register("redis", &driver{})
tracker.Register("redis", &driver{})
}

View file

@ -11,17 +11,17 @@ import (
"testing"
"time"
"github.com/pushrax/chihaya/cache"
"github.com/pushrax/chihaya/config"
"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"))
panicOnErr(err)
conf := &testConfig.Cache
testPool, err := cache.Open(conf)
testPool, err := tracker.Open(conf)
panicOnErr(err)
txObj, err := testPool.Get()

View file

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