mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 17:20:18 +01:00
Added a few more comments to mtredisalize and unexport a few symbols.
This commit is contained in:
parent
7ac3c67e63
commit
4dc43881c6
@ -5,24 +5,39 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
type (
|
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 {
|
Block struct {
|
||||||
Key []byte
|
Key []byte
|
||||||
Data []byte
|
Data []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Session is a database session.
|
||||||
Session interface {
|
Session interface {
|
||||||
|
// Fetch fetches the block data for a given position.
|
||||||
Fetch(hash, key []byte) ([]byte, error)
|
Fetch(hash, key []byte) ([]byte, error)
|
||||||
|
// InTransaction returns true if a transaction is running.
|
||||||
InTransaction() bool
|
InTransaction() bool
|
||||||
|
// Store stores a block with a given position and data.
|
||||||
Store(hash, key, value []byte) (bool, error)
|
Store(hash, key, value []byte) (bool, error)
|
||||||
|
// AllKeys returns all keys in the database.
|
||||||
AllKeys(hash []byte, done chan struct{}) (chan []byte, int, error)
|
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)
|
SpatialQuery(hash, first, second []byte, done chan struct{}) (chan Block, error)
|
||||||
|
// BeginTransaction starts a transcation.
|
||||||
BeginTransaction() error
|
BeginTransaction() error
|
||||||
|
// CommitTransaction finishes a transaction.
|
||||||
CommitTransaction() error
|
CommitTransaction() error
|
||||||
|
// Close closes the database session.
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Backend is interface representing a database.
|
||||||
Backend interface {
|
Backend interface {
|
||||||
|
// NewSession opens a new session.
|
||||||
NewSession() (Session, error)
|
NewSession() (Session, error)
|
||||||
|
// Shutdown shuts down the database server.
|
||||||
Shutdown() error
|
Shutdown() error
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -22,16 +22,16 @@ type quantizedXZ struct {
|
|||||||
X, Z int16
|
X, Z int16
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChangeTracker struct {
|
type changeTracker struct {
|
||||||
changes map[quantizedXZ]bool
|
changes map[quantizedXZ]bool
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChangeTracker() *ChangeTracker {
|
func newChangeTracker() *changeTracker {
|
||||||
return &ChangeTracker{changes: make(map[quantizedXZ]bool)}
|
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.mutex.Lock()
|
||||||
ct.changes[quantizedXZ{
|
ct.changes[quantizedXZ{
|
||||||
X: coord.X / quantizationFactor,
|
X: coord.X / quantizationFactor,
|
||||||
@ -39,7 +39,7 @@ func (ct *ChangeTracker) BlockChanged(coord common.Coord) {
|
|||||||
ct.mutex.Unlock()
|
ct.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ct *ChangeTracker) FlushChanges(url string) {
|
func (ct *changeTracker) FlushChanges(url string) {
|
||||||
var oldChanges map[quantizedXZ]bool
|
var oldChanges map[quantizedXZ]bool
|
||||||
ct.mutex.Lock()
|
ct.mutex.Lock()
|
||||||
if len(ct.changes) > 0 {
|
if len(ct.changes) > 0 {
|
||||||
|
@ -21,7 +21,7 @@ type LevelDBBackend struct {
|
|||||||
encoder common.KeyTranscoder
|
encoder common.KeyTranscoder
|
||||||
decoder common.KeyTranscoder
|
decoder common.KeyTranscoder
|
||||||
|
|
||||||
changeTracker *ChangeTracker
|
changeTracker *changeTracker
|
||||||
mutex sync.RWMutex
|
mutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ type LevelDBSession struct {
|
|||||||
|
|
||||||
func NewLeveDBBackend(
|
func NewLeveDBBackend(
|
||||||
path string,
|
path string,
|
||||||
changeTracker *ChangeTracker,
|
changeTracker *changeTracker,
|
||||||
interleaved bool,
|
interleaved bool,
|
||||||
cacheSize int) (ldb *LevelDBBackend, err error) {
|
cacheSize int) (ldb *LevelDBBackend, err error) {
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
defaultMaxBulkStringSize = 32 * 1024 * 1024
|
defaultMaxBulkStringSize = 32 * 1024 * 1024
|
||||||
GCDuration = "24h"
|
defaultGCDuration = "24h"
|
||||||
ChangeDuration = "30s"
|
defaultChangeDuration = "30s"
|
||||||
)
|
)
|
||||||
|
|
||||||
func usage() {
|
func usage() {
|
||||||
@ -55,9 +55,9 @@ func main() {
|
|||||||
flag.BoolVar(&interleaved,
|
flag.BoolVar(&interleaved,
|
||||||
"interleaved", false, "Backend stores key in interleaved form.")
|
"interleaved", false, "Backend stores key in interleaved form.")
|
||||||
flag.StringVar(&gcDuration,
|
flag.StringVar(&gcDuration,
|
||||||
"gc-duration", GCDuration, "Duration between forced GCs.")
|
"gc-duration", defaultGCDuration, "Duration between forced GCs.")
|
||||||
flag.StringVar(&changeDuration,
|
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.StringVar(&changeURL, "change-url", "", "URL to send changes to.")
|
||||||
flag.Int64Var(&maxBulkStringSize, "max-bulk-string-size", defaultMaxBulkStringSize,
|
flag.Int64Var(&maxBulkStringSize, "max-bulk-string-size", defaultMaxBulkStringSize,
|
||||||
"max size of a bulk string to be accepted as input (in bytes).")
|
"max size of a bulk string to be accepted as input (in bytes).")
|
||||||
@ -76,7 +76,7 @@ func main() {
|
|||||||
backend Backend
|
backend Backend
|
||||||
gcDur time.Duration
|
gcDur time.Duration
|
||||||
chDur time.Duration
|
chDur time.Duration
|
||||||
changeTracker *ChangeTracker
|
changeTracker *changeTracker
|
||||||
)
|
)
|
||||||
|
|
||||||
if gcDur, err = time.ParseDuration(gcDuration); err != nil {
|
if gcDur, err = time.ParseDuration(gcDuration); err != nil {
|
||||||
@ -94,7 +94,7 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
changeChan = time.Tick(chDur)
|
changeChan = time.Tick(chDur)
|
||||||
changeTracker = NewChangeTracker()
|
changeTracker = newChangeTracker()
|
||||||
} else {
|
} else {
|
||||||
// We will never receive ticks on this.
|
// We will never receive ticks on this.
|
||||||
changeChan = make(<-chan time.Time)
|
changeChan = make(<-chan time.Time)
|
||||||
|
@ -30,7 +30,7 @@ type SqliteBackend struct {
|
|||||||
db *sql.DB
|
db *sql.DB
|
||||||
encoder common.KeyEncoder
|
encoder common.KeyEncoder
|
||||||
decoder common.KeyDecoder
|
decoder common.KeyDecoder
|
||||||
changeTracker *ChangeTracker
|
changeTracker *changeTracker
|
||||||
interleaved bool
|
interleaved bool
|
||||||
coverage *common.Coverage3D
|
coverage *common.Coverage3D
|
||||||
existsStmt *sql.Stmt
|
existsStmt *sql.Stmt
|
||||||
@ -62,7 +62,7 @@ func (ss *SqliteSession) Close() error {
|
|||||||
|
|
||||||
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}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user