Browse Source

issue 43 "go fmt" chagnes from "Ryan S. Brown" <sb@ryansb.com>

some basic changes to parse upload url
pull/2/head
Chris Lu 11 years ago
parent
commit
82b74c7940
  1. 2
      go/operation/delete_content.go
  2. 2
      go/replication/store_replicate.go
  3. 2
      go/replication/volume_growth.go
  4. 2
      go/sequence/sequence.go
  5. 3
      go/storage/cdb_map.go
  6. 2
      go/storage/compact_map_perf_test.go
  7. 2
      go/storage/compress.go
  8. 5
      go/storage/needle.go
  9. 22
      go/storage/needle_map.go
  10. 2
      go/storage/needle_read_write.go
  11. 2
      go/storage/store.go
  12. 2
      go/topology/node.go
  13. 2
      go/topology/node_list.go
  14. 2
      go/topology/topology.go
  15. 2
      go/topology/topology_compact.go
  16. 2
      go/topology/topology_event_handling.go
  17. 2
      go/util/config.go
  18. 2
      go/util/post.go
  19. 2
      go/weed/export.go
  20. 2
      go/weed/fix.go
  21. 2
      go/weed/master.go
  22. 2
      go/weed/shell.go
  23. 12
      go/weed/volume.go

2
go/operation/delete_content.go

