mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-11 17:30:18 +01:00
Enabaled interleaving in SQLite backend.
This commit is contained in:
parent
8cd23d257f
commit
5094f05414
7
main.go
7
main.go
@ -30,6 +30,7 @@ func main() {
|
|||||||
driver string
|
driver string
|
||||||
cacheSize int
|
cacheSize int
|
||||||
version bool
|
version bool
|
||||||
|
interleaved bool
|
||||||
gcDuration string
|
gcDuration string
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ func main() {
|
|||||||
flag.StringVar(&host, "host", "", "host to bind")
|
flag.StringVar(&host, "host", "", "host to bind")
|
||||||
flag.IntVar(&cacheSize, "cache", 32, "cache size in MB")
|
flag.IntVar(&cacheSize, "cache", 32, "cache size in MB")
|
||||||
flag.BoolVar(&version, "version", false, "Print version and exit.")
|
flag.BoolVar(&version, "version", false, "Print version and exit.")
|
||||||
|
flag.BoolVar(&interleaved, "interleaved", false, "Backend stores key in interleaved form.")
|
||||||
flag.StringVar(&gcDuration, "gc-duration", GCDuration, "Duration between forced GCs.")
|
flag.StringVar(&gcDuration, "gc-duration", GCDuration, "Duration between forced GCs.")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@ -63,10 +65,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if driver == "sqlite" {
|
if driver == "sqlite" {
|
||||||
if backend, err = NewSqliteBackend(
|
if backend, err = NewSqliteBackend(args[0], interleaved); err != nil {
|
||||||
args[0],
|
|
||||||
common.EncodeStringToBytes,
|
|
||||||
common.DecodeStringFromBytes); err != nil {
|
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
17
sqlite.go
17
sqlite.go
@ -29,6 +29,7 @@ type SqliteBackend struct {
|
|||||||
db *sql.DB
|
db *sql.DB
|
||||||
encoder common.KeyEncoder
|
encoder common.KeyEncoder
|
||||||
decoder common.KeyDecoder
|
decoder common.KeyDecoder
|
||||||
|
interleaved bool
|
||||||
existsStmt *sql.Stmt
|
existsStmt *sql.Stmt
|
||||||
fetchStmt *sql.Stmt
|
fetchStmt *sql.Stmt
|
||||||
insertStmt *sql.Stmt
|
insertStmt *sql.Stmt
|
||||||
@ -55,12 +56,9 @@ func (ss *SqliteSession) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSqliteBackend(
|
func NewSqliteBackend(path string, interleaved bool) (sqlb *SqliteBackend, err error) {
|
||||||
path string,
|
|
||||||
encoder common.KeyEncoder,
|
|
||||||
decoder common.KeyDecoder) (sqlb *SqliteBackend, err error) {
|
|
||||||
|
|
||||||
res := SqliteBackend{}
|
res := SqliteBackend{interleaved: interleaved}
|
||||||
|
|
||||||
if res.db, err = sql.Open("sqlite3", path); err != nil {
|
if res.db, err = sql.Open("sqlite3", path); err != nil {
|
||||||
return
|
return
|
||||||
@ -96,8 +94,13 @@ func NewSqliteBackend(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res.encoder = encoder
|
if interleaved {
|
||||||
res.decoder = decoder
|
res.encoder = common.EncodeStringToBytes
|
||||||
|
res.decoder = common.DecodeStringFromBytes
|
||||||
|
} else {
|
||||||
|
res.encoder = common.EncodeStringToBytesFromInterleaved
|
||||||
|
res.decoder = common.DecodeStringFromBytesToInterleaved
|
||||||
|
}
|
||||||
|
|
||||||
sqlb = &res
|
sqlb = &res
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user