Give each archive its own morango instance identity

Đang mở
#380 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
django, python
Lĩnh vực
backend, databases

Hướng nghiên cứu

Start with the Archive and ArchiveDatabase entry points in morango/sync/archive.py, then compare InstanceIDModel.get_current_instance_and_increment_counter in morango/models/core.py:191. Review tests/testapp/tests/sync/test_archive.py and the Default-DB guard; done means the archive rows and counters satisfy the acceptance criteria without querying the default database. This work is blocked by #378.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

DEV: backend DEV: distributions P0 - critical TAG: new feature

Overview

An archive gets its own DatabaseIDModel and InstanceIDModel rows, separate from the host instance. This issue is part of milestone M5 (archive).

Background & Motivation

Morango tracks sync state by instance ID. Counters, record max counters, and last_saved_instance all use it. An archive represents a standalone morango instance that received a push, so it needs an identity of its own.

The dequeue step on the archive increments the counter of the current instance. That counter must belong to the archive, not to the host. The host method InstanceIDModel.get_or_create_current_instance reads the host environment and caches its result, so the archive cannot use it.

Design: spec. Plan: implementation plan, Task 19.

Description & Expected Outcomes

When an archive is created, the archive writes one DatabaseIDModel row and one InstanceIDModel row into its own database. The instance row identifies the archive as morango-archive and records the final archive path. The instance ID is sha2_uuid(database_id, system_id, node_id), the same formula that the host instance uses. InstanceIDModel has no calculate_uuid().

Both rows are written with a bulk insert through the archive handle, never with save() or objects.create(). DatabaseIDModel.save sets current=False on every DatabaseIDModel row of the host database, even when the save targets the archive (#362).

The archive database handle knows its own current instance. When code asks the archive handle for the current instance and a counter increment, the handle increments the archive row only. The host instance does not change.

Deliverables & Contracts

The feature delivers these capabilities:

  • Archive.write_identity() creates the archive instance and returns it.
  • ArchiveDatabase.current_instance_and_increment_counter() increments and returns the archive instance row.
  • Neither method sends a query to the default database.
Acceptance Criteria
  • After write_identity, the archive alias holds exactly one DatabaseIDModel row and one InstanceIDModel row.
  • The archive instance has platform == "morango-archive" and id == sha2_uuid(database_id, "", "").
  • The host current instance is unchanged after write_identity.
  • The host current DatabaseIDModel still has current=True after write_identity.
  • Two calls to current_instance_and_increment_counter() return counter values 1 and 2.
  • All tests pass inside assert_no_default_db_queries().

Technical Pointers & Architecture

  • Target Components / Context: morango/sync/archive.py (Archive, ArchiveDatabase).
  • Related Patterns: InstanceIDModel.get_current_instance_and_increment_counter (morango/models/core.py:191) is the host equivalent.
  • Data Model & Schema Considerations: No schema change. The rows use the existing morango models in the archive alias.
  • Resilience & Failure Modes: If a write fails, the error propagates to Archive.create or DiskSyncConnection.create_sync_session, which discard the archive.

Notes & Tradeoffs

  • Dependencies: Blocked by: #378 (Archive.create, discard, and ArchiveDatabase). Blocks: #383.
  • Testing Requirements: Unit tests in tests/testapp/tests/sync/test_archive.py under the Default-DB guard.
  • Tradeoffs & Alternatives Considered: The spec rejects an optional current_instance argument on _dequeue_into_store. A None value there acts as a hidden flag. The database handle selects the instance through polymorphism instead.
  • Compatibility & Migrations: Phase 4 (incremental update) must derive a new archive instance on each update. Two copies of one file otherwise share an instance ID.

Metadata

  • Complexity: Low
  • Target Branch: release-v0.9.x

AI Usage

Drafted with Claude (Claude Code) from the approved design spec and implementation plan. The author reviewed the requirements, and the code references were checked against the release-v0.9.x codebase.

Ngôn ngữ chính
Python
Star
15
Fork
27
Merge trung bình
6 ngày 44 phút
Pull request đã merge (30 ngày)
13

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của learningequality/morango

Tất cả issue của learningequality/morango

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.