forked from mirror/ledisdb
use mmap again, hope travis can pass
This commit is contained in:
parent
109468e0f3
commit
297c7c0592
|
@ -14,6 +14,10 @@
|
||||||
"Comment": "data/v1-228-g8fb50d5",
|
"Comment": "data/v1-228-g8fb50d5",
|
||||||
"Rev": "8fb50d5ee57110936b904a7539d4c5f2bf2359db"
|
"Rev": "8fb50d5ee57110936b904a7539d4c5f2bf2359db"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"ImportPath": "github.com/edsrzf/mmap-go",
|
||||||
|
"Rev": "6c75090c55983bef2e129e173681b20d24871ef8"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/siddontang/go/arena",
|
"ImportPath": "github.com/siddontang/go/arena",
|
||||||
"Rev": "ecf49fc0738105e87d20e29aa82c403b666ff0b4"
|
"Rev": "ecf49fc0738105e87d20e29aa82c403b666ff0b4"
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/edsrzf/mmap-go"
|
||||||
"github.com/siddontang/go/log"
|
"github.com/siddontang/go/log"
|
||||||
"github.com/siddontang/go/num"
|
"github.com/siddontang/go/num"
|
||||||
"github.com/siddontang/go/sync2"
|
"github.com/siddontang/go/sync2"
|
||||||
|
@ -43,6 +44,8 @@ type tableReader struct {
|
||||||
index int64
|
index int64
|
||||||
|
|
||||||
f *os.File
|
f *os.File
|
||||||
|
m mmap.MMap
|
||||||
|
|
||||||
pf *os.File
|
pf *os.File
|
||||||
|
|
||||||
first uint64
|
first uint64
|
||||||
|
@ -85,9 +88,9 @@ func (t *tableReader) Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tableReader) close() {
|
func (t *tableReader) close() {
|
||||||
if t.pf != nil {
|
if t.m != nil {
|
||||||
t.pf.Close()
|
t.m.Unmap()
|
||||||
t.pf = nil
|
t.m = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.f != nil {
|
if t.f != nil {
|
||||||
|
@ -106,15 +109,17 @@ func (t *tableReader) Keepalived() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tableReader) getLogPos(index int) (uint32, error) {
|
func (t *tableReader) getLogPos(index int) (uint32, error) {
|
||||||
if _, err := t.pf.Seek(t.offsetStartPos+int64(index*4), os.SEEK_SET); err != nil {
|
// if _, err := t.pf.Seek(t.offsetStartPos+int64(index*4), os.SEEK_SET); err != nil {
|
||||||
return 0, err
|
// return 0, err
|
||||||
}
|
// }
|
||||||
|
|
||||||
var pos uint32
|
// var pos uint32
|
||||||
if err := binary.Read(t.pf, binary.BigEndian, &pos); err != nil {
|
// if err := binary.Read(t.pf, binary.BigEndian, &pos); err != nil {
|
||||||
return 0, err
|
// return 0, err
|
||||||
}
|
// }
|
||||||
return pos, nil
|
// return pos, nil
|
||||||
|
|
||||||
|
return binary.BigEndian.Uint32(t.m[index*4:]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tableReader) check() error {
|
func (t *tableReader) check() error {
|
||||||
|
@ -162,7 +167,7 @@ func (t *tableReader) check() error {
|
||||||
return fmt.Errorf("invalid magic data %q", b)
|
return fmt.Errorf("invalid magic data %q", b)
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.pf, err = os.Open(t.name); err != nil {
|
if t.m, err = mmap.MapRegion(t.f, int(t.offsetLen), mmap.RDONLY, 0, t.offsetStartPos); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,8 +330,8 @@ func (t *tableReader) openTable() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.pf == nil {
|
if t.m == nil {
|
||||||
if t.pf, err = os.Open(t.name); err != nil {
|
if t.m, err = mmap.MapRegion(t.f, int(t.offsetLen), mmap.RDONLY, 0, t.offsetStartPos); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue