mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-25 15:40:22 +01:00
Made mtdbconverter pass golint by adding the missing comments.
This commit is contained in:
parent
67a16e2d3e
commit
7ac3c67e63
@ -13,6 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// LevelDBBlockProducer is a helper to fetch blocks from a LevelDB.
|
||||||
LevelDBBlockProducer struct {
|
LevelDBBlockProducer struct {
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
opts *leveldb.Options
|
opts *leveldb.Options
|
||||||
@ -22,6 +23,7 @@ type (
|
|||||||
decoder common.KeyDecoder
|
decoder common.KeyDecoder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LevelDBBlockConsumer is a helper to store blocks in a LevelDB.
|
||||||
LevelDBBlockConsumer struct {
|
LevelDBBlockConsumer struct {
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
opts *leveldb.Options
|
opts *leveldb.Options
|
||||||
@ -31,6 +33,7 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewLevelDBBlockProducer returns a new helper to fetch blocks from a LevelDB.
|
||||||
func NewLevelDBBlockProducer(path string,
|
func NewLevelDBBlockProducer(path string,
|
||||||
splitter common.KeySplitter,
|
splitter common.KeySplitter,
|
||||||
decoder common.KeyDecoder) (ldbp *LevelDBBlockProducer, err error) {
|
decoder common.KeyDecoder) (ldbp *LevelDBBlockProducer, err error) {
|
||||||
@ -65,6 +68,7 @@ func NewLevelDBBlockProducer(path string,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes a helper to fetch blocks from a LevelDB.
|
||||||
func (ldbp *LevelDBBlockProducer) Close() error {
|
func (ldbp *LevelDBBlockProducer) Close() error {
|
||||||
if ldbp.iterator != nil {
|
if ldbp.iterator != nil {
|
||||||
ldbp.iterator.Close()
|
ldbp.iterator.Close()
|
||||||
@ -75,6 +79,7 @@ func (ldbp *LevelDBBlockProducer) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next fetches the next block from a LevelDB.
|
||||||
func (ldbp *LevelDBBlockProducer) Next(block *common.Block) (err error) {
|
func (ldbp *LevelDBBlockProducer) Next(block *common.Block) (err error) {
|
||||||
if ldbp.iterator == nil {
|
if ldbp.iterator == nil {
|
||||||
err = common.ErrNoMoreBlocks
|
err = common.ErrNoMoreBlocks
|
||||||
@ -98,6 +103,7 @@ func (ldbp *LevelDBBlockProducer) Next(block *common.Block) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewLevelDBBlockConsumer returns a new helper to store blocks in a LevelDB.
|
||||||
func NewLevelDBBlockConsumer(
|
func NewLevelDBBlockConsumer(
|
||||||
path string,
|
path string,
|
||||||
joiner common.KeyJoiner,
|
joiner common.KeyJoiner,
|
||||||
@ -120,6 +126,7 @@ func NewLevelDBBlockConsumer(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes a helper to store blocks in a LevelDB.
|
||||||
func (ldbc *LevelDBBlockConsumer) Close() error {
|
func (ldbc *LevelDBBlockConsumer) Close() error {
|
||||||
ldbc.wo.Close()
|
ldbc.wo.Close()
|
||||||
ldbc.db.Close()
|
ldbc.db.Close()
|
||||||
@ -127,6 +134,7 @@ func (ldbc *LevelDBBlockConsumer) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Consume stores a block in LevelDB.
|
||||||
func (ldbc *LevelDBBlockConsumer) Consume(block *common.Block) (err error) {
|
func (ldbc *LevelDBBlockConsumer) Consume(block *common.Block) (err error) {
|
||||||
var encodedKey []byte
|
var encodedKey []byte
|
||||||
if encodedKey, err = ldbc.encoder(ldbc.joiner(block.Coord)); err != nil {
|
if encodedKey, err = ldbc.encoder(ldbc.joiner(block.Coord)); err != nil {
|
||||||
|
@ -21,17 +21,20 @@ const (
|
|||||||
selectSQL = "SELECT pos, data FROM blocks"
|
selectSQL = "SELECT pos, data FROM blocks"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrDatabaseNotExists indicates that the database does not exist.
|
||||||
var ErrDatabaseNotExists = errors.New("Database does not exists.")
|
var ErrDatabaseNotExists = errors.New("Database does not exists.")
|
||||||
|
|
||||||
const blocksPerTx = 128
|
const blocksPerTx = 128 // Number of blocks copied in a transaction.
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// SQLiteBlockProducer helps getting blocks from a SQLite database.
|
||||||
SQLiteBlockProducer struct {
|
SQLiteBlockProducer struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
rows *sql.Rows
|
rows *sql.Rows
|
||||||
splitter common.KeySplitter
|
splitter common.KeySplitter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SQLiteBlockConsumer helps storing blocks into a SQLite database.
|
||||||
SQLiteBlockConsumer struct {
|
SQLiteBlockConsumer struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
insertStmt *sql.Stmt
|
insertStmt *sql.Stmt
|
||||||
@ -46,6 +49,7 @@ func fileExists(path string) bool {
|
|||||||
return !os.IsNotExist(err)
|
return !os.IsNotExist(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewSQLiteBlockConsumer returns a storage helper for SQLite databases.
|
||||||
func NewSQLiteBlockConsumer(
|
func NewSQLiteBlockConsumer(
|
||||||
path string,
|
path string,
|
||||||
joiner common.KeyJoiner) (sbc *SQLiteBlockConsumer, err error) {
|
joiner common.KeyJoiner) (sbc *SQLiteBlockConsumer, err error) {
|
||||||
@ -91,6 +95,7 @@ func NewSQLiteBlockConsumer(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes a SQLite storage helper.
|
||||||
func (sbc *SQLiteBlockConsumer) Close() error {
|
func (sbc *SQLiteBlockConsumer) Close() error {
|
||||||
sbc.tx.Commit()
|
sbc.tx.Commit()
|
||||||
sbc.insertStmt.Close()
|
sbc.insertStmt.Close()
|
||||||
@ -112,6 +117,7 @@ func (sbc *SQLiteBlockConsumer) getTx() (tx *sql.Tx, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Consume stores a block in an SQLite database.
|
||||||
func (sbc *SQLiteBlockConsumer) Consume(block *common.Block) (err error) {
|
func (sbc *SQLiteBlockConsumer) Consume(block *common.Block) (err error) {
|
||||||
var tx *sql.Tx
|
var tx *sql.Tx
|
||||||
if tx, err = sbc.getTx(); err != nil {
|
if tx, err = sbc.getTx(); err != nil {
|
||||||
@ -121,6 +127,8 @@ func (sbc *SQLiteBlockConsumer) Consume(block *common.Block) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewSQLiteBlockProducer returns a new producer to fetch blocks from a
|
||||||
|
// SQLite database.
|
||||||
func NewSQLiteBlockProducer(
|
func NewSQLiteBlockProducer(
|
||||||
path string,
|
path string,
|
||||||
splitter common.KeySplitter) (sbp *SQLiteBlockProducer, err error) {
|
splitter common.KeySplitter) (sbp *SQLiteBlockProducer, err error) {
|
||||||
@ -149,6 +157,7 @@ func NewSQLiteBlockProducer(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next fetches the next block from a SQLite database.
|
||||||
func (sbp *SQLiteBlockProducer) Next(block *common.Block) (err error) {
|
func (sbp *SQLiteBlockProducer) Next(block *common.Block) (err error) {
|
||||||
if sbp.rows == nil {
|
if sbp.rows == nil {
|
||||||
err = common.ErrNoMoreBlocks
|
err = common.ErrNoMoreBlocks
|
||||||
@ -167,6 +176,7 @@ func (sbp *SQLiteBlockProducer) Next(block *common.Block) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes a block producer from a SQLite database.
|
||||||
func (sbp *SQLiteBlockProducer) Close() error {
|
func (sbp *SQLiteBlockProducer) Close() error {
|
||||||
if sbp.rows != nil {
|
if sbp.rows != nil {
|
||||||
sbp.rows.Close()
|
sbp.rows.Close()
|
||||||
|
Loading…
Reference in New Issue
Block a user