design.txt 992 B

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