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

Open
#99 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Start by comparing the temporary AbstractLogEntry and AbstractStateMachine declarations in the .pyi file with the installed raftify/init.py and the Python wheel contents. Reproduce the shown import error, then verify that the two types are available from raftify and support the sample SetCommand and HashStore relationships without import errors.

Written by the indexing model from the issue text.

Description

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)
Dominant language
Rust
Stars
44
Forks
14
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lablup/raftify

All issues in lablup/raftify

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.