From cf53f9554cbe546ca4cc171a54f993df305ec757 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Thu, 3 Oct 2013 22:10:46 -0400 Subject: [PATCH] initial storage reorganization --- main.go | 6 ++--- server/server.go | 8 +++---- server/stats_test.go | 4 ++-- {cache => storage/tracker}/redis/redis.go | 12 +++++----- .../tracker}/redis/redis_bench_test.go | 0 .../tracker}/redis/redis_test.go | 0 {cache => storage/tracker}/redis/tx_test.go | 6 ++--- cache/cache.go => storage/tracker/tracker.go | 22 +++++++++---------- storage/{ => web}/batter/batter.go | 0 storage/{ => web}/batter/load.go | 0 storage/{ => web}/gazelle/flush.go | 0 storage/{ => web}/gazelle/gazelle.go | 0 storage/{ => web}/gazelle/load.go | 0 13 files changed, 29 insertions(+), 29 deletions(-) rename {cache => storage/tracker}/redis/redis.go (98%) rename {cache => storage/tracker}/redis/redis_bench_test.go (100%) rename {cache => storage/tracker}/redis/redis_test.go (100%) rename {cache => storage/tracker}/redis/tx_test.go (99%) rename cache/cache.go => storage/tracker/tracker.go (79%) rename storage/{ => web}/batter/batter.go (100%) rename storage/{ => web}/batter/load.go (100%) rename storage/{ => web}/gazelle/flush.go (100%) rename storage/{ => web}/gazelle/gazelle.go (100%) rename storage/{ => web}/gazelle/load.go (100%) diff --git a/main.go b/main.go index ed13f83..3beac1a 100644 --- a/main.go +++ b/main.go @@ -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 ( diff --git a/server/server.go b/server/server.go index d23cb7d..52e2022 100644 --- a/server/server.go +++ b/server/server.go @@ -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") } diff --git a/server/stats_test.go b/server/stats_test.go index 2bf1542..f539266 100644 --- a/server/stats_test.go +++ b/server/stats_test.go @@ -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) { diff --git a/cache/redis/redis.go b/storage/tracker/redis/redis.go similarity index 98% rename from cache/redis/redis.go rename to storage/tracker/redis/redis.go index 3b70069..1caee0d 100644 --- a/cache/redis/redis.go +++ b/storage/tracker/redis/redis.go @@ -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{}) } diff --git a/cache/redis/redis_bench_test.go b/storage/tracker/redis/redis_bench_test.go similarity index 100% rename from cache/redis/redis_bench_test.go rename to storage/tracker/redis/redis_bench_test.go diff --git a/cache/redis/redis_test.go b/storage/tracker/redis/redis_test.go similarity index 100% rename from cache/redis/redis_test.go rename to storage/tracker/redis/redis_test.go diff --git a/cache/redis/tx_test.go b/storage/tracker/redis/tx_test.go similarity index 99% rename from cache/redis/tx_test.go rename to storage/tracker/redis/tx_test.go index 3d9772c..be4ef10 100644 --- a/cache/redis/tx_test.go +++ b/storage/tracker/redis/tx_test.go @@ -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() diff --git a/cache/cache.go b/storage/tracker/tracker.go similarity index 79% rename from cache/cache.go rename to storage/tracker/tracker.go index bcd2a4d..16036ed 100644 --- a/cache/cache.go +++ b/storage/tracker/tracker.go @@ -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) diff --git a/storage/batter/batter.go b/storage/web/batter/batter.go similarity index 100% rename from storage/batter/batter.go rename to storage/web/batter/batter.go diff --git a/storage/batter/load.go b/storage/web/batter/load.go similarity index 100% rename from storage/batter/load.go rename to storage/web/batter/load.go diff --git a/storage/gazelle/flush.go b/storage/web/gazelle/flush.go similarity index 100% rename from storage/gazelle/flush.go rename to storage/web/gazelle/flush.go diff --git a/storage/gazelle/gazelle.go b/storage/web/gazelle/gazelle.go similarity index 100% rename from storage/gazelle/gazelle.go rename to storage/web/gazelle/gazelle.go diff --git a/storage/gazelle/load.go b/storage/web/gazelle/load.go similarity index 100% rename from storage/gazelle/load.go rename to storage/web/gazelle/load.go