From 3cd8af2c7d1cbb82b5733fc12c3b292fa1ee7e88 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 4 Jan 2013 20:20:41 -0800 Subject: [PATCH] schema: more incremental work on making FileReader faster Change-Id: I033df1654a062dfa57dfe0afce7030f605e88450 --- pkg/schema/filereader.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/schema/filereader.go b/pkg/schema/filereader.go index 01a942c04..3b45eba7c 100644 --- a/pkg/schema/filereader.go +++ b/pkg/schema/filereader.go @@ -173,6 +173,16 @@ func (sw *sliceWriter) Write(p []byte) (n int, err error) { var eofReader io.ReadCloser = ioutil.NopCloser(strings.NewReader("")) +func (fr *FileReader) getSuperset(br *blobref.BlobRef) (*Superset, error) { + // TODO: cache this. use a new pkg/cacher type. + rsc, _, err := fr.fetcher.Fetch(br) + if err != nil { + return nil, fmt.Errorf("schema/filereader: fetching file schema blob: %v", err) + } + defer rsc.Close() + return ParseSuperset(rsc) +} + // readerForOffset returns a ReadCloser that reads some number of bytes and then EOF // from the provided offset. Seeing EOF doesn't mean the end of the whole file; just the // chunk at that offset. The caller must close the ReadCloser when done reading. @@ -203,7 +213,16 @@ func (fr *FileReader) readerForOffset(off int64) (io.ReadCloser, error) { case p0.BlobRef != nil: rsc, _, err = fr.fetcher.Fetch(p0.BlobRef) case p0.BytesRef != nil: - rsc, err = NewFileReader(fr.fetcher, p0.BytesRef) + var ss *Superset + ss, err = fr.getSuperset(p0.BytesRef) + if err != nil { + return nil, err + } + rsc, err = ss.NewFileReader(fr.fetcher) + if err == nil && fr.readAll.Get() { + rsc.(*FileReader).readAll.Set(true) + // TODO: tell it to start faulting everything in + } } if err != nil { return nil, err