Skip to content

Commit 2dd3f31

Browse files
authored
cmd/sync: change tmp file name (#6665)
1 parent 32bbf3d commit 2dd3f31

File tree

9 files changed

+14
-15
lines changed

9 files changed

+14
-15
lines changed

cmd/object.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"errors"
2323
"fmt"
2424
"io"
25-
"math/rand"
2625
"os"
2726
"path"
2827
"runtime"
@@ -139,7 +138,7 @@ func (j *juiceFS) Put(rCtx context.Context, key string, in io.Reader, getters ..
139138
if len(name) > 200 {
140139
name = name[:200]
141140
}
142-
tmp = path.Join(path.Dir(p), fmt.Sprintf(".%s.tmp.%d", name, rand.Int()))
141+
tmp = object.TmpFilePath(p, name)
143142
defer func() {
144143
if err != nil {
145144
if e := j.jfs.Delete(ctx, tmp); e != 0 {

docs/en/guide/sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ If you notice the progress bar is not changing, use the methods below for monito
312312
* Use [`juicefs stats`](../administration/fault_diagnosis_and_analysis.md#stats) to quickly check current I/O status.
313313
* Review the [client log](../administration/fault_diagnosis_and_analysis.md#client-log) (default path: `/var/log/juicefs.log`) for [slow requests or timeout errors](../administration/troubleshooting.md#io-error-object-storage).
314314

315-
* If the destination is a local disk, check the directory for temporary files with `.tmp.xxx`. During the synchronization process, the transfer results are written to these temporary files. Once the transfer is complete, they are renamed to finalize the write. By monitoring the size changes of the temporary files, you can determine the current I/O status.
315+
* If the destination is a local disk, check the directory for temporary files with `.jfs.xxx.tmp.xxx`. During the synchronization process, the transfer results are written to these temporary files. Once the transfer is complete, they are renamed to finalize the write. By monitoring the size changes of the temporary files, you can determine the current I/O status.
316316

317317
* If both the source and destination are object storage systems, use tools like `nethogs` to check network I/O.
318318

docs/zh_cn/guide/sync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ juicefs sync --worker host1,host2 /jfs-src /jfs-dst
319319
* 如果数据同步的两方有任何一个是 JuiceFS 宿主机挂载点:
320320
*[`juicefs stats`](../administration/fault_diagnosis_and_analysis.md#stats) 快速查看文件系统是否正在写入(或读出);
321321
* 阅读[客户端日志](../administration/fault_diagnosis_and_analysis.md#client-log)(默认 `/var/log/juicefs.log`),观察是否有[慢请求或者超时错误日志](../administration/troubleshooting.md#io-error-object-storage)
322-
* 如果数据同步的目的地是宿主机本地盘,可以直接观察目录下是否存在名称中带 `.tmp.xxx` 后缀的临时文件,`sync` 过程中会将传输结果写入临时文件,待传输完成后进行重命名,才完成最终的写入。观察临时文件大小是否变化,就能确定当前的写入状况;
322+
* 如果数据同步的目的地是宿主机本地盘,可以直接观察目录下是否存在名称中带 `.jfs.xxx.tmp.xxx` 后缀的临时文件,`sync` 过程中会将传输结果写入临时文件,待传输完成后进行重命名,才完成最终的写入。观察临时文件大小是否变化,就能确定当前的写入状况;
323323
* 如果传输目的地均为对象存储,可以通过类似 `nethogs` 的命令,查看出入网流量,来判断传输进展;
324324
* 以上手段均未能获得有效排查信息,则需要对 `sync` 进程采集 goroutine,结合源码分析排查:
325325

pkg/object/cifs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"context"
2525
"fmt"
2626
"io"
27-
"math/rand"
2827
"net"
2928
"net/url"
3029
"os"
@@ -237,7 +236,7 @@ func (c *cifsStore) Put(ctx context.Context, key string, in io.Reader, getters .
237236
if len(name) > 200 {
238237
name = name[:200]
239238
}
240-
tmp = path.Join(path.Dir(p), fmt.Sprintf(".%s.tmp.%d", name, rand.Int()))
239+
tmp = TmpFilePath(p, name)
241240
defer func() {
242241
if err != nil {
243242
_ = conn.share.Remove(tmp)

pkg/object/file.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ import (
2222
"fmt"
2323
"io"
2424
"io/fs"
25-
"math/rand"
2625
"os"
2726
"path"
2827
"path/filepath"
2928
"runtime"
3029
"sort"
31-
"strconv"
3230
"strings"
3331

3432
"github.com/juicedata/juicefs/pkg/utils"
@@ -160,7 +158,7 @@ func (d *filestore) Put(ctx context.Context, key string, in io.Reader, getters .
160158
if len(name) > 200 {
161159
name = name[:200]
162160
}
163-
tmp = filepath.Join(filepath.Dir(p), "."+name+".tmp"+strconv.Itoa(rand.Int()))
161+
tmp = TmpFilePath(p, name)
164162
defer func() {
165163
if err != nil {
166164
_ = os.Remove(tmp)

pkg/object/hdfs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"fmt"
2727
"io"
2828
"io/fs"
29-
"math/rand"
3029
"os"
3130
"os/user"
3231
"path"
@@ -139,7 +138,7 @@ func (h *hdfsclient) Put(ctx context.Context, key string, in io.Reader, getters
139138
if len(name) > 200 {
140139
name = name[:200]
141140
}
142-
tmp = path.Join(path.Dir(p), fmt.Sprintf(".%s.tmp.%d", name, rand.Int()))
141+
tmp = TmpFilePath(p, name)
143142
defer func() {
144143
if err != nil {
145144
_ = h.c.Remove(tmp)

pkg/object/nfs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"context"
2525
"fmt"
2626
"io"
27-
"math/rand"
2827
"os"
2928
"os/user"
3029
"path"
@@ -176,7 +175,7 @@ func (n *nfsStore) Put(ctx context.Context, key string, in io.Reader, getters ..
176175
if len(name) > 200 {
177176
name = name[:200]
178177
}
179-
tmp = path.Join(path.Dir(p), fmt.Sprintf(".%s.tmp.%d", name, rand.Int()))
178+
tmp = TmpFilePath(p, name)
180179
defer func() {
181180
if err != nil {
182181
_ = n.target.Remove(tmp)

pkg/object/object_storage.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import (
2020
"context"
2121
"fmt"
2222
"io"
23+
"math/rand"
2324
"net/url"
2425
"os"
26+
"path/filepath"
2527
"strconv"
2628
"strings"
2729
"sync"
@@ -315,3 +317,7 @@ func decodeKey(value string, typ *string) (string, error) {
315317
}
316318
return value, nil
317319
}
320+
321+
func TmpFilePath(parent, name string) string {
322+
return filepath.Join(filepath.Dir(parent), ".jfs."+name+".tmp."+strconv.Itoa(rand.Int()))
323+
}

pkg/object/sftp.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"context"
1212
"fmt"
1313
"io"
14-
"math/rand"
1514
"net"
1615
"net/url"
1716
"os"
@@ -236,7 +235,7 @@ func (f *sftpStore) Put(ctx context.Context, key string, in io.Reader, getters .
236235
if len(name) > 200 {
237236
name = name[:200]
238237
}
239-
tmp = path.Join(path.Dir(p), fmt.Sprintf(".%s.tmp.%d", name, rand.Int()))
238+
tmp = TmpFilePath(p, name)
240239
defer func() {
241240
if err != nil {
242241
_ = c.sftpClient.Remove(tmp)

0 commit comments

Comments
 (0)