Chris Lu
12 years ago
35 changed files with 476 additions and 491 deletions
-
1weed-fs/src/cmd/weed/command.go
-
15weed-fs/src/cmd/weed/shell.go
-
6weed-fs/src/cmd/weed/volume.go
-
4weed-fs/src/pkg/directory/file_id.go
-
2weed-fs/src/pkg/operation/delete_content.go
-
6weed-fs/src/pkg/operation/lookup_volume_id.go
-
4weed-fs/src/pkg/operation/upload_content.go
-
2weed-fs/src/pkg/replication/volume_growth.go
-
9weed-fs/src/pkg/replication/volume_growth_test.go
-
2weed-fs/src/pkg/sequence/sequence.go
-
2weed-fs/src/pkg/storage/compact_map_perf_test.go
-
12weed-fs/src/pkg/storage/compact_map_test.go
-
34weed-fs/src/pkg/storage/compress.go
-
4weed-fs/src/pkg/storage/needle.go
-
8weed-fs/src/pkg/storage/replication_type.go
-
9weed-fs/src/pkg/storage/store.go
-
12weed-fs/src/pkg/storage/volume.go
-
9weed-fs/src/pkg/storage/volume_id.go
-
3weed-fs/src/pkg/storage/volume_version.go
-
6weed-fs/src/pkg/topology/configuration_test.go
-
5weed-fs/src/pkg/topology/data_center.go
-
4weed-fs/src/pkg/topology/node_list.go
-
14weed-fs/src/pkg/topology/node_list_test.go
-
6weed-fs/src/pkg/topology/topo_test.go
-
2weed-fs/src/pkg/topology/topology_compact.go
-
3weed-fs/src/pkg/topology/topology_map.go
-
2weed-fs/src/pkg/topology/volume_location.go
-
27weed-fs/src/pkg/util/bytes.go
-
8weed-fs/src/pkg/util/parse.go
@ -1,38 +1,38 @@ |
|||||
package topology |
package topology |
||||
|
|
||||
import ( |
import ( |
||||
|
_ "fmt" |
||||
"strconv" |
"strconv" |
||||
"testing" |
"testing" |
||||
_ "fmt" |
|
||||
) |
) |
||||
|
|
||||
func TestXYZ(t *testing.T) { |
func TestXYZ(t *testing.T) { |
||||
topo := NewTopology("topo","/etc/weed.conf", "/tmp","test",234,5) |
|
||||
|
topo := NewTopology("topo", "/etc/weed.conf", "/tmp", "test", 234, 5) |
||||
for i := 0; i < 5; i++ { |
for i := 0; i < 5; i++ { |
||||
dc := NewDataCenter("dc" + strconv.Itoa(i)) |
dc := NewDataCenter("dc" + strconv.Itoa(i)) |
||||
dc.activeVolumeCount = i |
dc.activeVolumeCount = i |
||||
dc.maxVolumeCount = 5 |
dc.maxVolumeCount = 5 |
||||
topo.LinkChildNode(dc) |
topo.LinkChildNode(dc) |
||||
} |
} |
||||
nl := NewNodeList(topo.Children(),nil) |
|
||||
|
nl := NewNodeList(topo.Children(), nil) |
||||
|
|
||||
picked, ret := nl.RandomlyPickN(1) |
picked, ret := nl.RandomlyPickN(1) |
||||
if !ret || len(picked)!=1 { |
|
||||
|
if !ret || len(picked) != 1 { |
||||
t.Errorf("need to randomly pick 1 node") |
t.Errorf("need to randomly pick 1 node") |
||||
} |
} |
||||
|
|
||||
picked, ret = nl.RandomlyPickN(4) |
picked, ret = nl.RandomlyPickN(4) |
||||
if !ret || len(picked)!=4 { |
|
||||
|
if !ret || len(picked) != 4 { |
||||
t.Errorf("need to randomly pick 4 nodes") |
t.Errorf("need to randomly pick 4 nodes") |
||||
} |
} |
||||
|
|
||||
picked, ret = nl.RandomlyPickN(5) |
picked, ret = nl.RandomlyPickN(5) |
||||
if !ret || len(picked)!=5 { |
|
||||
|
if !ret || len(picked) != 5 { |
||||
t.Errorf("need to randomly pick 5 nodes") |
t.Errorf("need to randomly pick 5 nodes") |
||||
} |
} |
||||
|
|
||||
picked, ret = nl.RandomlyPickN(6) |
picked, ret = nl.RandomlyPickN(6) |
||||
if ret || len(picked)!=0 { |
|
||||
|
if ret || len(picked) != 0 { |
||||
t.Errorf("can not randomly pick 6 nodes:", ret, picked) |
t.Errorf("can not randomly pick 6 nodes:", ret, picked) |
||||
} |
} |
||||
|
|
||||
|
@ -1,34 +1,33 @@ |
|||||
package util |
package util |
||||
|
|
||||
func BytesToUint64(b []byte)(v uint64){ |
|
||||
|
func BytesToUint64(b []byte) (v uint64) { |
||||
length := uint(len(b)) |
length := uint(len(b)) |
||||
for i :=uint(0);i<length-1;i++ { |
|
||||
|
for i := uint(0); i < length-1; i++ { |
||||
v += uint64(b[i]) |
v += uint64(b[i]) |
||||
v <<= 8 |
v <<= 8 |
||||
} |
} |
||||
v+=uint64(b[length-1]) |
|
||||
|
v += uint64(b[length-1]) |
||||
return |
return |
||||
} |
} |
||||
func BytesToUint32(b []byte)(v uint32){ |
|
||||
|
func BytesToUint32(b []byte) (v uint32) { |
||||
length := uint(len(b)) |
length := uint(len(b)) |
||||
for i :=uint(0);i<length-1;i++ { |
|
||||
|
for i := uint(0); i < length-1; i++ { |
||||
v += uint32(b[i]) |
v += uint32(b[i]) |
||||
v <<= 8 |
v <<= 8 |
||||
} |
} |
||||
v+=uint32(b[length-1]) |
|
||||
|
v += uint32(b[length-1]) |
||||
return |
return |
||||
} |
} |
||||
func Uint64toBytes(b []byte, v uint64){ |
|
||||
for i :=uint(0);i<8;i++ { |
|
||||
b[7-i] = byte(v>>(i*8)) |
|
||||
|
func Uint64toBytes(b []byte, v uint64) { |
||||
|
for i := uint(0); i < 8; i++ { |
||||
|
b[7-i] = byte(v >> (i * 8)) |
||||
} |
} |
||||
} |
} |
||||
func Uint32toBytes(b []byte, v uint32){ |
|
||||
for i :=uint(0);i<4;i++ { |
|
||||
b[3-i] = byte(v>>(i*8)) |
|
||||
|
func Uint32toBytes(b []byte, v uint32) { |
||||
|
for i := uint(0); i < 4; i++ { |
||||
|
b[3-i] = byte(v >> (i * 8)) |
||||
} |
} |
||||
} |
} |
||||
func Uint8toBytes(b []byte, v uint8){ |
|
||||
|
func Uint8toBytes(b []byte, v uint8) { |
||||
b[0] = byte(v) |
b[0] = byte(v) |
||||
} |
} |
||||
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue