Added a few more comments to mtredisalize and unexport a few symbols.

This commit is contained in:
Sascha L. Teichmann 2016-04-24 19:41:15 +02:00
parent 7ac3c67e63
commit 4dc43881c6
5 changed files with 30 additions and 15 deletions

View File

@ -5,24 +5,39 @@
package main
type (
// Block is the essential transfer unit from to the database.
// Key is the serialized spatial position.
// Data is the serialized from of the corresponding block data.
Block struct {
Key []byte
Data []byte
}
// Session is a database session.
Session interface {
// Fetch fetches the block data for a given position.
Fetch(hash, key []byte) ([]byte, error)
// InTransaction returns true if a transaction is running.
InTransaction() bool
// Store stores a block with a given position and data.
Store(hash, key, value []byte) (bool, error)
// AllKeys returns all keys in the database.
AllKeys(hash []byte, done chan struct{}) (chan []byte, int, error)
// SpatialQuery performs a box query between the positions first and second.
SpatialQuery(hash, first, second []byte, done chan struct{}) (chan Block, error)
// BeginTransaction starts a transcation.
BeginTransaction() error
// CommitTransaction finishes a transaction.
CommitTransaction() error
// Close closes the database session.
Close() error
}
// Backend is interface representing a database.
Backend interface {
// NewSession opens a new session.
NewSession() (Session, error)
// Shutdown shuts down the database server.
Shutdown() error
}
)

View File

@ -22,16 +22,16 @@ type quantizedXZ struct {
X, Z int16
}
type ChangeTracker struct {
type changeTracker struct {
changes map[quantizedXZ]bool
mutex sync.Mutex
}
func NewChangeTracker() *ChangeTracker {
return &ChangeTracker{changes: make(map[quantizedXZ]bool)}
func newChangeTracker() *changeTracker {
return &changeTracker{changes: make(map[quantizedXZ]bool)}
}
func (ct *ChangeTracker) BlockChanged(coord common.Coord) {
func (ct *changeTracker) BlockChanged(coord common.Coord) {
ct.mutex.Lock()
ct.changes[quantizedXZ{
X: coord.X / quantizationFactor,
@ -39,7 +39,7 @@ func (ct *ChangeTracker) BlockChanged(coord common.Coord) {
ct.mutex.Unlock()
}
func (ct *ChangeTracker) FlushChanges(url string) {
func (ct *changeTracker) FlushChanges(url string) {
var oldChanges map[quantizedXZ]bool
ct.mutex.Lock()
if len(ct.changes) > 0 {

View File

@ -21,7 +21,7 @@ type LevelDBBackend struct {
encoder common.KeyTranscoder
decoder common.KeyTranscoder
changeTracker *ChangeTracker
changeTracker *changeTracker
mutex sync.RWMutex
}
@ -32,7 +32,7 @@ type LevelDBSession struct {
func NewLeveDBBackend(
path string,
changeTracker *ChangeTracker,
changeTracker *changeTracker,
interleaved bool,
cacheSize int) (ldb *LevelDBBackend, err error) {

View File

@ -19,8 +19,8 @@ import (
const (
defaultMaxBulkStringSize = 32 * 1024 * 1024
GCDuration = "24h"
ChangeDuration = "30s"
defaultGCDuration = "24h"
defaultChangeDuration = "30s"
)
func usage() {
@ -55,9 +55,9 @@ func main() {
flag.BoolVar(&interleaved,
"interleaved", false, "Backend stores key in interleaved form.")
flag.StringVar(&gcDuration,
"gc-duration", GCDuration, "Duration between forced GCs.")
"gc-duration", defaultGCDuration, "Duration between forced GCs.")
flag.StringVar(&changeDuration,
"change-duration", ChangeDuration, "Duration to aggregate changes.")
"change-duration", defaultChangeDuration, "Duration to aggregate changes.")
flag.StringVar(&changeURL, "change-url", "", "URL to send changes to.")
flag.Int64Var(&maxBulkStringSize, "max-bulk-string-size", defaultMaxBulkStringSize,
"max size of a bulk string to be accepted as input (in bytes).")
@ -76,7 +76,7 @@ func main() {
backend Backend
gcDur time.Duration
chDur time.Duration
changeTracker *ChangeTracker
changeTracker *changeTracker
)
if gcDur, err = time.ParseDuration(gcDuration); err != nil {
@ -94,7 +94,7 @@ func main() {
log.Fatal(err)
}
changeChan = time.Tick(chDur)
changeTracker = NewChangeTracker()
changeTracker = newChangeTracker()
} else {
// We will never receive ticks on this.
changeChan = make(<-chan time.Time)

View File

@ -30,7 +30,7 @@ type SqliteBackend struct {
db *sql.DB
encoder common.KeyEncoder
decoder common.KeyDecoder
changeTracker *ChangeTracker
changeTracker *changeTracker
interleaved bool
coverage *common.Coverage3D
existsStmt *sql.Stmt
@ -62,7 +62,7 @@ func (ss *SqliteSession) Close() error {
func NewSqliteBackend(
path string,
changeTracker *ChangeTracker, interleaved bool) (sqlb *SqliteBackend, err error) {
changeTracker *changeTracker, interleaved bool) (sqlb *SqliteBackend, err error) {
res := SqliteBackend{interleaved: interleaved, changeTracker: changeTracker}