mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
return written bytes, add debug mode
git-svn-id: https://weed-fs.googlecode.com/svn/trunk@22 282b0af5-e82d-9cf1-ede4-77906d7719d0
This commit is contained in:
parent
cc8af2e7dc
commit
cf7094f3c9
|
@ -18,6 +18,7 @@ var (
|
||||||
chunkCount = flag.Int("chunks", 5, "data chunks to store files")
|
chunkCount = flag.Int("chunks", 5, "data chunks to store files")
|
||||||
publicServer = flag.String("pserver", "localhost:8080", "public server to serve data read")
|
publicServer = flag.String("pserver", "localhost:8080", "public server to serve data read")
|
||||||
metaServer = flag.String("mserver", "localhost:9333", "metadata server to store mappings")
|
metaServer = flag.String("mserver", "localhost:9333", "metadata server to store mappings")
|
||||||
|
IsDebug = flag.Bool("debug", false, "enable debug mode")
|
||||||
|
|
||||||
store *storage.Store
|
store *storage.Store
|
||||||
)
|
)
|
||||||
|
@ -52,6 +53,9 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
volumeId, _ := strconv.Atoui64(path[sepIndex+1 : commaIndex])
|
volumeId, _ := strconv.Atoui64(path[sepIndex+1 : commaIndex])
|
||||||
n.ParsePath(fid)
|
n.ParsePath(fid)
|
||||||
|
|
||||||
|
if *IsDebug {
|
||||||
|
log.Println("volume", volumeId, "reading", n)
|
||||||
|
}
|
||||||
store.Read(volumeId, n)
|
store.Read(volumeId, n)
|
||||||
if dotIndex > 0 {
|
if dotIndex > 0 {
|
||||||
ext := path[dotIndex:]
|
ext := path[dotIndex:]
|
||||||
|
@ -67,8 +71,10 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if e != nil {
|
if e != nil {
|
||||||
writeJson(w, r, e)
|
writeJson(w, r, e)
|
||||||
} else {
|
} else {
|
||||||
store.Write(volumeId, storage.NewNeedle(r))
|
ret := store.Write(volumeId, storage.NewNeedle(r))
|
||||||
writeJson(w, r, make(map[string]string))
|
m := make(map[string]uint32)
|
||||||
|
m["size"] = ret
|
||||||
|
writeJson(w, r, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func DeleteHandler(w http.ResponseWriter, r *http.Request) {
|
func DeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (n *Needle) ParsePath(fid string) {
|
||||||
}
|
}
|
||||||
n.Key, n.Cookie = ParseKeyHash(fid)
|
n.Key, n.Cookie = ParseKeyHash(fid)
|
||||||
}
|
}
|
||||||
func (n *Needle) Append(w io.Writer) {
|
func (n *Needle) Append(w io.Writer) (uint32){
|
||||||
header := make([]byte, 16)
|
header := make([]byte, 16)
|
||||||
Uint32toBytes(header[0:4], n.Cookie)
|
Uint32toBytes(header[0:4], n.Cookie)
|
||||||
Uint64toBytes(header[4:12], n.Key)
|
Uint64toBytes(header[4:12], n.Key)
|
||||||
|
@ -58,6 +58,7 @@ func (n *Needle) Append(w io.Writer) {
|
||||||
rest := 8 - ((n.Size + 16 + 4) % 8)
|
rest := 8 - ((n.Size + 16 + 4) % 8)
|
||||||
Uint32toBytes(header[0:4], uint32(n.Checksum))
|
Uint32toBytes(header[0:4], uint32(n.Checksum))
|
||||||
w.Write(header[0 : rest+4])
|
w.Write(header[0 : rest+4])
|
||||||
|
return n.Size
|
||||||
}
|
}
|
||||||
func (n *Needle) Read(r io.Reader, size uint32) {
|
func (n *Needle) Read(r io.Reader, size uint32) {
|
||||||
bytes := make([]byte, size+16+4)
|
bytes := make([]byte, size+16+4)
|
||||||
|
|
|
@ -83,8 +83,8 @@ func (s *Store) Close() {
|
||||||
v.Close()
|
v.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (s *Store) Write(i uint64, n *Needle) {
|
func (s *Store) Write(i uint64, n *Needle) (uint32){
|
||||||
s.volumes[i].write(n)
|
return s.volumes[i].write(n)
|
||||||
}
|
}
|
||||||
func (s *Store) Read(i uint64, n *Needle) {
|
func (s *Store) Read(i uint64, n *Needle) {
|
||||||
s.volumes[i].read(n)
|
s.volumes[i].read(n)
|
||||||
|
|
|
@ -48,15 +48,16 @@ func (v *Volume) Close() {
|
||||||
v.dataFile.Close()
|
v.dataFile.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Volume) write(n *Needle) {
|
func (v *Volume) write(n *Needle) uint32{
|
||||||
counter := <-v.accessChannel
|
counter := <-v.accessChannel
|
||||||
offset, _ := v.dataFile.Seek(0, 2)
|
offset, _ := v.dataFile.Seek(0, 2)
|
||||||
n.Append(v.dataFile)
|
ret := n.Append(v.dataFile)
|
||||||
nv, ok := v.nm.get(n.Key)
|
nv, ok := v.nm.get(n.Key)
|
||||||
if !ok || int64(nv.Offset)*8 < offset {
|
if !ok || int64(nv.Offset)*8 < offset {
|
||||||
v.nm.put(n.Key, uint32(offset/8), n.Size)
|
v.nm.put(n.Key, uint32(offset/8), n.Size)
|
||||||
}
|
}
|
||||||
v.accessChannel <- counter + 1
|
v.accessChannel <- counter + 1
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
func (v *Volume) read(n *Needle) {
|
func (v *Volume) read(n *Needle) {
|
||||||
counter := <-v.accessChannel
|
counter := <-v.accessChannel
|
||||||
|
|
Loading…
Reference in a new issue