github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/store/nbs/chunk_source_adapter.go (about) 1 // Copyright 2019 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package nbs 16 17 type chunkSourceAdapter struct { 18 tableReader 19 h addr 20 } 21 22 func (csa chunkSourceAdapter) hash() (addr, error) { 23 return csa.h, nil 24 } 25 26 func newReaderFromIndexData(indexCache *indexCache, idxData []byte, name addr, tra tableReaderAt, blockSize uint64) (cs chunkSource, err error) { 27 index, err := parseTableIndex(idxData) 28 29 if err != nil { 30 return nil, err 31 } 32 33 if indexCache != nil { 34 indexCache.lockEntry(name) 35 defer func() { 36 unlockErr := indexCache.unlockEntry(name) 37 38 if err == nil { 39 err = unlockErr 40 } 41 }() 42 indexCache.put(name, index) 43 } 44 45 return &chunkSourceAdapter{newTableReader(index, tra, blockSize), name}, nil 46 } 47 48 func (csa chunkSourceAdapter) Close() error { 49 return csa.tableReader.Close() 50 } 51 52 func (csa chunkSourceAdapter) Clone() chunkSource { 53 return &chunkSourceAdapter{csa.tableReader.Clone(), csa.h} 54 }