s/SqliteBackend/SQLiteBackend/ s/SqliteSession/SQLiteSession/ in mtredisalize.

This commit is contained in:
Sascha L. Teichmann 2016-04-24 20:54:05 +02:00
parent d21fa6c027
commit 14ae6d3873
2 changed files with 23 additions and 23 deletions

View File

@ -103,7 +103,7 @@ func main() {
path := flag.Arg(0) path := flag.Arg(0)
if driver == "sqlite" { if driver == "sqlite" {
if backend, err = NewSqliteBackend(path, changeTracker, interleaved); err != nil { if backend, err = NewSQLiteBackend(path, changeTracker, interleaved); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} else { } else {

View File

@ -26,7 +26,7 @@ const (
rangeSQL = "SELECT pos, data FROM blocks WHERE pos BETWEEN ? AND ? ORDER BY pos" rangeSQL = "SELECT pos, data FROM blocks WHERE pos BETWEEN ? AND ? ORDER BY pos"
) )
type SqliteBackend struct { type SQLiteBackend struct {
db *sql.DB db *sql.DB
encoder common.KeyEncoder encoder common.KeyEncoder
decoder common.KeyDecoder decoder common.KeyDecoder
@ -42,16 +42,16 @@ type SqliteBackend struct {
rangeStmt *sql.Stmt rangeStmt *sql.Stmt
} }
type SqliteSession struct { type SQLiteSession struct {
backend *SqliteBackend backend *SQLiteBackend
tx *sql.Tx tx *sql.Tx
} }
func (sqlb *SqliteBackend) NewSession() (Session, error) { func (sqlb *SQLiteBackend) NewSession() (Session, error) {
return &SqliteSession{sqlb, nil}, nil return &SQLiteSession{sqlb, nil}, nil
} }
func (ss *SqliteSession) Close() error { func (ss *SQLiteSession) Close() error {
t := ss.tx t := ss.tx
if t != nil { if t != nil {
ss.tx = nil ss.tx = nil
@ -60,11 +60,11 @@ func (ss *SqliteSession) Close() error {
return nil return nil
} }
func NewSqliteBackend( func NewSQLiteBackend(
path string, path string,
changeTracker *changeTracker, interleaved bool) (sqlb *SqliteBackend, err error) { changeTracker *changeTracker, interleaved bool) (sqlb *SQLiteBackend, err error) {
res := SqliteBackend{interleaved: interleaved, changeTracker: changeTracker} res := SQLiteBackend{interleaved: interleaved, changeTracker: changeTracker}
if res.db, err = sql.Open("sqlite3", path); err != nil { if res.db, err = sql.Open("sqlite3", path); err != nil {
return return
@ -123,7 +123,7 @@ func NewSqliteBackend(
return return
} }
func (sqlb *SqliteBackend) buildCoverage() (err error) { func (sqlb *SQLiteBackend) buildCoverage() (err error) {
log.Println("INFO: Start building coverage index (this may take some time)...") log.Println("INFO: Start building coverage index (this may take some time)...")
sqlb.coverage = common.NewCoverage3D() sqlb.coverage = common.NewCoverage3D()
@ -163,7 +163,7 @@ func closeDB(db **sql.DB) error {
return nil return nil
} }
func (sqlb *SqliteBackend) closeAll() error { func (sqlb *SQLiteBackend) closeAll() error {
closeStmt(&sqlb.fetchStmt) closeStmt(&sqlb.fetchStmt)
closeStmt(&sqlb.insertStmt) closeStmt(&sqlb.insertStmt)
closeStmt(&sqlb.updateStmt) closeStmt(&sqlb.updateStmt)
@ -174,21 +174,21 @@ func (sqlb *SqliteBackend) closeAll() error {
return closeDB(&sqlb.db) return closeDB(&sqlb.db)
} }
func (sqlb *SqliteBackend) Shutdown() error { func (sqlb *SQLiteBackend) Shutdown() error {
globalLock.Lock() globalLock.Lock()
defer globalLock.Unlock() defer globalLock.Unlock()
return sqlb.closeAll() return sqlb.closeAll()
} }
func (ss *SqliteSession) txStmt(stmt *sql.Stmt) *sql.Stmt { func (ss *SQLiteSession) txStmt(stmt *sql.Stmt) *sql.Stmt {
if ss.tx != nil { if ss.tx != nil {
return ss.tx.Stmt(stmt) return ss.tx.Stmt(stmt)
} }
return stmt return stmt
} }
func (ss *SqliteSession) Fetch(hash, key []byte) (data []byte, err error) { func (ss *SQLiteSession) Fetch(hash, key []byte) (data []byte, err error) {
var pos int64 var pos int64
if pos, err = ss.backend.decoder(key); err != nil { if pos, err = ss.backend.decoder(key); err != nil {
return return
@ -206,11 +206,11 @@ func (ss *SqliteSession) Fetch(hash, key []byte) (data []byte, err error) {
return return
} }
func (ss *SqliteSession) InTransaction() bool { func (ss *SQLiteSession) InTransaction() bool {
return ss.tx != nil return ss.tx != nil
} }
func (ss *SqliteSession) Store(hash, key, value []byte) (exists bool, err error) { func (ss *SQLiteSession) Store(hash, key, value []byte) (exists bool, err error) {
var pos int64 var pos int64
if pos, err = ss.backend.decoder(key); err != nil { if pos, err = ss.backend.decoder(key); err != nil {
return return
@ -257,7 +257,7 @@ func (ss *SqliteSession) Store(hash, key, value []byte) (exists bool, err error)
return return
} }
func (ss *SqliteSession) BeginTransaction() (err error) { func (ss *SQLiteSession) BeginTransaction() (err error) {
if ss.tx != nil { if ss.tx != nil {
log.Println("WARN: Already running transaction.") log.Println("WARN: Already running transaction.")
return nil return nil
@ -269,7 +269,7 @@ func (ss *SqliteSession) BeginTransaction() (err error) {
return return
} }
func (ss *SqliteSession) CommitTransaction() error { func (ss *SQLiteSession) CommitTransaction() error {
tx := ss.tx tx := ss.tx
if tx == nil { if tx == nil {
@ -283,7 +283,7 @@ func (ss *SqliteSession) CommitTransaction() error {
return tx.Commit() return tx.Commit()
} }
func (ss *SqliteSession) AllKeys( func (ss *SQLiteSession) AllKeys(
hash []byte, hash []byte,
done <-chan struct{}) (<-chan []byte, int, error) { done <-chan struct{}) (<-chan []byte, int, error) {
globalLock.RLock() globalLock.RLock()
@ -334,7 +334,7 @@ func (ss *SqliteSession) AllKeys(
return keys, n, nil return keys, n, nil
} }
func (ss *SqliteSession) SpatialQuery( func (ss *SQLiteSession) SpatialQuery(
hash, first, second []byte, hash, first, second []byte,
done <-chan struct{}) (<-chan Block, error) { done <-chan struct{}) (<-chan Block, error) {
@ -345,7 +345,7 @@ func (ss *SqliteSession) SpatialQuery(
return ss.plainSpatialQuery(first, second, done) return ss.plainSpatialQuery(first, second, done)
} }
func (ss *SqliteSession) interleavedSpatialQuery( func (ss *SQLiteSession) interleavedSpatialQuery(
first, second []byte, first, second []byte,
done <-chan struct{}) (<-chan Block, error) { done <-chan struct{}) (<-chan Block, error) {
@ -425,7 +425,7 @@ func (ss *SqliteSession) interleavedSpatialQuery(
return blocks, nil return blocks, nil
} }
func (ss *SqliteSession) plainSpatialQuery( func (ss *SQLiteSession) plainSpatialQuery(
first, second []byte, first, second []byte,
done <-chan struct{}) (<-chan Block, error) { done <-chan struct{}) (<-chan Block, error) {