Establish actual relationship of the Python binding's `LogEntry`, `StateMachine` types

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

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

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
distributed-systems

Hướng nghiên cứu

Bắt đầu bằng cách so sánh các khai báo tạm thời của AbstractLogEntry và AbstractStateMachine trong tệp .pyi với raftify/init.py đã cài đặt và nội dung của Python wheel. Tái hiện lỗi import đã cho, sau đó xác minh rằng hai kiểu này có sẵn từ raftify và hỗ trợ các mối quan hệ mẫu giữa SetCommand và HashStore mà không có lỗi import.

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

Mô tả

low-priority python

Ideally, the SetCommand and LogEntry in the sample code should be represented as shown below.

class SetCommand(AbstractLogEntry):
    """
    Represent simple key-value command.
    Use pickle to serialize the data.
    """

    def __init__(self, key: str, value: str) -> None:
        self.key = key
        self.value = value

    @override
    def encode(self) -> bytes:
        return pickle.dumps(self.__dict__)

    @override
    @classmethod
    def decode(cls, packed: bytes) -> "SetCommand":
        unpacked = pickle.loads(packed)
        return cls(unpacked["key"], unpacked["value"])


class HashStore(AbstractStateMachine):
    """
    A simple key-value store that stores data in memory.
    Use pickle to serialize the data.
    """

    def __init__(self):
        self._store = dict()
        self._loop = asyncio.get_running_loop()

    def get(self, key: str) -> Optional[str]:
        return self._store.get(key)

    def as_dict(self) -> dict:
        return self._store

    @override
    async def apply(self, msg: bytes) -> bytes:
        message = SetCommand.decode(msg)
        self._store[message.key] = message.value
        return msg

    @override
    async def snapshot(self) -> bytes:
        return pickle.dumps(self._store)

    @override
    async def restore(self, snapshot: bytes) -> None:
        self._store = pickle.loads(snapshot)

However, for now, these two types are only temporarily defined in the .pyi file and are not actually included in the whl, resulting in an import error.

from raftify import AbstractLogEntry, AbstractStateMachine
ImportError: cannot import name 'AbstractLogEntry' from 'raftify' (/opt/homebrew/lib/python3.12/site-packages/raftify/__init__.py)
Ngôn ngữ chính
Rust
Star
44
Fork
14
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

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 lablup/raftify

Tất cả issue của lablup/raftify

Issue tương tự

Thêm issue về Rust

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.