mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #5172 from pnasrat/5166-large-image-graph-restore
Enable construction of TruncIndex from id array.
This commit is contained in:
commit
413190e159
4 changed files with 34 additions and 7 deletions
|
@ -40,7 +40,7 @@ func NewGraph(root string, driver graphdriver.Driver) (*Graph, error) {
|
||||||
|
|
||||||
graph := &Graph{
|
graph := &Graph{
|
||||||
Root: abspath,
|
Root: abspath,
|
||||||
idIndex: utils.NewTruncIndex(),
|
idIndex: utils.NewTruncIndex([]string{}),
|
||||||
driver: driver,
|
driver: driver,
|
||||||
}
|
}
|
||||||
if err := graph.restore(); err != nil {
|
if err := graph.restore(); err != nil {
|
||||||
|
@ -54,12 +54,14 @@ func (graph *Graph) restore() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
var ids = []string{}
|
||||||
for _, v := range dir {
|
for _, v := range dir {
|
||||||
id := v.Name()
|
id := v.Name()
|
||||||
if graph.driver.Exists(id) {
|
if graph.driver.Exists(id) {
|
||||||
graph.idIndex.Add(id)
|
ids = append(ids, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
graph.idIndex = utils.NewTruncIndex(ids)
|
||||||
utils.Debugf("Restored %d elements", len(dir))
|
utils.Debugf("Restored %d elements", len(dir))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -779,7 +779,7 @@ func NewRuntimeFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*
|
||||||
containers: list.New(),
|
containers: list.New(),
|
||||||
graph: g,
|
graph: g,
|
||||||
repositories: repositories,
|
repositories: repositories,
|
||||||
idIndex: utils.NewTruncIndex(),
|
idIndex: utils.NewTruncIndex([]string{}),
|
||||||
sysInfo: sysInfo,
|
sysInfo: sysInfo,
|
||||||
volumes: volumes,
|
volumes: volumes,
|
||||||
config: config,
|
config: config,
|
||||||
|
|
|
@ -426,12 +426,17 @@ type TruncIndex struct {
|
||||||
bytes []byte
|
bytes []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTruncIndex() *TruncIndex {
|
func NewTruncIndex(ids []string) (idx *TruncIndex) {
|
||||||
return &TruncIndex{
|
idx = &TruncIndex{
|
||||||
index: suffixarray.New([]byte{' '}),
|
|
||||||
ids: make(map[string]bool),
|
ids: make(map[string]bool),
|
||||||
bytes: []byte{' '},
|
bytes: []byte{' '},
|
||||||
}
|
}
|
||||||
|
for _, id := range ids {
|
||||||
|
idx.ids[id] = true
|
||||||
|
idx.bytes = append(idx.bytes, []byte(id+" ")...)
|
||||||
|
}
|
||||||
|
idx.index = suffixarray.New(idx.bytes)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (idx *TruncIndex) Add(id string) error {
|
func (idx *TruncIndex) Add(id string) error {
|
||||||
|
|
|
@ -138,7 +138,8 @@ func TestRaceWriteBroadcaster(t *testing.T) {
|
||||||
|
|
||||||
// Test the behavior of TruncIndex, an index for querying IDs from a non-conflicting prefix.
|
// Test the behavior of TruncIndex, an index for querying IDs from a non-conflicting prefix.
|
||||||
func TestTruncIndex(t *testing.T) {
|
func TestTruncIndex(t *testing.T) {
|
||||||
index := NewTruncIndex()
|
ids := []string{}
|
||||||
|
index := NewTruncIndex(ids)
|
||||||
// Get on an empty index
|
// Get on an empty index
|
||||||
if _, err := index.Get("foobar"); err == nil {
|
if _, err := index.Get("foobar"); err == nil {
|
||||||
t.Fatal("Get on an empty index should return an error")
|
t.Fatal("Get on an empty index should return an error")
|
||||||
|
@ -218,6 +219,25 @@ func assertIndexGet(t *testing.T, index *TruncIndex, input, expectedResult strin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkTruncIndexAdd(b *testing.B) {
|
||||||
|
ids := []string{"banana", "bananaa", "bananab"}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
index := NewTruncIndex([]string{})
|
||||||
|
for _, id := range ids {
|
||||||
|
index.Add(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkTruncIndexNew(b *testing.B) {
|
||||||
|
ids := []string{"banana", "bananaa", "bananab"}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
NewTruncIndex(ids)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func assertKernelVersion(t *testing.T, a, b *KernelVersionInfo, result int) {
|
func assertKernelVersion(t *testing.T, a, b *KernelVersionInfo, result int) {
|
||||||
if r := CompareKernelVersion(a, b); r != result {
|
if r := CompareKernelVersion(a, b); r != result {
|
||||||
t.Fatalf("Unexpected kernel version comparison result. Found %d, expected %d", r, result)
|
t.Fatalf("Unexpected kernel version comparison result. Found %d, expected %d", r, result)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue