objectstore: copy on write semantics for Object
Since Object knows its base now, the initialization of the tree with the content of its base can be delayed until the moment someone wants to actually modify the tree, thus implementing copy on write semantics. For this a new `write` method is added that will initialize the base and return the writable tree. It should be used instead of `path` whenever the a client wants to write to the tree of the Object. Adapt the pipeline and the tests to use the new `write` method in all the appropriate places. NB: since the intention can not be inferred when using `path` directly, the Object is still being initialized there.
This commit is contained in:
parent
0874b80734
commit
39213b7f44
3 changed files with 27 additions and 11 deletions
|
|
@ -25,7 +25,8 @@ class TestObjectStore(unittest.TestCase):
|
|||
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
|
||||
object_store = objectstore.ObjectStore(tmp)
|
||||
with object_store.new("a") as tree:
|
||||
p = Path(f"{tree.path}/A")
|
||||
path = tree.write()
|
||||
p = Path(f"{path}/A")
|
||||
p.touch()
|
||||
|
||||
assert os.path.exists(f"{object_store.refs}/a")
|
||||
|
|
@ -35,9 +36,10 @@ class TestObjectStore(unittest.TestCase):
|
|||
assert len(os.listdir(f"{object_store.refs}/a/")) == 1
|
||||
|
||||
with object_store.new("b") as tree:
|
||||
p = Path(f"{tree.path}/A")
|
||||
path = tree.write()
|
||||
p = Path(f"{path}/A")
|
||||
p.touch()
|
||||
p = Path(f"{tree.path}/B")
|
||||
p = Path(f"{path}/B")
|
||||
p.touch()
|
||||
|
||||
assert os.path.exists(f"{object_store.refs}/b")
|
||||
|
|
@ -51,12 +53,14 @@ class TestObjectStore(unittest.TestCase):
|
|||
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
|
||||
object_store = objectstore.ObjectStore(tmp)
|
||||
with object_store.new("a") as tree:
|
||||
p = Path(f"{tree.path}/A")
|
||||
path = tree.write()
|
||||
p = Path(f"{path}/A")
|
||||
p.touch()
|
||||
|
||||
with object_store.new("b") as tree:
|
||||
path = tree.write()
|
||||
shutil.copy2(f"{object_store.refs}/a/A",
|
||||
f"{tree.path}/A")
|
||||
f"{path}/A")
|
||||
|
||||
assert os.path.exists(f"{object_store.refs}/a")
|
||||
assert os.path.exists(f"{object_store.refs}/a/A")
|
||||
|
|
@ -70,10 +74,12 @@ class TestObjectStore(unittest.TestCase):
|
|||
def test_snapshot(self):
|
||||
object_store = objectstore.ObjectStore(self.store)
|
||||
with object_store.new("b") as tree:
|
||||
p = Path(f"{tree.path}/A")
|
||||
path = tree.write()
|
||||
p = Path(f"{path}/A")
|
||||
p.touch()
|
||||
object_store.snapshot(tree, "a")
|
||||
p = Path(f"{tree.path}/B")
|
||||
path = tree.write()
|
||||
p = Path(f"{path}/B")
|
||||
p.touch()
|
||||
|
||||
# check the references exist
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue