Browse Source

refactor memory map related code

pull/1091/head
Chris Lu 5 years ago
parent
commit
c9a183eb69
  1. 3
      weed/server/master_server_handlers_admin.go
  2. 22
      weed/storage/memory_map/memory_map.go
  3. 24
      weed/storage/memory_map/memory_map_other.go
  4. 2
      weed/storage/memory_map/memory_map_test.go
  5. 18
      weed/storage/memory_map/memory_map_windows.go
  6. 14
      weed/storage/needle/volume_memory_map_max_size.go

3
weed/server/master_server_handlers_admin.go

@ -11,6 +11,7 @@ import (
"github.com/chrislusf/seaweedfs/weed/operation"
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
"github.com/chrislusf/seaweedfs/weed/storage"
"github.com/chrislusf/seaweedfs/weed/storage/memory_map"
"github.com/chrislusf/seaweedfs/weed/storage/needle"
"github.com/chrislusf/seaweedfs/weed/topology"
"github.com/chrislusf/seaweedfs/weed/util"
@ -147,7 +148,7 @@ func (ms *MasterServer) getVolumeGrowOption(r *http.Request) (*topology.VolumeGr
if err != nil {
return nil, err
}
memoryMapMaxSizeMb, err := needle.ReadMemoryMapMaxSizeMb(r.FormValue("memoryMapMaxSizeMb"))
memoryMapMaxSizeMb, err := memory_map.ReadMemoryMapMaxSizeMb(r.FormValue("memoryMapMaxSizeMb"))
if err != nil {
return nil, err
}

22
weed/storage/memory_map/memory_map.go

@ -1,10 +1,8 @@
// +build !windows
package memory_map
import (
"fmt"
"os"
"strconv"
)
type MemoryBuffer struct {
@ -25,18 +23,10 @@ type MemoryMap struct {
var FileMemoryMap = make(map[string]*MemoryMap)
func (mMap *MemoryMap) CreateMemoryMap(file *os.File, maxLength uint64) {
}
func (mMap *MemoryMap) WriteMemory(offset uint64, length uint64, data []byte) {
func ReadMemoryMapMaxSizeMb(memoryMapMaxSizeMbString string) (uint32, error) {
if memoryMapMaxSizeMbString == "" {
return 0, nil
}
func (mMap *MemoryMap) ReadMemory(offset uint64, length uint64) ([]byte, error) {
dataSlice := []byte{}
return dataSlice, fmt.Errorf("Memory Map not implemented for this platform")
}
func (mBuffer *MemoryMap) DeleteFileAndMemoryMap() {
memoryMapMaxSize64, err := strconv.ParseUint(memoryMapMaxSizeMbString, 10, 32)
return uint32(memoryMapMaxSize64), err
}

24
weed/storage/memory_map/memory_map_other.go

@ -0,0 +1,24 @@
// +build !windows
package memory_map
import (
"fmt"
"os"
)
func (mMap *MemoryMap) CreateMemoryMap(file *os.File, maxLength uint64) {
}
func (mMap *MemoryMap) WriteMemory(offset uint64, length uint64, data []byte) {
}
func (mMap *MemoryMap) ReadMemory(offset uint64, length uint64) ([]byte, error) {
dataSlice := []byte{}
return dataSlice, fmt.Errorf("Memory Map not implemented for this platform")
}
func (mBuffer *MemoryMap) DeleteFileAndMemoryMap() {
}

2
weed/storage/needle/volume_memory_map_max_size_test.go → weed/storage/memory_map/memory_map_test.go

@ -1,4 +1,4 @@
package needle
package memory_map
import "testing"

18
weed/storage/memory_map/memory_map_windows.go

@ -11,24 +11,6 @@ import (
"golang.org/x/sys/windows"
)
type MemoryBuffer struct {
aligned_length uint64
length uint64
aligned_ptr uintptr
ptr uintptr
Buffer []byte
}
type MemoryMap struct {
File *os.File
file_memory_map_handle uintptr
write_map_views []MemoryBuffer
max_length uint64
End_of_file int64
}
var FileMemoryMap = make(map[string]*MemoryMap)
type DWORDLONG = uint64
type DWORD = uint32
type WORD = uint16

14
weed/storage/needle/volume_memory_map_max_size.go

@ -1,14 +0,0 @@
package needle
import "strconv"
func ReadMemoryMapMaxSizeMb(MemoryMapMaxSizeMbString string) (uint32, error) {
if MemoryMapMaxSizeMbString == "" {
return 0, nil
}
var MemoryMapMaxSize64 uint64
var err error
MemoryMapMaxSize64, err = strconv.ParseUint(MemoryMapMaxSizeMbString, 10, 32)
MemoryMapMaxSize := uint32(MemoryMapMaxSize64)
return MemoryMapMaxSize, err
}
Loading…
Cancel
Save