@ -6,7 +6,7 @@ import (
"net/http"
)
func DeleteFile(server string, fileId string) (error) {
func DeleteFile(server string, fileId string) error {
fid, parseErr := storage.ParseFileId(fileId)
if parseErr != nil {
return parseErr

2
go/replication/store_replicate.go

@ -2,9 +2,9 @@ package replication
import (
"bytes"
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/operation"
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/glog"
"net/http"
"strconv"
)

2
go/replication/volume_growth.go

@ -1,12 +1,12 @@
package replication
import (
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/operation"
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/topology"
"errors"
"fmt"
"code.google.com/p/weed-fs/go/glog"
"math/rand"
"sync"
)

2
go/sequence/sequence.go

@ -1,8 +1,8 @@
package sequence
import (
"encoding/gob"
"code.google.com/p/weed-fs/go/glog"
"encoding/gob"
"os"
"path"
"sync"

3
go/storage/cdb_map.go

@ -76,6 +76,9 @@ func (m cdbMap) FileCount() int {
func (m *cdbMap) DeletedCount() int {
return m.DeletionCounter
}
func (m *cdbMap) NextFileKey(count int) (uint64) {
return 0
}
func getMetric(c *cdb.Cdb, m *mapMetric) error {
data, err := c.Data([]byte{'M'})

2
go/storage/compact_map_perf_test.go

@ -1,8 +1,8 @@
package storage
import (
"code.google.com/p/weed-fs/go/util"
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/util"
"os"
"testing"
)

2
go/storage/compress.go

@ -2,9 +2,9 @@ package storage
import (
"bytes"
"code.google.com/p/weed-fs/go/glog"
"compress/flate"
"compress/gzip"
"code.google.com/p/weed-fs/go/glog"
"io/ioutil"
"strings"
)

5
go/storage/needle.go

@ -1,10 +1,10 @@
package storage
import (
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/util"
"encoding/hex"
"io/ioutil"
"code.google.com/p/weed-fs/go/glog"
"mime"
"net/http"
"path"
@ -127,9 +127,6 @@ func NewNeedle(r *http.Request) (n *Needle, e error) {
func (n *Needle) ParsePath(fid string) {
length := len(fid)
if length <= 8 {
if length > 0 {
glog.V(0).Infoln("Invalid fid", fid, "length", length)
}
return
}
delta := ""

22
go/storage/needle_map.go

@ -2,6 +2,7 @@ package storage
import (
"bufio"
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/util"
"fmt"
"io"
@ -18,6 +19,7 @@ type NeedleMapper interface {
FileCount() int
DeletedCount() int
Visit(visit func(NeedleValue) error) (err error)
NextFileKey(count int) uint64
}
type mapMetric struct {
@ -25,6 +27,7 @@ type mapMetric struct {
FileCounter int `json:"FileCounter"`
DeletionByteCounter uint64 `json:"DeletionByteCounter"`
FileByteCounter uint64 `json:"FileByteCounter"`
MaximumFileKey uint64 `json:"MaxFileKey"`
}
type NeedleMap struct {
@ -53,23 +56,27 @@ const (
func LoadNeedleMap(file *os.File) (*NeedleMap, error) {
nm := NewNeedleMap(file)
e := walkIndexFile(file, func(key uint64, offset, size uint32) error {
if key > nm.MaximumFileKey {
nm.MaximumFileKey = key
}
nm.FileCounter++
nm.FileByteCounter = nm.FileByteCounter + uint64(size)
if offset > 0 {
oldSize := nm.m.Set(Key(key), offset, size)
//glog.V(0).Infoln("reading key", key, "offset", offset, "size", size, "oldSize", oldSize)
glog.V(4).Infoln("reading key", key, "offset", offset, "size", size, "oldSize", oldSize)
if oldSize > 0 {
nm.DeletionCounter++
nm.DeletionByteCounter = nm.DeletionByteCounter + uint64(oldSize)
}
} else {
oldSize := nm.m.Delete(Key(key))
//glog.V(0).Infoln("removing key", key, "offset", offset, "size", size, "oldSize", oldSize)
glog.V(4).Infoln("removing key", key, "offset", offset, "size", size, "oldSize", oldSize)
nm.DeletionCounter++
nm.DeletionByteCounter = nm.DeletionByteCounter + uint64(oldSize)
}
return nil
})
glog.V(1).Infoln("max file key:", nm.MaximumFileKey)
return nm, e
}
@ -163,3 +170,14 @@ func (nm NeedleMap) DeletedCount() int {
func (nm *NeedleMap) Visit(visit func(NeedleValue) error) (err error) {
return nm.m.Visit(visit)
}
func (nm NeedleMap) MaxFileKey() uint64 {
return nm.MaximumFileKey
}
func (nm NeedleMap) NextFileKey(count int) (ret uint64) {
if count <= 0 {
return 0
}
ret = nm.MaximumFileKey
nm.MaximumFileKey += uint64(count)
return
}

2
go/storage/needle_read_write.go

@ -1,11 +1,11 @@
package storage
import (
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/util"
"errors"
"fmt"
"io"
"code.google.com/p/weed-fs/go/glog"
"os"
)

2
go/storage/store.go

@ -1,11 +1,11 @@
package storage
import (
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/util"
"encoding/json"
"fmt"
"io/ioutil"
"code.google.com/p/weed-fs/go/glog"
"net/url"
"strconv"
"strings"

2
go/topology/node.go

@ -1,8 +1,8 @@
package topology
import (
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/storage"
)
type NodeId string

2
go/topology/node_list.go

@ -1,8 +1,8 @@
package topology
import (
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/storage"
"math/rand"
)

2
go/topology/topology.go

@ -1,11 +1,11 @@
package topology
import (
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/sequence"
"code.google.com/p/weed-fs/go/storage"
"errors"
"io/ioutil"
"code.google.com/p/weed-fs/go/glog"
"math/rand"
)

2
go/topology/topology_compact.go

@ -1,11 +1,11 @@
package topology
import (
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/util"
"encoding/json"
"errors"
"code.google.com/p/weed-fs/go/glog"
"net/url"
"time"
)

2
go/topology/topology_event_handling.go

@ -1,8 +1,8 @@
package topology
import (
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/storage"
"math/rand"
"time"
)

2
go/util/config.go

@ -10,8 +10,8 @@ package util
import (
"bytes"
"encoding/json"
"code.google.com/p/weed-fs/go/glog"
"encoding/json"
"os"
)

2
go/util/post.go

@ -1,8 +1,8 @@
package util
import (
"io/ioutil"
"code.google.com/p/weed-fs/go/glog"
"io/ioutil"
"net/http"
"net/url"
)

2
go/weed/export.go

@ -3,9 +3,9 @@ package main
import (
"archive/tar"
"bytes"
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/storage"
"fmt"
"code.google.com/p/weed-fs/go/glog"
"os"
"path"
"strconv"

2
go/weed/fix.go

@ -1,8 +1,8 @@
package main
import (
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/storage"
"os"
"path"
"strconv"

2
go/weed/master.go

@ -182,7 +182,7 @@ func volumeStatusHandler(w http.ResponseWriter, r *http.Request) {
}
func redirectHandler(w http.ResponseWriter, r *http.Request) {
vid, _, _, _ := parseURLPath(r.URL.Path)
vid, _, _, _, _ := parseURLPath(r.URL.Path)
volumeId, err := storage.NewVolumeId(vid)
if err != nil {
debug("parsing error:", err, r.URL.Path)

2
go/weed/shell.go

@ -2,8 +2,8 @@ package main
import (
"bufio"
"fmt"
"code.google.com/p/weed-fs/go/glog"
"fmt"
"os"
)

12
go/weed/volume.go

@ -118,7 +118,7 @@ func storeHandler(w http.ResponseWriter, r *http.Request) {
}
func GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {
n := new(storage.Needle)
vid, fid, filename, ext := parseURLPath(r.URL.Path)
vid, fid, filename, ext, _ := parseURLPath(r.URL.Path)
volumeId, err := storage.NewVolumeId(vid)
if err != nil {
debug("parsing error:", err, r.URL.Path)
@ -207,7 +207,7 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
writeJsonError(w, r, e)
return
}
vid, _, _, _ := parseURLPath(r.URL.Path)
vid, _, _, _, _ := parseURLPath(r.URL.Path)
volumeId, ve := storage.NewVolumeId(vid)
if ve != nil {
debug("NewVolumeId error:", ve)
@ -231,7 +231,7 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
}
func DeleteHandler(w http.ResponseWriter, r *http.Request) {
n := new(storage.Needle)
vid, fid, _, _ := parseURLPath(r.URL.Path)
vid, fid, _, _, _ := parseURLPath(r.URL.Path)
volumeId, _ := storage.NewVolumeId(vid)
n.ParsePath(fid)
@ -266,7 +266,7 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
writeJsonQuiet(w, r, m)
}
func parseURLPath(path string) (vid, fid, filename, ext string) {
func parseURLPath(path string) (vid, fid, filename, ext string, isVolumeIdOnly bool) {
switch strings.Count(path, "/") {
case 3:
parts := strings.Split(path, "/")
@ -284,9 +284,7 @@ func parseURLPath(path string) (vid, fid, filename, ext string) {
sepIndex := strings.LastIndex(path, "/")
commaIndex := strings.LastIndex(path[sepIndex:], ",")
if commaIndex <= 0 {
if "favicon.ico" != path[sepIndex+1:] {
glog.V(0).Infoln("unknown file id", path[sepIndex+1:])
}
vid, isVolumeIdOnly = path[sepIndex+1:], true
return
}
dotIndex := strings.LastIndex(path[sepIndex:], ".")

Loading…
Cancel
Save