lablup / lablup/raftify

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

Open
#99 0 comments 0 reactions 0 assignees View on GitHub
low-priority python
Dominant language
Rust
Stars
44
Forks
14
PR merge metrics
No merged PRs in 30d

Description

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

```py
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)
```

Contributor guide

No contributing guide indexed for this repository

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.