cp file can work

1. consolidate to filer_pb.FileChunk
2. dir add file, mkdir
3. file flush, write

updates having issue
This commit is contained in:
Chris Lu
2018-05-16 00:08:44 -07:00
parent c7a71d35b0
commit b303a02461
14 changed files with 619 additions and 102 deletions

View File

@@ -3,6 +3,7 @@ package embedded
import (
"github.com/syndtr/goleveldb/leveldb"
"github.com/chrislusf/seaweedfs/weed/filer2"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
)
type EmbeddedStore struct {
@@ -25,7 +26,7 @@ func (filer *EmbeddedStore) AddDirectoryLink(directory *filer2.Entry, delta int3
return nil
}
func (filer *EmbeddedStore) AppendFileChunk(fullpath filer2.FullPath, fileChunk filer2.FileChunk) (err error) {
func (filer *EmbeddedStore) AppendFileChunk(fullpath filer2.FullPath, fileChunks []*filer_pb.FileChunk) (err error) {
return nil
}

View File

@@ -1,6 +1,8 @@
package filer2
type Chunks []FileChunk
import "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
type Chunks []*filer_pb.FileChunk
func (chunks Chunks) TotalSize() (size uint64) {
for _, c := range chunks {

View File

@@ -8,6 +8,7 @@ import (
"path/filepath"
"time"
"os"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
)
type Filer struct {
@@ -105,8 +106,8 @@ func (f *Filer) CreateEntry(entry *Entry) (error) {
return nil
}
func (f *Filer) AppendFileChunk(p FullPath, c FileChunk) (err error) {
return f.store.AppendFileChunk(p, c)
func (f *Filer) AppendFileChunk(p FullPath, chunks []*filer_pb.FileChunk) (err error) {
return f.store.AppendFileChunk(p, chunks)
}
func (f *Filer) FindEntry(p FullPath) (found bool, entry *Entry, err error) {

View File

@@ -5,9 +5,9 @@ import (
"os"
"time"
"path/filepath"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
)
type FileId string //file id in SeaweedFS
type FullPath string
func NewFullPath(dir, name string) FullPath {
@@ -51,18 +51,12 @@ type Entry struct {
Attr
// the following is for files
Chunks []FileChunk `json:"chunks,omitempty"`
}
type FileChunk struct {
Fid FileId `json:"fid,omitempty"`
Offset int64 `json:"offset,omitempty"`
Size uint64 `json:"size,omitempty"` // size in bytes
Chunks []*filer_pb.FileChunk `json:"chunks,omitempty"`
}
type AbstractFiler interface {
CreateEntry(*Entry) (error)
AppendFileChunk(FullPath, FileChunk) (err error)
AppendFileChunk(FullPath, []*filer_pb.FileChunk) (err error)
FindEntry(FullPath) (found bool, fileEntry *Entry, err error)
DeleteEntry(FullPath) (fileEntry *Entry, err error)
@@ -74,7 +68,7 @@ var ErrNotFound = errors.New("filer: no entry is found in filer store")
type FilerStore interface {
InsertEntry(*Entry) (error)
AppendFileChunk(FullPath, FileChunk) (err error)
AppendFileChunk(FullPath, []*filer_pb.FileChunk) (err error)
FindEntry(FullPath) (found bool, entry *Entry, err error)
DeleteEntry(FullPath) (fileEntry *Entry, err error)

View File

@@ -6,6 +6,7 @@ import (
"strings"
"fmt"
"time"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
)
type MemDbStore struct {
@@ -32,13 +33,15 @@ func (filer *MemDbStore) InsertEntry(entry *filer2.Entry) (err error) {
return nil
}
func (filer *MemDbStore) AppendFileChunk(fullpath filer2.FullPath, fileChunk filer2.FileChunk) (err error) {
func (filer *MemDbStore) AppendFileChunk(fullpath filer2.FullPath, fileChunks []*filer_pb.FileChunk) (err error) {
found, entry, err := filer.FindEntry(fullpath)
if !found {
return fmt.Errorf("No such file: %s", fullpath)
}
entry.Chunks = append(entry.Chunks, fileChunk)
entry.Chunks = append(entry.Chunks, fileChunks...)
entry.Mtime = time.Now()
println("appending to entry", entry.Name(), len(entry.Chunks))
filer.tree.ReplaceOrInsert(Entry{entry})
return nil
}