From cc756ddd79608ff46839a1542c3f42d4ab8148d7 Mon Sep 17 00:00:00 2001 From: "j.laycock" Date: Wed, 4 Sep 2019 14:24:17 +0100 Subject: [PATCH] Rename End_of_file variable, implement platform indepenent memory_map.go --- weed/storage/memory_map/memory_map.go | 25 ++++++++++++++++--- weed/storage/memory_map/memory_map_windows.go | 8 +++--- weed/storage/needle/needle_read_write.go | 2 +- weed/storage/volume_super_block.go | 2 +- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/weed/storage/memory_map/memory_map.go b/weed/storage/memory_map/memory_map.go index 1c1f8dd69..e8d3de6e0 100644 --- a/weed/storage/memory_map/memory_map.go +++ b/weed/storage/memory_map/memory_map.go @@ -2,7 +2,10 @@ package memory_map -import "os" +import ( + "fmt" + "os" +) type MemoryBuffer struct { aligned_length uint64 @@ -17,7 +20,23 @@ type MemoryMap struct { file_memory_map_handle uintptr write_map_views []MemoryBuffer max_length uint64 - End_Of_File int64 + End_of_file int64 } -var FileMemoryMap = make(map[string]MemoryMap) +var FileMemoryMap = make(map[string]*MemoryMap) + +func (mMap *MemoryMap) WriteMemory(offset uint64, length uint64, data []byte) { + +} + +func (mMap *MemoryMap) ReadMemory(offset uint64, length uint64) (MemoryBuffer, error) { + return MemoryBuffer{}, fmt.Errorf("Memory Map not implemented for this platform") +} + +func (mem_buffer *MemoryBuffer) ReleaseMemory() { + +} + +func (mMap *MemoryMap) DeleteFileAndMemoryMap() { + +} diff --git a/weed/storage/memory_map/memory_map_windows.go b/weed/storage/memory_map/memory_map_windows.go index fe6f152b7..055aeacc5 100644 --- a/weed/storage/memory_map/memory_map_windows.go +++ b/weed/storage/memory_map/memory_map_windows.go @@ -24,7 +24,7 @@ type MemoryMap struct { file_memory_map_handle uintptr write_map_views []MemoryBuffer max_length uint64 - End_Of_File int64 + End_of_file int64 } var FileMemoryMap = make(map[string]*MemoryMap) @@ -51,7 +51,7 @@ func (mMap *MemoryMap) CreateMemoryMap(file *os.File, maxlength uint64) { mMap.file_memory_map_handle = uintptr(file_memory_map_handle) mMap.write_map_views = make([]MemoryBuffer, 0, maxlength/chunk_size) mMap.max_length = maxlength - mMap.End_Of_File = -1 + mMap.End_of_file = -1 } } @@ -103,8 +103,8 @@ func (mMap *MemoryMap) WriteMemory(offset uint64, length uint64, data []byte) { } } - if mMap.End_Of_File < int64(offset+length-1) { - mMap.End_Of_File = int64(offset + length - 1) + if mMap.End_of_file < int64(offset+length-1) { + mMap.End_of_file = int64(offset + length - 1) } } diff --git a/weed/storage/needle/needle_read_write.go b/weed/storage/needle/needle_read_write.go index c29e17079..23a192543 100644 --- a/weed/storage/needle/needle_read_write.go +++ b/weed/storage/needle/needle_read_write.go @@ -145,7 +145,7 @@ func (n *Needle) Append(w *os.File, version Version) (offset uint64, size uint32 return } } else { - offset = uint64(mMap.End_Of_File + 1) + offset = uint64(mMap.End_of_file + 1) } bytesToWrite, size, actualSize, err := n.prepareWriteBuffer(version) diff --git a/weed/storage/volume_super_block.go b/weed/storage/volume_super_block.go index 936648f44..f93c43fbf 100644 --- a/weed/storage/volume_super_block.go +++ b/weed/storage/volume_super_block.go @@ -75,7 +75,7 @@ func (v *Volume) maybeWriteSuperBlock() error { mMap, exists := memory_map.FileMemoryMap[v.dataFile.Name()] if exists { - if mMap.End_Of_File == -1 { + if mMap.End_of_file == -1 { v.SuperBlock.version = needle.CurrentVersion mMap.WriteMemory(0, uint64(len(v.SuperBlock.Bytes())), v.SuperBlock.Bytes()) }