Compare commits

...
3 Commits
Author SHA1 Message Date
Chris Lu 53e2e73de2 fix metrics
fix https://github.com/chrislusf/seaweedfs/issues/935
2019-04-22 12:32:10 -07:00
Chris Lu 0c96cfdb2e minor 2019-04-21 15:50:51 -07:00
Chris Lu 00b6f653fa shell: add fs.cat 2019-04-21 15:43:43 -07:00
4 changed files with 90 additions and 10 deletions

No files matched your search

+10 -2
View File
@@ -14,7 +14,9 @@ import (
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/chrislusf/seaweedfs/weed/util"
"github.com/chrislusf/seaweedfs/weed/wdclient"
)
func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {
@@ -231,13 +233,19 @@ func (fs *FilerServer) handleMultipleChunks(w http.ResponseWriter, r *http.Reque
func (fs *FilerServer) writeContent(w io.Writer, entry *filer2.Entry, offset int64, size int) error {
chunkViews := filer2.ViewFromChunks(entry.Chunks, offset, size)
return StreamContent(fs.filer.MasterClient, w, entry.Chunks, offset, size)
}
func StreamContent(masterClient *wdclient.MasterClient, w io.Writer, chunks []*filer_pb.FileChunk, offset int64, size int) error {
chunkViews := filer2.ViewFromChunks(chunks, offset, size)
fileId2Url := make(map[string]string)
for _, chunkView := range chunkViews {
urlString, err := fs.filer.MasterClient.LookupFileId(chunkView.FileId)
urlString, err := masterClient.LookupFileId(chunkView.FileId)
if err != nil {
glog.V(1).Infof("operation LookupFileId %s failed, err: %v", chunkView.FileId, err)
return err
+69
View File
@@ -0,0 +1,69 @@
package shell
import (
"context"
"fmt"
"io"
"math"
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
weed_server "github.com/chrislusf/seaweedfs/weed/server"
)
func init() {
commands = append(commands, &commandFsCat{})
}
type commandFsCat struct {
}
func (c *commandFsCat) Name() string {
return "fs.cat"
}
func (c *commandFsCat) Help() string {
return `stream the file content on to the screen
fs.cat /dir/
fs.cat /dir/file_name
fs.cat /dir/file_prefix
fs.cat http://<filer_server>:<port>/dir/
fs.cat http://<filer_server>:<port>/dir/file_name
fs.cat http://<filer_server>:<port>/dir/file_prefix
`
}
func (c *commandFsCat) Do(args []string, commandEnv *commandEnv, writer io.Writer) (err error) {
input := findInputDirectory(args)
filerServer, filerPort, path, err := commandEnv.parseUrl(input)
if err != nil {
return err
}
ctx := context.Background()
if commandEnv.isDirectory(ctx, filerServer, filerPort, path) {
return fmt.Errorf("%s is a directory", path)
}
dir, name := filer2.FullPath(path).DirAndName()
return commandEnv.withFilerClient(ctx, filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {
request := &filer_pb.LookupDirectoryEntryRequest{
Name: name,
Directory: dir,
}
respLookupEntry, err := client.LookupDirectoryEntry(ctx, request)
if err != nil {
return err
}
return weed_server.StreamContent(commandEnv.masterClient, writer, respLookupEntry.Entry.Chunks, 0, math.MaxInt32)
})
}
+3
View File
@@ -26,6 +26,9 @@ func (c *commandFsLs) Name() string {
func (c *commandFsLs) Help() string {
return `list all files under a directory
fs.ls [-l] [-a] /dir/
fs.ls [-l] [-a] /dir/file_name
fs.ls [-l] [-a] /dir/file_prefix
fs.ls [-l] [-a] http://<filer_server>:<port>/dir/
fs.ls [-l] [-a] http://<filer_server>:<port>/dir/file_name
fs.ls [-l] [-a] http://<filer_server>:<port>/dir/file_prefix
+8 -8
View File
@@ -28,33 +28,33 @@ func (mm *mapMetric) logPut(key NeedleId, oldSize uint32, newSize uint32) {
mm.LogDeletionCounter(oldSize)
}
}
func (mm mapMetric) LogFileCounter(newSize uint32) {
func (mm *mapMetric) LogFileCounter(newSize uint32) {
atomic.AddUint32(&mm.FileCounter, 1)
atomic.AddUint64(&mm.FileByteCounter, uint64(newSize))
}
func (mm mapMetric) LogDeletionCounter(oldSize uint32) {
func (mm *mapMetric) LogDeletionCounter(oldSize uint32) {
if oldSize > 0 {
atomic.AddUint32(&mm.DeletionCounter, 1)
atomic.AddUint64(&mm.DeletionByteCounter, uint64(oldSize))
}
}
func (mm mapMetric) ContentSize() uint64 {
func (mm *mapMetric) ContentSize() uint64 {
return atomic.LoadUint64(&mm.FileByteCounter)
}
func (mm mapMetric) DeletedSize() uint64 {
func (mm *mapMetric) DeletedSize() uint64 {
return atomic.LoadUint64(&mm.DeletionByteCounter)
}
func (mm mapMetric) FileCount() int {
func (mm *mapMetric) FileCount() int {
return int(atomic.LoadUint32(&mm.FileCounter))
}
func (mm mapMetric) DeletedCount() int {
func (mm *mapMetric) DeletedCount() int {
return int(atomic.LoadUint32(&mm.DeletionCounter))
}
func (mm mapMetric) MaxFileKey() NeedleId {
func (mm *mapMetric) MaxFileKey() NeedleId {
t := uint64(mm.MaximumFileKey)
return NeedleId(t)
}
func (mm mapMetric) MaybeSetMaxFileKey(key NeedleId) {
func (mm *mapMetric) MaybeSetMaxFileKey(key NeedleId) {
if key > mm.MaxFileKey() {
atomic.StoreUint64(&mm.MaximumFileKey, uint64(key))
}