diff --git a/weed/storage/memory_map/memory_map.go b/weed/storage/memory_map/memory_map.go index e8d3de6e0..4baf6fc1f 100644 --- a/weed/storage/memory_map/memory_map.go +++ b/weed/storage/memory_map/memory_map.go @@ -33,10 +33,10 @@ func (mMap *MemoryMap) ReadMemory(offset uint64, length uint64) (MemoryBuffer, e return MemoryBuffer{}, fmt.Errorf("Memory Map not implemented for this platform") } -func (mem_buffer *MemoryBuffer) ReleaseMemory() { +func (mBuffer *MemoryBuffer) ReleaseMemory() { } -func (mMap *MemoryMap) DeleteFileAndMemoryMap() { +func (mBuffer *MemoryMap) DeleteFileAndMemoryMap() { } diff --git a/weed/storage/memory_map/memory_map_windows.go b/weed/storage/memory_map/memory_map_windows.go index c5deef84a..58ebcea22 100644 --- a/weed/storage/memory_map/memory_map_windows.go +++ b/weed/storage/memory_map/memory_map_windows.go @@ -119,29 +119,29 @@ func (mMap *MemoryMap) ReadMemory(offset uint64, length uint64) (MemoryBuffer, e return allocate(windows.Handle(mMap.file_memory_map_handle), offset, length, false) } -func (mem_buffer *MemoryBuffer) ReleaseMemory() { - windows.UnmapViewOfFile(mem_buffer.aligned_ptr) - - mem_buffer.ptr = 0 - mem_buffer.aligned_ptr = 0 - mem_buffer.length = 0 - mem_buffer.aligned_length = 0 - mem_buffer.Buffer = nil +func (mBuffer *MemoryBuffer) ReleaseMemory() { + windows.UnmapViewOfFile(mBuffer.aligned_ptr) + + mBuffer.ptr = 0 + mBuffer.aligned_ptr = 0 + mBuffer.length = 0 + mBuffer.aligned_length = 0 + mBuffer.Buffer = nil } func allocateChunk(mMap *MemoryMap) { start := uint64(len(mMap.write_map_views)) * chunk_size - mem_buffer, err := allocate(windows.Handle(mMap.file_memory_map_handle), start, chunk_size, true) + mBuffer, err := allocate(windows.Handle(mMap.file_memory_map_handle), start, chunk_size, true) if err == nil { - mMap.write_map_views = append(mMap.write_map_views, mem_buffer) + mMap.write_map_views = append(mMap.write_map_views, mBuffer) } } func allocate(hMapFile windows.Handle, offset uint64, length uint64, write bool) (MemoryBuffer, error) { - mem_buffer := MemoryBuffer{} + mBuffer := MemoryBuffer{} dwSysGran := system_info.dwAllocationGranularity @@ -165,20 +165,20 @@ func allocate(hMapFile windows.Handle, offset uint64, length uint64, write bool) uintptr(aligned_length)) if addr_ptr == 0 { - return mem_buffer, errno + return mBuffer, errno } - mem_buffer.aligned_ptr = addr_ptr - mem_buffer.aligned_length = aligned_length - mem_buffer.ptr = addr_ptr + uintptr(diff) - mem_buffer.length = length + mBuffer.aligned_ptr = addr_ptr + mBuffer.aligned_length = aligned_length + mBuffer.ptr = addr_ptr + uintptr(diff) + mBuffer.length = length - slice_header := (*reflect.SliceHeader)(unsafe.Pointer(&mem_buffer.Buffer)) + slice_header := (*reflect.SliceHeader)(unsafe.Pointer(&mBuffer.Buffer)) slice_header.Data = addr_ptr + uintptr(diff) slice_header.Len = int(length) slice_header.Cap = int(length) - return mem_buffer, nil + return mBuffer, nil } // typedef struct _SYSTEM_INFO { diff --git a/weed/storage/needle/needle_read_write.go b/weed/storage/needle/needle_read_write.go index 23a192543..c942af206 100644 --- a/weed/storage/needle/needle_read_write.go +++ b/weed/storage/needle/needle_read_write.go @@ -291,9 +291,9 @@ func ReadNeedleHeader(r *os.File, version Version, offset int64) (n *Needle, byt mMap, exists := memory_map.FileMemoryMap[r.Name()] if exists { - mem_buffer, err := mMap.ReadMemory(uint64(offset), NeedleHeaderSize) - copy(bytes, mem_buffer.Buffer) - mem_buffer.ReleaseMemory() + mBuffer, err := mMap.ReadMemory(uint64(offset), NeedleHeaderSize) + copy(bytes, mBuffer.Buffer) + mBuffer.ReleaseMemory() if err != nil { return nil, bytes, 0, err diff --git a/weed/storage/volume_super_block.go b/weed/storage/volume_super_block.go index f93c43fbf..20a223f7d 100644 --- a/weed/storage/volume_super_block.go +++ b/weed/storage/volume_super_block.go @@ -113,13 +113,13 @@ func ReadSuperBlock(dataFile *os.File) (superBlock SuperBlock, err error) { header := make([]byte, _SuperBlockSize) mMap, exists := memory_map.FileMemoryMap[dataFile.Name()] if exists { - mem_buffer, e := mMap.ReadMemory(0, _SuperBlockSize) + mBuffer, e := mMap.ReadMemory(0, _SuperBlockSize) if err != nil { err = fmt.Errorf("cannot read volume %s super block: %v", dataFile.Name(), e) return } - copy(header, mem_buffer.Buffer) - mem_buffer.ReleaseMemory() + copy(header, mBuffer.Buffer) + mBuffer.ReleaseMemory() } else { if _, err = dataFile.Seek(0, 0); err != nil { err = fmt.Errorf("cannot seek to the beginning of %s: %v", dataFile.Name(), err)