Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check export snapshot status with the manifest file #3561

Merged
merged 4 commits into from
Jul 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions scripts/sync_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import argparse



def get_height(method, url, post_data, headers):

parsed_url = urllib.parse.urlparse(url)
Expand Down Expand Up @@ -55,7 +54,6 @@ def check_or_do(network):
print(export_cmd)
os.system(export_cmd)


# tar block csv file
filename = "block_%s_%s.csv" % (start, end)
file_compress_name = "%s.tar.gz" % filename
Expand All @@ -66,7 +64,8 @@ def check_or_do(network):

# append and tar the block list csv file
block_list_file_name = "block_list.csv"
append_cmd = "kubectl exec -it -n starcoin-%s starcoin-1 -- bash -c 'echo %s >> /sc-data/%s' " % (network, filename, block_list_file_name)
append_cmd = "kubectl exec -it -n starcoin-%s starcoin-1 -- bash -c 'echo %s >> /sc-data/%s' " % (
network, filename, block_list_file_name)
block_list_file_tar_name = "%s.tar.gz" % block_list_file_name
tar_block_list_cmd = "kubectl exec -it -n starcoin-%s starcoin-1 -- tar -czvf /sc-data/%s -C /sc-data/ %s " % (
network, block_list_file_tar_name, block_list_file_name)
Expand All @@ -83,9 +82,36 @@ def check_or_do(network):
network, block_list_file_tar_name, network, block_list_file_tar_name)
os.system(cp_blocklist_tar_cmd)

# update the last_export_height
os.system("echo %s > ./last_export_height.txt" % end)
os.system("aws s3api put-object --bucket main.starcoin.org --key %s/last_export_height.txt --body ./last_export_height.txt" % network)

# back up last snapshot cp to backdir
# do the increment snapshot export
# check the snapshot is ok or not with the manifest file
# if not, recover the backdir, then exit.
# if ok, rm backup dir, and do the next step
os.system("cp -r /sc-data/snapshot /sc-data/snapshotbak")
# export snapshot
export_snapshot_cmd = "kubectl exec -it -n starcoin-%s starcoin-1 -- /starcoin/starcoin_db_exporter export-snapshot --db-path /sc-data/%s -n %s -o /sc-data/snapshot -t true" % (network, network, network)
export_snapshot_cmd = "kubectl exec -it -n starcoin-%s starcoin-1 -- /starcoin/starcoin_db_exporter export-snapshot --db-path /sc-data/%s -n %s -o /sc-data/snapshot -t true" % (
network, network, network)
os.system(export_snapshot_cmd)
export_state_node_status = os.system(
"bash -c \"if [ $(less /sc-data/snapshot/manifest.csv| grep state_node | awk -F ' ' '{print$2}') -eq $(less /sc-data/snapshot/state_node | wc -l) ]; then exit 0; else exit 1;fi\"")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里五个文件都的检测下

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里五个文件都的检测下

好的。

export_acc_node_transaction_status = os.system(
"bash -c \"if [ $(less /sc-data/snapshot/manifest.csv| grep acc_node_transaction | awk -F ' ' '{print$2}') -eq $(less /sc-data/snapshot/acc_node_transaction | wc -l) ]; then exit 0; else exit 1;fi\"")
export_acc_node_block_status = os.system(
"bash -c \"if [ $(less /sc-data/snapshot/manifest.csv| grep acc_node_block | awk -F ' ' '{print$2}') -eq $(less /sc-data/snapshot/acc_node_block | wc -l) ]; then exit 0; else exit 1;fi\"")
export_block_status = os.system(
"bash -c \"if [ $(less /sc-data/snapshot/manifest.csv| grep -w block | awk -F ' ' '{print$2}') -eq $(less /sc-data/snapshot/block | wc -l) ]; then exit 0; else exit 1;fi\"")
export_block_info_status = os.system(
"bash -c \"if [ $(less /sc-data/snapshot/manifest.csv| grep block_info | awk -F ' ' '{print$2}') -eq $(less /sc-data/snapshot/block_info | wc -l) ]; then exit 0; else exit 1;fi\"")

if export_state_node_status != 0 or export_acc_node_transaction_status != 0 or export_acc_node_block_status != 0 or export_block_status != 0 or export_block_info_status != 0:
os.system("rm -rf /sc-data/snapshot")
os.system("mv /sc-data/snapshotbak /sc-data/snapshot")
sys.exit(1)
os.system("rm -rf /sc-data/snapshotbak")

# tar snapshot
tar_snapshot_cmd = "kubectl exec -it -n starcoin-%s starcoin-1 -- tar -czvf /sc-data/%s -C /sc-data/ %s " % (
Expand All @@ -97,13 +123,10 @@ def check_or_do(network):
network, "snapshot.tar.gz", network, "snapshot.tar.gz")
os.system(cp_snapshot_tar_cmd)

# update the last_export_height
os.system("echo %s > ./last_export_height.txt" % end)
os.system("aws s3api put-object --bucket main.starcoin.org --key %s/last_export_height.txt --body ./last_export_height.txt" % network)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='sync blocks for main, proxima, barnard')
parser = argparse.ArgumentParser(
description='sync blocks for main, proxima, barnard')
parser.add_argument(
'--net',
metavar='net',
Expand Down