Skip to content

Commit

Permalink
fix: Broken python binding CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Sep 30, 2024
1 parent 85e61a6 commit 8c83e0d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,9 @@ Last index: 3

## Bootstrapping from WAL

You can bootstrap cluster from WAL (Write Ahead Logs), and WAL's snapshot.

This feature is useful in cases where a failure occurs in more than the number of nodes in the quorum, requiring a restart of the cluster, or when there is a need to reboot the cluster after making a batch change to the cluster members.

Use the `restore_wal_from` and `restore_wal_snapshot_from` options in `RaftConfig`.

See [this example](https://github.com/lablup/raftify/blob/main/examples/memstore/static-members/src/main.rs) for more details.
If there are previous logs remaining in the log directory, the raft node will automatically apply them after the node is bootstrapped.
If you intend to bootstrap the cluster from the scratch, please remove the previous log directory.
To ignore the previous logs and bootstrap the cluster from a snapshot, use the `Config.bootstrap_from_snapshot` option.

## Support for other languages

Expand Down
8 changes: 2 additions & 6 deletions binding/python/examples/cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_requirements(env: str = None):
version=VERSION,
description="Experimental High level Raft framework",
long_description=README,
long_description_content_type='text/markdown',
long_description_content_type="text/markdown",
author="Lablup Inc.",
maintainer="jopemachine",
maintainer_email="[email protected]",
Expand All @@ -35,9 +35,5 @@ def get_requirements(env: str = None):
install_requires=default_requires,
zip_safe=False,
include_package_data=True,
entry_points={
'console_scripts': [
'raftify_cli = raftify_cli.cli:main'
]
}
entry_points={"console_scripts": ["raftify_cli = raftify_cli.cli:main"]},
)
4 changes: 4 additions & 0 deletions binding/python/examples/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .deserializer import register_custom_deserializer
from .web_server_api import routes, WebServer
from .state_machine import HashStore
from .utils import ensure_directory_exist, get_storage_path


def load_peers() -> Peers:
Expand Down Expand Up @@ -113,6 +114,9 @@ async def main():
logger = Logger(setup_logger())
store = HashStore()

storage_path = get_storage_path(cfg.log_dir, node_id)
ensure_directory_exist(storage_path)

tasks = []
raft = Raft.bootstrap(node_id, raft_addr, store, cfg, logger)
tasks.append(raft.run())
Expand Down
10 changes: 10 additions & 0 deletions binding/python/examples/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os


def get_storage_path(log_dir: str, node_id: int) -> str:
return f"{log_dir}/node-{node_id}"


def ensure_directory_exist(storage_path: str):
if not os.path.exists(storage_path):
os.makedirs(storage_path)
8 changes: 7 additions & 1 deletion binding/python/tests/data_replication.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import asyncio
import pytest
from utils import load_peers, wait_for_until_cluster_size_increase
from utils import (
ensure_directory_exist,
load_peers,
wait_for_until_cluster_size_increase,
)
from constant import THREE_NODE_EXAMPLE
from harness.raft_server import RAFTS, run_rafts
from harness.state_machine import SetCommand


@pytest.mark.asyncio
async def test_data_replication():
ensure_directory_exist("./logs")

peers = load_peers(THREE_NODE_EXAMPLE)
asyncio.create_task(run_rafts(peers))
await asyncio.sleep(2)
Expand Down
10 changes: 10 additions & 0 deletions binding/python/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from asyncio import sleep
import os
import tomli
from pathlib import Path
from raftify import InitialRole, Peer, Peers, Raft
Expand Down Expand Up @@ -45,3 +46,12 @@ async def wait_for_until_cluster_size_decrease(raft: Raft, target: int):

# Wait for the conf_change reflected to the cluster
await sleep(0.1)


def get_storage_path(log_dir: str, node_id: int) -> str:
return f"{log_dir}/node-{node_id}"


def ensure_directory_exist(storage_path: str):
if not os.path.exists(storage_path):
os.makedirs(storage_path)

0 comments on commit 8c83e0d

Please sign in to comment.