goleveldb icon indicating copy to clipboard operation
goleveldb copied to clipboard

OpenFile() with &Opts{ReadOnly: true} returns leveldb/storage: storage is read-only

Open alessio opened this issue 5 years ago • 7 comments

Hi,

This is an excerpt of my wrapper function:

func NewGoLevelDBWithOpts(name string, dir string, o *opt.Options) (*GoLevelDB, error) {
	dbPath := filepath.Join(dir, name+".db")
	db, err := leveldb.OpenFile(dbPath, o)
	if err != nil {
		return nil, err
	}
	database := &GoLevelDB{
		db: db,
	}
	return database, nil
}

When I pass &Opts{ReadOnly: true} to the function, it returns nil, error. The error in particular complains about the storage being read-only, which is incidentally what I asked for by setting ReadOnly to true.

Thanks for considering.

alessio avatar Nov 01 '18 14:11 alessio

@syndtr it'd be nice if you could have a look

alessio avatar Nov 01 '18 14:11 alessio

How is this PR going? Is there ETA that goleveldb owner will merge it? Thanks!

ackratos avatar Dec 04 '18 02:12 ackratos

What PR?

syndtr avatar Dec 04 '18 02:12 syndtr

I've had make changes on f908035 but have yet to have time to verify whether that fixed the issue or investigate whether they're other bug that cause thus. @alessio let me know whether f908035 fix this or not? Thanks!

syndtr avatar Dec 04 '18 02:12 syndtr

yes I mean this commit https://github.com/syndtr/goleveldb/commit/f9080354173f192dfc8821931eacf9cfd6819253

ackratos avatar Dec 04 '18 05:12 ackratos

No, f908035 doesn't fix this

alessio avatar Dec 04 '18 08:12 alessio

@syndtr if ReadOnly is true and the path of db is empty ( or no CURRENT and MANIFEST), the fileStorage still tries to create a MANIFEST by calling Create and causes the issue. I've commit a pr (https://github.com/syndtr/goleveldb/pull/250) to fix this but I think the implement is kind of twisted.

Fullstop000 avatar Dec 08 '18 04:12 Fullstop000