-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from eclipsevortex/release/2.2.3
Release/2.2.3
- Loading branch information
Showing
46 changed files
with
3,131 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.2.2 | ||
2.2.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from redis import asyncio as aioredis | ||
|
||
current = "2.0.0" | ||
|
||
|
||
async def rollout(database: aioredis.Redis): | ||
async for key in database.scan_iter("stats:*"): | ||
metadata_dict = await database.hgetall(key) | ||
|
||
if b"subtensor_successes" not in metadata_dict: | ||
await database.hset(key, b"subtensor_successes", 0) | ||
if b"subtensor_attempts" not in metadata_dict: | ||
await database.hset(key, b"subtensor_attempts", 0) | ||
if b"metric_successes" not in metadata_dict: | ||
await database.hset(key, b"metric_successes", 0) | ||
if b"metric_attempts" not in metadata_dict: | ||
await database.hset(key, b"metric_attempts", 0) | ||
if b"total_successes" not in metadata_dict: | ||
await database.hset(key, b"total_successes", 0) | ||
if b"tier" not in metadata_dict: | ||
await database.hset(key, b"tier", "Bronze") | ||
|
||
await database.set("version", current) | ||
|
||
|
||
async def rollback(database: aioredis.Redis): | ||
async for key in database.scan_iter("stats:*"): | ||
metadata_dict = await database.hgetall(key) | ||
|
||
if b"subtensor_successes" in metadata_dict: | ||
await database.hdel(key, b"subtensor_successes") | ||
if b"subtensor_attempts" in metadata_dict: | ||
await database.hdel(key, b"subtensor_attempts") | ||
if b"metric_successes" in metadata_dict: | ||
await database.hdel(key, b"metric_successes") | ||
if b"metric_attempts" in metadata_dict: | ||
await database.hdel(key, b"metric_attempts") | ||
if b"total_successes" in metadata_dict: | ||
await database.hdel(key, b"total_successes") | ||
if b"tier" in metadata_dict: | ||
await database.hdel(key, b"tier") | ||
|
||
await database.set("version", None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import asyncio | ||
import argparse | ||
import bittensor as bt | ||
from redis import asyncio as aioredis | ||
|
||
from subnet.shared.utils import get_redis_password | ||
from subnet.validator.database import create_dump, restore_dump | ||
|
||
|
||
async def create(args): | ||
try: | ||
bt.logging.info( | ||
f"Loading database from {args.database_host}:{args.database_port}" | ||
) | ||
redis_password = get_redis_password(args.redis_password) | ||
database = aioredis.StrictRedis( | ||
host=args.database_host, | ||
port=args.database_port, | ||
db=args.database_index, | ||
password=redis_password, | ||
) | ||
|
||
bt.logging.info("Create dump starting") | ||
|
||
await create_dump(args.dump_path, database) | ||
|
||
bt.logging.success("Create dump successful") | ||
except Exception as e: | ||
bt.logging.error(f"Error during rollout: {e}") | ||
|
||
|
||
async def restore(args): | ||
try: | ||
bt.logging.info( | ||
f"Loading database from {args.database_host}:{args.database_port}" | ||
) | ||
redis_password = get_redis_password(args.redis_password) | ||
database = aioredis.StrictRedis( | ||
host=args.database_host, | ||
port=args.database_port, | ||
db=args.database_index, | ||
password=redis_password, | ||
) | ||
|
||
bt.logging.info("Restore dump starting") | ||
|
||
await restore_dump(args.dump_path, database) | ||
|
||
bt.logging.success("Restore dump successful") | ||
|
||
except Exception as e: | ||
bt.logging.error(f"Error during rollback: {e}") | ||
|
||
|
||
async def main(args): | ||
if args.run_type == "create": | ||
await create(args) | ||
else: | ||
await restore(args) | ||
|
||
|
||
if __name__ == "__main__": | ||
try: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--run-type", | ||
type=str, | ||
default="create", | ||
help="Type of migration you want too execute. Possible values are rollout or rollback)", | ||
) | ||
parser.add_argument( | ||
"--dump-path", | ||
type=str, | ||
default="/tmp/redis", | ||
help="Dump file (with path) to create or restore", | ||
) | ||
parser.add_argument( | ||
"--redis_password", | ||
type=str, | ||
default=None, | ||
help="password for the redis database", | ||
) | ||
parser.add_argument( | ||
"--redis_conf_path", | ||
type=str, | ||
default="/etc/redis/redis.conf", | ||
help="path to the redis configuration file", | ||
) | ||
parser.add_argument("--database_host", type=str, default="localhost") | ||
parser.add_argument("--database_port", type=int, default=6379) | ||
parser.add_argument("--database_index", type=int, default=1) | ||
args = parser.parse_args() | ||
|
||
asyncio.run(main(args)) | ||
except KeyboardInterrupt: | ||
print("KeyboardInterrupt") | ||
except ValueError as e: | ||
print(f"ValueError: {e}") |
Oops, something went wrong.