Chris Lu
5 years ago
5 changed files with 125 additions and 4 deletions
-
2weed/filer2/filer.go
-
5weed/filer2/filerstore.go
-
47weed/filer2/leveldb2/leveldb2_local_store.go
-
38weed/filer2/meta_aggregator.go
-
37weed/filer2/meta_replay.go
@ -0,0 +1,47 @@ |
|||||
|
package leveldb |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
|
||||
|
"github.com/chrislusf/seaweedfs/weed/filer2" |
||||
|
"github.com/chrislusf/seaweedfs/weed/util" |
||||
|
) |
||||
|
|
||||
|
func init() { |
||||
|
filer2.Stores = append(filer2.Stores, &LevelDB2Store{}) |
||||
|
} |
||||
|
|
||||
|
var ( |
||||
|
_ = filer2.FilerLocalStore(&LevelDB2Store{}) |
||||
|
) |
||||
|
|
||||
|
func (store *LevelDB2Store) UpdateOffset(filer string, lastTsNs int64) error { |
||||
|
|
||||
|
value := make([]byte, 8) |
||||
|
util.Uint64toBytes(value, uint64(lastTsNs)) |
||||
|
|
||||
|
err := store.dbs[0].Put([]byte("meta"+filer), value, nil) |
||||
|
|
||||
|
if err != nil { |
||||
|
return fmt.Errorf("UpdateOffset %s : %v", filer, err) |
||||
|
} |
||||
|
|
||||
|
println("UpdateOffset", filer, "lastTsNs", lastTsNs) |
||||
|
|
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
func (store *LevelDB2Store) ReadOffset(filer string) (lastTsNs int64, err error) { |
||||
|
|
||||
|
value, err := store.dbs[0].Get([]byte("meta"+filer), nil) |
||||
|
|
||||
|
if err != nil { |
||||
|
return 0, fmt.Errorf("ReadOffset %s : %v", filer, err) |
||||
|
} |
||||
|
|
||||
|
lastTsNs = int64(util.BytesToUint64(value)) |
||||
|
|
||||
|
println("ReadOffset", filer, "lastTsNs", lastTsNs) |
||||
|
|
||||
|
return |
||||
|
} |
@ -0,0 +1,37 @@ |
|||||
|
package filer2 |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
|
||||
|
"github.com/chrislusf/seaweedfs/weed/glog" |
||||
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" |
||||
|
"github.com/chrislusf/seaweedfs/weed/util" |
||||
|
) |
||||
|
|
||||
|
func Replay(filerStore FilerStore, resp *filer_pb.SubscribeMetadataResponse) error { |
||||
|
message := resp.EventNotification |
||||
|
var oldPath util.FullPath |
||||
|
var newEntry *Entry |
||||
|
if message.OldEntry != nil { |
||||
|
oldPath = util.NewFullPath(resp.Directory, message.OldEntry.Name) |
||||
|
glog.V(4).Infof("deleting %v", oldPath) |
||||
|
if err := filerStore.DeleteEntry(context.Background(), oldPath); err != nil { |
||||
|
return err |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if message.NewEntry != nil { |
||||
|
dir := resp.Directory |
||||
|
if message.NewParentPath != "" { |
||||
|
dir = message.NewParentPath |
||||
|
} |
||||
|
key := util.NewFullPath(dir, message.NewEntry.Name) |
||||
|
glog.V(4).Infof("creating %v", key) |
||||
|
newEntry = FromPbEntry(dir, message.NewEntry) |
||||
|
if err := filerStore.InsertEntry(context.Background(), newEntry); err != nil { |
||||
|
return err |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return nil |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue