github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/store/nbs/benchmarks/file_block_store.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 // This file incorporates work covered by the following copyright and 16 // permission notice: 17 // 18 // Copyright 2016 Attic Labs, Inc. All rights reserved. 19 // Licensed under the Apache License, version 2.0: 20 // http://www.apache.org/licenses/LICENSE-2.0 21 22 package main 23 24 import ( 25 "bufio" 26 "bytes" 27 "context" 28 "io" 29 30 "github.com/dustin/go-humanize" 31 32 "github.com/dolthub/dolt/go/store/chunks" 33 "github.com/dolthub/dolt/go/store/hash" 34 ) 35 36 type fileBlockStore struct { 37 bw *bufio.Writer 38 w io.WriteCloser 39 } 40 41 func newFileBlockStore(w io.WriteCloser) (chunks.ChunkStore, error) { 42 return fileBlockStore{bufio.NewWriterSize(w, humanize.MiByte), w}, nil 43 } 44 45 func (fb fileBlockStore) Get(ctx context.Context, h hash.Hash) (chunks.Chunk, error) { 46 panic("not impl") 47 } 48 49 func (fb fileBlockStore) GetMany(ctx context.Context, hashes hash.HashSet, found func(*chunks.Chunk)) error { 50 panic("not impl") 51 } 52 53 func (fb fileBlockStore) Has(ctx context.Context, h hash.Hash) (bool, error) { 54 panic("not impl") 55 } 56 57 func (fb fileBlockStore) HasMany(ctx context.Context, hashes hash.HashSet) (present hash.HashSet, err error) { 58 panic("not impl") 59 } 60 61 func (fb fileBlockStore) Put(ctx context.Context, c chunks.Chunk) error { 62 _, err := io.Copy(fb.bw, bytes.NewReader(c.Data())) 63 return err 64 } 65 66 func (fb fileBlockStore) Version() string { 67 panic("not impl") 68 } 69 70 func (fb fileBlockStore) Close() error { 71 fb.w.Close() 72 return nil 73 } 74 75 func (fb fileBlockStore) Rebase(ctx context.Context) error { 76 return nil 77 } 78 79 func (fb fileBlockStore) Stats() interface{} { 80 return nil 81 } 82 83 func (fb fileBlockStore) StatsSummary() string { 84 return "Unsupported" 85 } 86 87 func (fb fileBlockStore) Root(ctx context.Context) (hash.Hash, error) { 88 return hash.Hash{}, nil 89 } 90 91 func (fb fileBlockStore) Commit(ctx context.Context, current, last hash.Hash) (bool, error) { 92 err := fb.bw.Flush() 93 return true, err 94 }