From e5edfe5ae1c947c9ffb01f980d8114b2f6136c3c Mon Sep 17 00:00:00 2001 From: yanghanbing Date: Sat, 23 Jun 2018 17:35:02 +0800 Subject: [PATCH 1/2] snapshot lotate --- plasma/child_chain/snapshot.py | 8 ++++++-- plasma/config.py | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plasma/child_chain/snapshot.py b/plasma/child_chain/snapshot.py index 876c4f95..545426b1 100644 --- a/plasma/child_chain/snapshot.py +++ b/plasma/child_chain/snapshot.py @@ -11,7 +11,7 @@ def list_snapshots(): dir_path = os.path.join(plasma_config["PICKLE_DIR"], dir_name) if os.path.isdir(dir_path): res.append(dir_name) - return res + return sorted(res) def get_max_snapshot(): @@ -39,4 +39,8 @@ def make_snapshot(): file_path = os.path.join(plasma_config["PICKLE_DIR"], file_name) if os.path.isfile(file_path) and file_name.endswith(".pickle"): shutil.copy(file_path, os.path.join(snapshot_dir, file_name)) - print("snapshot created") \ No newline at end of file + print("snapshot created") + snapshots = list_snapshots() + if len(snapshots) > plasma_config["MAX_SNAPSHOTS"]: + for snapshot in snapshots[:len(snapshots) - plasma_config["MAX_SNAPSHOTS"]]: + shutil.rmtree(os.path.join(plasma_config["PICKLE_DIR"], snapshot), ignore_errors=True) \ No newline at end of file diff --git a/plasma/config.py b/plasma/config.py index d3c2191d..1c30f463 100644 --- a/plasma/config.py +++ b/plasma/config.py @@ -13,6 +13,7 @@ ROOT_CHAIN_CONTRACT_ADDRESS="0xa3b2a1804203b75b494028966c0f62e677447a39", NETWORK="http://localhost:8545", BLOCK_AUTO_SUMBITTER_INTERVAL=1, + MAX_SNAPSHOTS=100, MIN_SNAPSHOT_SECONDS=10, # set 0 will not make snapshot ) else: @@ -20,7 +21,8 @@ ROOT_CHAIN_CONTRACT_ADDRESS="0xC47e711ac6A3D16Db0826c404d8C5d8bDC01d7b1", NETWORK="http://localhost:8545", BLOCK_AUTO_SUMBITTER_INTERVAL=30, - MIN_SNAPSHOT_SECONDS=0, # set 0 will not make snapshot + MAX_SNAPSHOTS=50, + MIN_SNAPSHOT_SECONDS=3600, # set 0 will not make snapshot ) plasma_config["PICKLE_DIR"] = "child_chain_pickle" From 66e4cb0c2bb7f7e387840a0d3db7d8096a93156d Mon Sep 17 00:00:00 2001 From: yanghanbing Date: Sat, 23 Jun 2018 17:39:38 +0800 Subject: [PATCH 2/2] remove unused code --- plasma_tools/chain_inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plasma_tools/chain_inspect.py b/plasma_tools/chain_inspect.py index 4d0e7a51..68494be3 100644 --- a/plasma_tools/chain_inspect.py +++ b/plasma_tools/chain_inspect.py @@ -19,7 +19,7 @@ from plasma.child_chain.snapshot import list_snapshots -list_timestamp = lambda: sorted(list_snapshots()) +list_timestamp = list_snapshots class ChildChainSnapshot(object):