Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
01498b89
提交
01498b89
authored
9月 03, 2019
作者:
Steven Allen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commands/repo: add the provider record information to stat
Useful for debugging repo usage.
上级
d778b84f
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
45 行增加
和
26 行删除
+45
-26
repo.go
core/commands/repo.go
+2
-0
stat.go
core/corerepo/stat.go
+42
-26
go.mod
go.mod
+1
-0
没有找到文件。
core/commands/repo.go
浏览文件 @
01498b89
...
...
@@ -195,6 +195,8 @@ Version string The repo version.
if
!
sizeOnly
{
fmt
.
Fprintf
(
wtr
,
"NumObjects:
\t
%d
\n
"
,
stat
.
NumObjects
)
fmt
.
Fprintf
(
wtr
,
"NumValues:
\t
%d
\n
"
,
stat
.
NumValues
)
fmt
.
Fprintf
(
wtr
,
"NumProviders:
\t
%d
\n
"
,
stat
.
NumProviders
)
}
printSize
(
"RepoSize"
,
stat
.
RepoSize
)
...
...
core/corerepo/stat.go
浏览文件 @
01498b89
package
corerepo
import
(
"context"
"fmt"
"math"
context
"context"
"strings"
"github.com/ipfs/go-ipfs/core"
fsrepo
"github.com/ipfs/go-ipfs/repo/fsrepo"
humanize
"github.com/dustin/go-humanize"
dsq
"github.com/ipfs/go-datastore/query"
)
// SizeStat wraps information about the repository size and its limit.
...
...
@@ -21,45 +22,60 @@ type SizeStat struct {
// Stat wraps information about the objects stored on disk.
type
Stat
struct
{
SizeStat
// Number of blocks. Called "objects" for historical reasons".
NumObjects
uint64
RepoPath
string
Version
string
// Number of provider records.
NumProviders
uint64
// Total number of values in the datastore.
NumValues
uint64
RepoPath
string
Version
string
}
// NoLimit represents the value for unlimited storage
const
NoLimit
uint64
=
math
.
MaxUint64
// RepoStat returns a *Stat object with all the fields set.
func
RepoStat
(
ctx
context
.
Context
,
n
*
core
.
IpfsNode
)
(
Stat
,
error
)
{
sizeStat
,
err
:=
RepoSize
(
ctx
,
n
)
func
RepoStat
(
ctx
context
.
Context
,
n
*
core
.
IpfsNode
)
(
stat
Stat
,
err
error
)
{
stat
.
Version
=
fmt
.
Sprintf
(
"fs-repo@%d"
,
fsrepo
.
RepoVersion
)
stat
.
RepoPath
,
err
=
fsrepo
.
BestKnownPath
()
if
err
!=
nil
{
return
Stat
{}
,
err
return
stat
,
err
}
allKeys
,
err
:=
n
.
Blockstore
.
AllKeysChan
(
ctx
)
stat
.
SizeStat
,
err
=
RepoSize
(
ctx
,
n
)
if
err
!=
nil
{
return
Stat
{},
err
}
count
:=
uint64
(
0
)
for
range
allKeys
{
count
++
return
stat
,
err
}
path
,
err
:=
fsrepo
.
BestKnownPath
()
// count the records.
query
,
err
:=
n
.
Repo
.
Datastore
()
.
Query
(
dsq
.
Query
{
KeysOnly
:
true
})
if
err
!=
nil
{
return
Stat
{}
,
err
return
stat
,
err
}
defer
query
.
Close
()
return
Stat
{
SizeStat
:
SizeStat
{
RepoSize
:
sizeStat
.
RepoSize
,
StorageMax
:
sizeStat
.
StorageMax
,
},
NumObjects
:
count
,
RepoPath
:
path
,
Version
:
fmt
.
Sprintf
(
"fs-repo@%d"
,
fsrepo
.
RepoVersion
),
},
nil
for
{
if
err
:=
ctx
.
Err
();
err
!=
nil
{
return
stat
,
err
}
res
,
ok
:=
query
.
NextSync
()
if
!
ok
{
return
stat
,
nil
}
if
res
.
Error
!=
nil
{
return
stat
,
res
.
Error
}
stat
.
NumValues
++
if
strings
.
HasPrefix
(
res
.
Key
,
"/blocks/"
)
{
stat
.
NumObjects
++
}
else
if
strings
.
HasPrefix
(
res
.
Key
,
"/providers/"
)
{
stat
.
NumProviders
++
}
}
}
// RepoSize returns a *Stat object with the RepoSize and StorageMax fields set.
...
...
go.mod
浏览文件 @
01498b89
...
...
@@ -112,6 +112,7 @@ require (
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac // indirect
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect
google.golang.org/appengine v1.4.0 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28
gotest.tools/gotestsum v0.3.4
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论