From 314dc1c957041501349fa731e21148c7e93d0006 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 30 Jan 2021 13:38:44 -0800 Subject: [PATCH] filer: etcd store fix listing fix https://github.com/chrislusf/seaweedfs/issues/1767 --- docker/Makefile | 3 ++ docker/swarm-etcd.yml | 84 +++++++++++++++++++++++++++++++++++ weed/filer/etcd/etcd_store.go | 12 ++++- 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 docker/swarm-etcd.yml diff --git a/docker/Makefile b/docker/Makefile index 5949842f1..c3c541738 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -30,5 +30,8 @@ cluster: build 2clusters: build docker-compose -f local-clusters-compose.yml -p seaweedfs up +filer_etcd: build + docker stack deploy -c swarm-etcd.yml fs + clean: rm ./weed diff --git a/docker/swarm-etcd.yml b/docker/swarm-etcd.yml new file mode 100644 index 000000000..186b24790 --- /dev/null +++ b/docker/swarm-etcd.yml @@ -0,0 +1,84 @@ +# 2021-01-30 16:25:30 +version: '3.8' + +services: + + etcd: + image: gasparekatapy/etcd + networks: + - net + deploy: + mode: replicated + replicas: 3 + + master: + image: chrislusf/seaweedfs:local + environment: + WEED_MASTER_FILER_DEFAULT: "filer:8888" + WEED_MASTER_SEQUENCER_TYPE: "raft" + ports: + - "9333:9333" + - "19333:19333" + networks: + - net + command: + - 'master' + - '-resumeState=true' + - '-ip=master' + - '-port=9333' + deploy: + mode: replicated + replicas: 1 + + filer: + image: chrislusf/seaweedfs:local + environment: + WEED_LEVELDB2_ENABLED: "false" + WEED_ETCD_ENABLED: "true" + WEED_ETCD_SERVERS: "etcd:2379" + ports: + - target: 8888 + published: 8888 + protocol: tcp + mode: host + - target: 18888 + published: 18888 + protocol: tcp + mode: host + networks: + - net + command: + - 'filer' + - '-ip=filer' + - '-port=8888' + - '-port.readonly=28888' + - '-master=master:9333' + - '-disableDirListing=true' + deploy: + mode: replicated + replicas: 1 + + volume: + image: chrislusf/seaweedfs:local + ports: + - target: 8080 + published: 8080 + protocol: tcp + mode: host + - target: 18080 + published: 18080 + protocol: tcp + mode: host + networks: + - net + command: + - 'volume' + - '-mserver=master:9333' + - '-port=8080' + deploy: + mode: global + + ########################################################################### + +networks: + net: diff --git a/weed/filer/etcd/etcd_store.go b/weed/filer/etcd/etcd_store.go index 8159c634d..71ed738f9 100644 --- a/weed/filer/etcd/etcd_store.go +++ b/weed/filer/etcd/etcd_store.go @@ -1,6 +1,7 @@ package etcd import ( + "bytes" "context" "fmt" "strings" @@ -145,14 +146,21 @@ func (store *EtcdStore) ListDirectoryPrefixedEntries(ctx context.Context, dirPat func (store *EtcdStore) ListDirectoryEntries(ctx context.Context, dirPath weed_util.FullPath, startFileName string, includeStartFile bool, limit int64, eachEntryFunc filer.ListEachEntryFunc) (lastFileName string, err error) { directoryPrefix := genDirectoryKeyPrefix(dirPath, "") + lastFileStart := directoryPrefix + if startFileName != "" { + lastFileStart = genDirectoryKeyPrefix(dirPath, startFileName) + } - resp, err := store.client.Get(ctx, string(directoryPrefix), + resp, err := store.client.Get(ctx, string(lastFileStart), clientv3.WithPrefix(), clientv3.WithSort(clientv3.SortByKey, clientv3.SortDescend)) if err != nil { return lastFileName, fmt.Errorf("list %s : %v", dirPath, err) } for _, kv := range resp.Kvs { + if !bytes.HasPrefix(kv.Key, directoryPrefix) { + break + } fileName := getNameFromKey(kv.Key) if fileName == "" { continue @@ -160,7 +168,6 @@ func (store *EtcdStore) ListDirectoryEntries(ctx context.Context, dirPath weed_u if fileName == startFileName && !includeStartFile { continue } - lastFileName = fileName limit-- if limit < 0 { break @@ -176,6 +183,7 @@ func (store *EtcdStore) ListDirectoryEntries(ctx context.Context, dirPath weed_u if !eachEntryFunc(entry) { break } + lastFileName = fileName } return lastFileName, err