mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Clear old parent reference on resetting image parent
On migration 2 different images can end up with same content addressable ID, meaning `SetParent` will be called multiple times. Previous version did not clear the old in-memory reference. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
		
							parent
							
								
									b3bacb42af
								
							
						
					
					
						commit
						4852932494
					
				
					 2 changed files with 59 additions and 0 deletions
				
			
		| 
						 | 
					@ -231,6 +231,9 @@ func (is *store) SetParent(id, parent ID) error {
 | 
				
			||||||
	if parentMeta == nil {
 | 
						if parentMeta == nil {
 | 
				
			||||||
		return fmt.Errorf("unknown parent image ID %s", parent.String())
 | 
							return fmt.Errorf("unknown parent image ID %s", parent.String())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if parent, err := is.GetParent(id); err == nil && is.images[parent] != nil {
 | 
				
			||||||
 | 
							delete(is.images[parent].children, id)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	parentMeta.children[id] = struct{}{}
 | 
						parentMeta.children[id] = struct{}{}
 | 
				
			||||||
	return is.fs.SetMetadata(id, "parent", []byte(parent))
 | 
						return is.fs.SetMetadata(id, "parent", []byte(parent))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -233,6 +233,62 @@ func TestSearchAfterDelete(t *testing.T) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestParentReset(t *testing.T) {
 | 
				
			||||||
 | 
						tmpdir, err := ioutil.TempDir("", "images-fs-store")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						defer os.RemoveAll(tmpdir)
 | 
				
			||||||
 | 
						fs, err := NewFSStoreBackend(tmpdir)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						is, err := NewImageStore(fs, &mockLayerGetReleaser{})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						id, err := is.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						id2, err := is.Create([]byte(`{"comment": "abc2", "rootfs": {"type": "layers"}}`))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						id3, err := is.Create([]byte(`{"comment": "abc3", "rootfs": {"type": "layers"}}`))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := is.SetParent(id, id2); err != nil {
 | 
				
			||||||
 | 
							t.Fatal(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ids := is.Children(id2)
 | 
				
			||||||
 | 
						if actual, expected := len(ids), 1; expected != actual {
 | 
				
			||||||
 | 
							t.Fatalf("wrong number of children: %d, got %d", expected, actual)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := is.SetParent(id, id3); err != nil {
 | 
				
			||||||
 | 
							t.Fatal(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ids = is.Children(id2)
 | 
				
			||||||
 | 
						if actual, expected := len(ids), 0; expected != actual {
 | 
				
			||||||
 | 
							t.Fatalf("wrong number of children after parent reset: %d, got %d", expected, actual)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ids = is.Children(id3)
 | 
				
			||||||
 | 
						if actual, expected := len(ids), 1; expected != actual {
 | 
				
			||||||
 | 
							t.Fatalf("wrong number of children after parent reset: %d, got %d", expected, actual)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type mockLayerGetReleaser struct{}
 | 
					type mockLayerGetReleaser struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (ls *mockLayerGetReleaser) Get(layer.ChainID) (layer.Layer, error) {
 | 
					func (ls *mockLayerGetReleaser) Get(layer.ChainID) (layer.Layer, error) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue