Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Juicedata
JuiceFS
提交
7472e165
JuiceFS
项目概览
Juicedata
/
JuiceFS
通知
10
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
JuiceFS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7472e165
编写于
1月 25, 2021
作者:
D
Davies Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor
上级
35b1cd2a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
83 addition
and
60 deletion
+83
-60
cmd/mount.go
cmd/mount.go
+1
-60
pkg/vfs/compact.go
pkg/vfs/compact.go
+82
-0
未找到文件。
cmd/mount.go
浏览文件 @
7472e165
...
...
@@ -16,7 +16,6 @@
package
main
import
(
"context"
"fmt"
"net/http"
_
"net/http/pprof"
...
...
@@ -172,7 +171,7 @@ func mount(c *cli.Context) error {
m
.
OnMsg
(
meta
.
CompactChunk
,
meta
.
MsgCallback
(
func
(
args
...
interface
{})
error
{
slices
:=
args
[
0
]
.
([]
meta
.
Slice
)
chunkid
:=
args
[
1
]
.
(
uint64
)
return
c
ompact
(
chunkConf
,
store
,
slices
,
chunkid
)
return
vfs
.
C
ompact
(
chunkConf
,
store
,
slices
,
chunkid
)
}))
conf
:=
&
vfs
.
Config
{
...
...
@@ -315,61 +314,3 @@ func mountFlags() *cli.Command {
},
}
}
func
readSlice
(
store
chunk
.
ChunkStore
,
s
*
meta
.
Slice
,
page
*
chunk
.
Page
,
off
int
)
error
{
buf
:=
page
.
Data
read
:=
0
reader
:=
store
.
NewReader
(
s
.
Chunkid
,
int
(
s
.
Size
))
for
read
<
len
(
buf
)
{
p
:=
page
.
Slice
(
read
,
len
(
buf
)
-
read
)
n
,
err
:=
reader
.
ReadAt
(
context
.
Background
(),
p
,
off
+
int
(
s
.
Off
))
p
.
Release
()
if
n
==
0
&&
err
!=
nil
{
return
err
}
read
+=
n
off
+=
n
}
return
nil
}
func
compact
(
conf
chunk
.
Config
,
store
chunk
.
ChunkStore
,
slices
[]
meta
.
Slice
,
chunkid
uint64
)
error
{
writer
:=
store
.
NewWriter
(
chunkid
)
defer
writer
.
Abort
()
var
pos
int
for
i
,
s
:=
range
slices
{
if
s
.
Chunkid
==
0
{
_
,
err
:=
writer
.
WriteAt
(
make
([]
byte
,
int
(
s
.
Len
)),
int64
(
pos
))
if
err
!=
nil
{
return
err
}
pos
+=
int
(
s
.
Len
)
continue
}
var
read
int
for
read
<
int
(
s
.
Len
)
{
l
:=
utils
.
Min
(
conf
.
BlockSize
,
int
(
s
.
Len
)
-
read
)
p
:=
chunk
.
NewOffPage
(
l
)
if
err
:=
readSlice
(
store
,
&
s
,
p
,
read
);
err
!=
nil
{
logger
.
Infof
(
"can't compact chunk %d, retry later, read %d: %s"
,
chunkid
,
i
,
err
)
p
.
Release
()
return
err
}
_
,
err
:=
writer
.
WriteAt
(
p
.
Data
,
int64
(
pos
+
read
))
p
.
Release
()
if
err
!=
nil
{
logger
.
Errorf
(
"can't compact chunk %d, retry later, write: %s"
,
chunkid
,
err
)
return
err
}
read
+=
l
if
pos
+
read
>=
conf
.
BlockSize
{
if
err
=
writer
.
FlushTo
(
pos
+
read
);
err
!=
nil
{
panic
(
err
)
}
}
}
pos
+=
int
(
s
.
Len
)
}
return
writer
.
Finish
(
pos
)
}
pkg/vfs/compact.go
0 → 100644
浏览文件 @
7472e165
/*
* JuiceFS, Copyright (C) 2020 Juicedata, Inc.
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package
vfs
import
(
"context"
"github.com/juicedata/juicefs/pkg/chunk"
"github.com/juicedata/juicefs/pkg/meta"
"github.com/juicedata/juicefs/pkg/utils"
)
func
readSlice
(
store
chunk
.
ChunkStore
,
s
*
meta
.
Slice
,
page
*
chunk
.
Page
,
off
int
)
error
{
buf
:=
page
.
Data
read
:=
0
reader
:=
store
.
NewReader
(
s
.
Chunkid
,
int
(
s
.
Size
))
for
read
<
len
(
buf
)
{
p
:=
page
.
Slice
(
read
,
len
(
buf
)
-
read
)
n
,
err
:=
reader
.
ReadAt
(
context
.
Background
(),
p
,
off
+
int
(
s
.
Off
))
p
.
Release
()
if
n
==
0
&&
err
!=
nil
{
return
err
}
read
+=
n
off
+=
n
}
return
nil
}
func
Compact
(
conf
chunk
.
Config
,
store
chunk
.
ChunkStore
,
slices
[]
meta
.
Slice
,
chunkid
uint64
)
error
{
writer
:=
store
.
NewWriter
(
chunkid
)
defer
writer
.
Abort
()
var
pos
int
for
i
,
s
:=
range
slices
{
if
s
.
Chunkid
==
0
{
_
,
err
:=
writer
.
WriteAt
(
make
([]
byte
,
int
(
s
.
Len
)),
int64
(
pos
))
if
err
!=
nil
{
return
err
}
pos
+=
int
(
s
.
Len
)
continue
}
var
read
int
for
read
<
int
(
s
.
Len
)
{
l
:=
utils
.
Min
(
conf
.
BlockSize
,
int
(
s
.
Len
)
-
read
)
p
:=
chunk
.
NewOffPage
(
l
)
if
err
:=
readSlice
(
store
,
&
s
,
p
,
read
);
err
!=
nil
{
logger
.
Infof
(
"can't compact chunk %d, retry later, read %d: %s"
,
chunkid
,
i
,
err
)
p
.
Release
()
return
err
}
_
,
err
:=
writer
.
WriteAt
(
p
.
Data
,
int64
(
pos
+
read
))
p
.
Release
()
if
err
!=
nil
{
logger
.
Errorf
(
"can't compact chunk %d, retry later, write: %s"
,
chunkid
,
err
)
return
err
}
read
+=
l
if
pos
+
read
>=
conf
.
BlockSize
{
if
err
=
writer
.
FlushTo
(
pos
+
read
);
err
!=
nil
{
panic
(
err
)
}
}
}
pos
+=
int
(
s
.
Len
)
}
return
writer
.
Finish
(
pos
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录