design.txt 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """
  2. Dedupstore
  3. ==========
  4. TODO
  5. ----
  6. * Symbolic links
  7. * Owner, group, mode
  8. * msgpack
  9. * Hard links
  10. cache = Cache(path,)
  11. for file in files:
  12. chunks = chunkify(file)
  13. for chunk in chunkify(file):
  14. if chunk.sha in cache:
  15. cache.chunk_inc_ref(chunk)
  16. else:
  17. fs.add_chunk(chunk)
  18. entry = Entry
  19. archive.add(entry)
  20. Repository layout
  21. -----------------
  22. REPO/README
  23. REPO/VERSION
  24. REPO/tid = x
  25. REPO/data/
  26. REPO/txn-active/tid
  27. REPO/txn-active/add/<PATH>/
  28. REPO/txn-active/delete/<PATH>/
  29. REPO/txn-active/tid
  30. REPO/txn-commit/add/<PATH>/
  31. REPO/txn-commit/delete/<PATH>/
  32. REPO/archives/<ARCHIVENAME>
  33. REPO/blocks/XX/YY/XYZ
  34. txn_completed/add/<PATH>/
  35. txn_completed/delete/<PATH>/
  36. API
  37. ---
  38. """
  39. class Cache(object):
  40. def chunk_inc_ref(self, chunk):
  41. self.chunk_refcount.setdefault(chunk.sha, 0)
  42. self.chunk_refcount[chunk.sha] += 1
  43. def chunk_dec_ref(self, chunk):
  44. assert self.chunk_refcount.get(chunk.sha, 0) > 0
  45. self.chunk_refcount[chunk.sha] -= 1
  46. if self.chunk_refcount[chunk.sha] == 0:
  47. self.fs.delete_chunk(self.sha)
  48. txn = txn_begin()