def __init__(self): self.rq = RethinkdbUtils() self.ldb = LocaldbUtils() self.conn_block = self.ldb.get_conn('block') self.conn_block_header = self.ldb.get_conn('block_header') self.conn_vote = self.ldb.get_conn('vote') self.conn_vote_header = self.ldb.get_conn('vote_header') self.conn_block_records = self.ldb.get_conn('block_records') self.conn_node_info = self.ldb.get_conn('node_info')
class LocaldbValidate(): """Valide the localdb data is valid""" def __init__(self): self.rq = RethinkdbUtils() self.ldb = LocaldbUtils() self.conn_block = self.ldb.get_conn('block') self.conn_block_header = self.ldb.get_conn('block_header') self.conn_vote = self.ldb.get_conn('vote') self.conn_vote_header = self.ldb.get_conn('vote_header') self.conn_block_records = self.ldb.get_conn('block_records') self.conn_node_info = self.ldb.get_conn('node_info') def check_records(self, table, localdb_table_conn, localdb_header_conn, count_key): """check the records with rethinkdb and return the result Args: table: localdb_table_conn: localdb_header_conn: count_key: Return: isOk: is validate result: the result of this check """ localdb_records_count = self.ldb.get_records_count(localdb_table_conn) rethinkdb_records_count = self.rq.get_counts(table) header_count = self.ldb.get_val(localdb_header_conn, count_key) if header_count and header_count.strip() != '': header_count = int(header_count) if header_count is None: header_count = 0 if table == 'bigchain': block_records_count = lv.ldb.get_records_count( lv.conn_block_records) result = "block\t[rethinkdb={}, localdb={}, header={}, block_records={}]"\ .format(rethinkdb_records_count, localdb_records_count, header_count, block_records_count) isOK = False if localdb_records_count == rethinkdb_records_count\ and rethinkdb_records_count == header_count\ and header_count == block_records_count: isOK = True else: result = "vote\t[rethinkdb={}, localdb={}, header={}]"\ .format(rethinkdb_records_count, localdb_records_count, header_count) isOK = False if localdb_records_count == rethinkdb_records_count \ and rethinkdb_records_count == header_count: isOK = True return isOK, result def get_node_info(self): node_host = self.ldb.get_val(self.conn_node_info, "host") node_public_key = self.ldb.get_val(self.conn_node_info, "public_key") node_restart_times = self.ldb.get_val(self.conn_node_info, "restart_times") return node_host, node_public_key, node_restart_times
from ul_tests.db.utils_localdb import LocaldbUtils if __name__ == "__main__": ld = LocaldbUtils() block_conn = ld.get_conn('block') # all_blocks = ld.get_all_records(block_conn,show_only=False,limit=2) # for block in all_blocks: # print("{}\n".format(block)) # block_key = "000f39c7bd17ca45eabdfdb2565f267249358c701339f0f8006a32788431577b" # block_key = "00cd18127c78a49be8565cf4c0d123913cd3fa8f4b6993a801fb75f455e55913" # block_key_val = ld.get_val(block_conn,block_key) # print(block_key_val) block_key_prefix = "c2" block_dict = ld.get_val_prefix(block_conn, block_key_prefix) for key, block in block_dict.items(): print("key={},\nblock={}\n".format(key, block)) print("result[total={},prefix={}]".format(len(block_dict), block_key_prefix)) total_block = ld.get_records_count(block_conn) print("total_block is {}".format(total_block)) ld.close(block_conn)
from ul_tests.db.utils_localdb import LocaldbUtils if __name__ == "__main__": ld = LocaldbUtils() votes_conn = ld.get_conn('vote') # all_votes = ld.get_all_records(votes_conn,show_only=False) # print(all_votes) # vote_key = "000f39c7bd17ca45eabdfdb2565f267249358c701339f0f8006a32788431577b-akBGowqvc8WRQj5PxfN6zY9iNhkN7P87M99Hd4nHuBX" # # vote_key_val = ld.get_val(votes_conn,vote_key) # print(vote_key_val) # # records = ld.get_all_records(votes_conn,show_only=False) # print(records) # vote_for_block_key = "3d9423db02f5f8d56d2342316ae4a71fd78e8e45f99869a7c2cc8dc4126a5b57" vote_for_block_key_prefix = "c2" block_votes_dict = ld.get_val_prefix(votes_conn,vote_for_block_key_prefix) for vote_key,vote in block_votes_dict.items(): print("vote_key={},\nvote={}\n".format(vote_key,vote)) print("result[total={},prefix={}]".format(len(block_votes_dict),vote_for_block_key_prefix))
from ul_tests.db.utils_localdb import LocaldbUtils if __name__ == "__main__": ld = LocaldbUtils() conn_block_records = ld.get_conn('block_records') records = ld.get_all_records(conn_block_records, show_only=False) for record in records: print(record) total_records = ld.get_records_count(conn_block_records) print("total_records is {}".format(total_records)) ld.close(conn_block_records)
from ul_tests.db.utils_localdb import LocaldbUtils if __name__ == "__main__": ld = LocaldbUtils() # 1. vote header conn_header = ld.get_conn('block_header') records = ld.get_all_records(conn_header,show_only=False) for record in records: print(record) # block_num = ld.get_val(conn_header,'block_num') # current_block_id = ld.get_val(conn_header,'current_block_id') # current_block_timestamp = ld.get_val(conn_header,'current_block_timestamp') # genesis_block_id = ld.get_val(conn_header,'genesis_block_id') # # result = "block_num={}\ncurrent_block_id={}\ncurrent_block_timestamp={}\ngenesis_block_id={}\n"\ # .format(block_num,current_block_id,current_block_timestamp,genesis_block_id) # # print(result) total_records = ld.get_records_count(conn_header) print("total_records is {}".format(total_records)) ld.close(conn_header)
from ul_tests.db.utils_localdb import LocaldbUtils if __name__ == "__main__": ld = LocaldbUtils() conn_node_info = ld.get_conn('node_info') records = ld.get_all_records(conn_node_info, show_only=False) for record in records: print(record) total_records = ld.get_records_count(conn_node_info) print("total_records is {}".format(total_records)) ld.close(conn_node_info)