Browse Source
cleaner
cleaner
git-svn-id: https://weed-fs.googlecode.com/svn/trunk@16 282b0af5-e82d-9cf1-ede4-77906d7719d0pull/2/head
chris.lu@gmail.com
13 years ago
6 changed files with 126 additions and 134 deletions
-
11weed-fs/src/cmd/weeds.go
-
63weed-fs/src/pkg/directory/volume_mapping.go
-
100weed-fs/src/pkg/storage/needle.go
-
74weed-fs/src/pkg/storage/needle_map.go
-
7weed-fs/src/pkg/storage/store.go
-
5weed-fs/src/pkg/storage/volume.go
@ -1,53 +1,53 @@ |
|||
package storage |
|||
|
|||
import ( |
|||
"os" |
|||
"os" |
|||
) |
|||
|
|||
type NeedleKey struct{ |
|||
Key uint64 "file id" |
|||
AlternateKey uint32 "supplemental id" |
|||
type NeedleKey struct { |
|||
Key uint64 "file id" |
|||
AlternateKey uint32 "supplemental id" |
|||
} |
|||
|
|||
func (k *NeedleKey) String() string { |
|||
var tmp [12]byte |
|||
for i :=uint(0);i<8;i++{ |
|||
tmp[i] = byte(k.Key >> (8*i)); |
|||
} |
|||
for i :=uint(0);i<4;i++{ |
|||
tmp[i+8] = byte(k.AlternateKey >> (8*i)); |
|||
} |
|||
return string(tmp[:]) |
|||
var tmp [12]byte |
|||
for i := uint(0); i < 8; i++ { |
|||
tmp[i] = byte(k.Key >> (8 * i)) |
|||
} |
|||
for i := uint(0); i < 4; i++ { |
|||
tmp[i+8] = byte(k.AlternateKey >> (8 * i)) |
|||
} |
|||
return string(tmp[:]) |
|||
} |
|||
|
|||
type NeedleValue struct{ |
|||
Offset uint32 "Volume offset" //since aligned to 8 bytes, range is 4G*8=32G
|
|||
Size uint32 "Size of the data portion" |
|||
type NeedleValue struct { |
|||
Offset uint32 "Volume offset" //since aligned to 8 bytes, range is 4G*8=32G
|
|||
Size uint32 "Size of the data portion" |
|||
} |
|||
|
|||
type NeedleMap struct{ |
|||
m map[string]*NeedleValue //mapping NeedleKey(Key,AlternateKey) to NeedleValue
|
|||
type NeedleMap struct { |
|||
m map[string]*NeedleValue //mapping NeedleKey(Key,AlternateKey) to NeedleValue
|
|||
} |
|||
func NewNeedleMap() (nm *NeedleMap){ |
|||
nm = new(NeedleMap) |
|||
nm.m = make(map[string]*NeedleValue) |
|||
return |
|||
|
|||
func NewNeedleMap() *NeedleMap { |
|||
return &NeedleMap{m: make(map[string]*NeedleValue)} |
|||
} |
|||
func (nm *NeedleMap) load(file *os.File){ |
|||
func (nm *NeedleMap) load(file *os.File) { |
|||
} |
|||
func makeKey(key uint64, altKey uint32) string { |
|||
var tmp [12]byte |
|||
for i :=uint(0);i<8;i++{ |
|||
tmp[i] = byte(key >> (8*i)); |
|||
} |
|||
for i :=uint(0);i<4;i++{ |
|||
tmp[i+8] = byte(altKey >> (8*i)); |
|||
} |
|||
return string(tmp[:]) |
|||
} |
|||
func (nm *NeedleMap) put(key uint64, altKey uint32, offset uint32, size uint32){ |
|||
nm.m[makeKey(key,altKey)] = &NeedleValue{Offset:offset, Size:size} |
|||
} |
|||
func (nm *NeedleMap) get(key uint64, altKey uint32) (element *NeedleValue, ok bool){ |
|||
element, ok = nm.m[makeKey(key,altKey)] |
|||
return |
|||
var tmp [12]byte |
|||
for i := uint(0); i < 8; i++ { |
|||
tmp[i] = byte(key >> (8 * i)) |
|||
} |
|||
for i := uint(0); i < 4; i++ { |
|||
tmp[i+8] = byte(altKey >> (8 * i)) |
|||
} |
|||
return string(tmp[:]) |
|||
} |
|||
func (nm *NeedleMap) put(key uint64, altKey uint32, offset uint32, size uint32) { |
|||
nm.m[makeKey(key, altKey)] = &NeedleValue{Offset: offset, Size: size} |
|||
} |
|||
func (nm *NeedleMap) get(key uint64, altKey uint32) (element *NeedleValue, ok bool) { |
|||
element, ok = nm.m[makeKey(key, altKey)] |
|||
return |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue