|
|
@ -11,11 +11,17 @@ import ( |
|
|
|
|
|
|
|
// walks through the index file, calls fn function with each key, offset, size
|
|
|
|
// stops with the error returned by the fn function
|
|
|
|
func WalkIndexFile(r *os.File, fn func(key types.NeedleId, offset types.Offset, size uint32) error) error { |
|
|
|
func WalkIndexFile(r io.ReaderAt, fn func(key types.NeedleId, offset types.Offset, size uint32) error) error { |
|
|
|
var readerOffset int64 |
|
|
|
bytes := make([]byte, types.NeedleMapEntrySize*RowsToRead) |
|
|
|
count, e := r.ReadAt(bytes, readerOffset) |
|
|
|
glog.V(3).Infoln("file", r.Name(), "readerOffset", readerOffset, "count", count, "e", e) |
|
|
|
var name string |
|
|
|
if f, ok := r.(*os.File); ok { |
|
|
|
name = f.Name() |
|
|
|
} else { |
|
|
|
name = "memory" |
|
|
|
} |
|
|
|
glog.V(3).Infoln("file", name, "readerOffset", readerOffset, "count", count, "e", e) |
|
|
|
readerOffset += int64(count) |
|
|
|
var ( |
|
|
|
key types.NeedleId |
|
|
@ -35,7 +41,7 @@ func WalkIndexFile(r *os.File, fn func(key types.NeedleId, offset types.Offset, |
|
|
|
return nil |
|
|
|
} |
|
|
|
count, e = r.ReadAt(bytes, readerOffset) |
|
|
|
glog.V(3).Infoln("file", r.Name(), "readerOffset", readerOffset, "count", count, "e", e) |
|
|
|
glog.V(3).Infoln("file", name, "readerOffset", readerOffset, "count", count, "e", e) |
|
|
|
readerOffset += int64(count) |
|
|
|
} |
|
|
|
return e |
|
|
|