示例#1
0
func (ms *mmapStorage) WriteAt(p []byte, off int64) (n int, err error) {
	// err = fs.Lock(int(off), len(p))
	// if err != nil {
	// 	return 0, err
	// }
	// defer fs.Unlock(int(off), len(p))
	// return wrat(fs.fileHandle, p, off)//fs.f.WriteAt(p, off)
	if int(off)+len(p) >= ms.length {
		err = ms.Close()
		if err != nil {
			return 0, err
		}
		fStor := adapters.NewFileStorage(ms.name)
		err = fStor.Open()
		if err != nil {
			return 0, err
		}
		n, err = fStor.WriteAt(p, off)
		if err != nil {
			return 0, err
		}
		err = fStor.Close()
		if err != nil {
			return 0, err
		}
		err = ms.Open()
		if err != nil {
			return 0, err
		}
		return n, nil
	}
	return ms.mStor.WriteAt(p, off)
}
示例#2
0
func BenchmarkUpdateFileStorage(b *testing.B) {
	benchmarkUpdate(b, adapters.NewFileStorage(newTestFile("writebnch", b.N)))
}