manually compute size when badger is being stupid
This commit is contained in:
		
							parent
							
								
									74009bd67f
								
							
						
					
					
						commit
						2cfd73c879
					
				| @ -4,6 +4,8 @@ import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"runtime" | ||||
| 	"sync" | ||||
| 
 | ||||
| @ -84,7 +86,8 @@ type Blockstore struct { | ||||
| 	state   int | ||||
| 	viewers sync.WaitGroup | ||||
| 
 | ||||
| 	DB *badger.DB | ||||
| 	DB   *badger.DB | ||||
| 	opts Options | ||||
| 
 | ||||
| 	prefixing bool | ||||
| 	prefix    []byte | ||||
| @ -110,7 +113,7 @@ func Open(opts Options) (*Blockstore, error) { | ||||
| 		return nil, fmt.Errorf("failed to open badger blockstore: %w", err) | ||||
| 	} | ||||
| 
 | ||||
| 	bs := &Blockstore{DB: db} | ||||
| 	bs := &Blockstore{DB: db, opts: opts} | ||||
| 	if p := opts.Prefix; p != "" { | ||||
| 		bs.prefixing = true | ||||
| 		bs.prefix = []byte(p) | ||||
| @ -200,7 +203,27 @@ func (b *Blockstore) Size() (int64, error) { | ||||
| 	defer b.viewers.Done() | ||||
| 
 | ||||
| 	lsm, vlog := b.DB.Size() | ||||
| 	return lsm + vlog, nil | ||||
| 	size := lsm + vlog | ||||
| 
 | ||||
| 	if size == 0 { | ||||
| 		// badger reports a 0 size on symlinked directories... sigh
 | ||||
| 		dir := b.opts.Dir | ||||
| 		entries, err := os.ReadDir(dir) | ||||
| 		if err != nil { | ||||
| 			return 0, err | ||||
| 		} | ||||
| 
 | ||||
| 		for _, e := range entries { | ||||
| 			path := filepath.Join(dir, e.Name()) | ||||
| 			finfo, err := os.Stat(path) | ||||
| 			if err != nil { | ||||
| 				return 0, err | ||||
| 			} | ||||
| 			size += finfo.Size() | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return size, nil | ||||
| } | ||||
| 
 | ||||
| // View implements blockstore.Viewer, which leverages zero-copy read-only
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user