don't try to truncate files when invoked read-only

This commit is contained in:
Seebs 2020-05-12 15:40:38 -05:00 • committed by Jaden Weiss
parent ceaf5c15d1
commit 7e7051d387
No known key found for this signature in database
GPG key ID: 177F065773634B67
2 changed files with 12 additions and 1 deletions

View file

@ -223,6 +223,9 @@ func (f *fragment) Open() error {
// get no data. It tries to write the current storage to the provided file,
// which is assumed to be the file they didn't get any data from.
func (f *fragment) emptyStorage(file *os.File) (bool, error) {
if f.holder.ReadOnly {
return false, errors.New("can't flush/create storage for read-only holder")
}
// No data. We'll mark this for no mapping, clear any existing
// mapped containers, and set the Source to nil. We also have no
// ops.
@ -276,7 +279,10 @@ func (f *fragment) importStorage(data []byte, file *os.File, newGen generation,
}
f.holder.Logger.Printf("warning: unmarshal storage, file=%s, err=%v", file.Name(), err)
trunc, ok := cause.(roaring.FileShouldBeTruncatedError)
if ok {
if ok && !f.holder.ReadOnly {
// if the holder is ReadOnly, we silently ignore the "advisory"
// error. This may be a bad idea.
// generation code looks for a FileShouldBeTruncatedError
return false, trunc
}

View file

@ -101,6 +101,11 @@ type Holder struct {
// needs to be queued and completed after all indexes
// have opened.
opening bool
// ReadOnly indicates that this holder's contents should not produce
// disk writes under any circumstances. It must be set before Open
// is called, and changing it is not supported.
ReadOnly bool
}
func (h *Holder) StartTransaction(ctx context.Context, id string, timeout time.Duration, exclusive bool) (*Transaction, error) {