Skip to content

Commit 8c83e0d

Browse files
committed
fix: Broken python binding CI
1 parent 85e61a6 commit 8c83e0d

File tree

6 files changed

+36
-14
lines changed

6 files changed

+36
-14
lines changed

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,9 @@ Last index: 3
199199

200200
## Bootstrapping from WAL
201201

202-
You can bootstrap cluster from WAL (Write Ahead Logs), and WAL's snapshot.
203-
204-
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.
205-
206-
Use the `restore_wal_from` and `restore_wal_snapshot_from` options in `RaftConfig`.
207-
208-
See [this example](https://github.com/lablup/raftify/blob/main/examples/memstore/static-members/src/main.rs) for more details.
202+
If there are previous logs remaining in the log directory, the raft node will automatically apply them after the node is bootstrapped.
203+
If you intend to bootstrap the cluster from the scratch, please remove the previous log directory.
204+
To ignore the previous logs and bootstrap the cluster from a snapshot, use the `Config.bootstrap_from_snapshot` option.
209205

210206
## Support for other languages
211207

binding/python/examples/cli/setup.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def get_requirements(env: str = None):
2323
version=VERSION,
2424
description="Experimental High level Raft framework",
2525
long_description=README,
26-
long_description_content_type='text/markdown',
26+
long_description_content_type="text/markdown",
2727
author="Lablup Inc.",
2828
maintainer="jopemachine",
2929
maintainer_email="[email protected]",
@@ -35,9 +35,5 @@ def get_requirements(env: str = None):
3535
install_requires=default_requires,
3636
zip_safe=False,
3737
include_package_data=True,
38-
entry_points={
39-
'console_scripts': [
40-
'raftify_cli = raftify_cli.cli:main'
41-
]
42-
}
38+
entry_points={"console_scripts": ["raftify_cli = raftify_cli.cli:main"]},
4339
)

binding/python/examples/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .deserializer import register_custom_deserializer
2121
from .web_server_api import routes, WebServer
2222
from .state_machine import HashStore
23+
from .utils import ensure_directory_exist, get_storage_path
2324

2425

2526
def load_peers() -> Peers:
@@ -113,6 +114,9 @@ async def main():
113114
logger = Logger(setup_logger())
114115
store = HashStore()
115116

117+
storage_path = get_storage_path(cfg.log_dir, node_id)
118+
ensure_directory_exist(storage_path)
119+
116120
tasks = []
117121
raft = Raft.bootstrap(node_id, raft_addr, store, cfg, logger)
118122
tasks.append(raft.run())

binding/python/examples/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
3+
4+
def get_storage_path(log_dir: str, node_id: int) -> str:
5+
return f"{log_dir}/node-{node_id}"
6+
7+
8+
def ensure_directory_exist(storage_path: str):
9+
if not os.path.exists(storage_path):
10+
os.makedirs(storage_path)

binding/python/tests/data_replication.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import asyncio
22
import pytest
3-
from utils import load_peers, wait_for_until_cluster_size_increase
3+
from utils import (
4+
ensure_directory_exist,
5+
load_peers,
6+
wait_for_until_cluster_size_increase,
7+
)
48
from constant import THREE_NODE_EXAMPLE
59
from harness.raft_server import RAFTS, run_rafts
610
from harness.state_machine import SetCommand
711

812

913
@pytest.mark.asyncio
1014
async def test_data_replication():
15+
ensure_directory_exist("./logs")
16+
1117
peers = load_peers(THREE_NODE_EXAMPLE)
1218
asyncio.create_task(run_rafts(peers))
1319
await asyncio.sleep(2)

binding/python/tests/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from asyncio import sleep
2+
import os
23
import tomli
34
from pathlib import Path
45
from raftify import InitialRole, Peer, Peers, Raft
@@ -45,3 +46,12 @@ async def wait_for_until_cluster_size_decrease(raft: Raft, target: int):
4546

4647
# Wait for the conf_change reflected to the cluster
4748
await sleep(0.1)
49+
50+
51+
def get_storage_path(log_dir: str, node_id: int) -> str:
52+
return f"{log_dir}/node-{node_id}"
53+
54+
55+
def ensure_directory_exist(storage_path: str):
56+
if not os.path.exists(storage_path):
57+
os.makedirs(storage_path)

0 commit comments

Comments
 (0)