|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import argparse |
| 4 | +import grpc |
| 5 | +import sys |
| 6 | + |
| 7 | +import fossildbapi_pb2 as proto |
| 8 | +import fossildbapi_pb2_grpc as proto_rpc |
| 9 | + |
| 10 | +MAX_MESSAGE_LENGTH = 1073741824 |
| 11 | + |
| 12 | +def main(): |
| 13 | + verbose = True |
| 14 | + |
| 15 | + collections = ['skeletons', 'volumes', 'volumeData', 'skeletonUpdates'] |
| 16 | + |
| 17 | + listKeysBatchSize = 300 |
| 18 | + |
| 19 | + srcPort = 2000 |
| 20 | + dstPort = 7155 |
| 21 | + |
| 22 | + srcChannel = grpc.insecure_channel('localhost:{}'.format(srcPort), options=[('grpc.max_send_message_length', MAX_MESSAGE_LENGTH), ( |
| 23 | + 'grpc.max_receive_message_length', MAX_MESSAGE_LENGTH)]) |
| 24 | + srcStub = proto_rpc.FossilDBStub(srcChannel) |
| 25 | + |
| 26 | + dstChannel = grpc.insecure_channel('localhost:{}'.format(dstPort), options=[('grpc.max_send_message_length', MAX_MESSAGE_LENGTH), ( |
| 27 | + 'grpc.max_receive_message_length', MAX_MESSAGE_LENGTH)]) |
| 28 | + dstStub = proto_rpc.FossilDBStub(dstChannel) |
| 29 | + |
| 30 | + testHealth(srcStub, 'source fossildb at {}'.format(srcPort)) |
| 31 | + testHealth(dstStub, 'destination fossildb at {}'.format(dstPort)) |
| 32 | + |
| 33 | + putCount = 0 |
| 34 | + |
| 35 | + for collection in collections: |
| 36 | + print('copying collection ' + collection) |
| 37 | + lastKey = None |
| 38 | + while True: |
| 39 | + listKeysReply = srcStub.ListKeys(proto.ListKeysRequest(collection=collection, limit=listKeysBatchSize, startAfterKey=lastKey)) |
| 40 | + assertSuccess(listKeysReply) |
| 41 | + if len(listKeysReply.keys) == 0: |
| 42 | + break |
| 43 | + if verbose: |
| 44 | + print(' copying key batch ', listKeysReply.keys) |
| 45 | + for key in listKeysReply.keys: |
| 46 | + if verbose: |
| 47 | + print(' copying key ', key) |
| 48 | + getMultipleVersionsReply = srcStub.GetMultipleVersions(proto.GetMultipleVersionsRequest(collection=collection, key=key)) |
| 49 | + assertSuccess(getMultipleVersionsReply) |
| 50 | + for versionValueTuple in zip(getMultipleVersionsReply.versions, getMultipleVersionsReply.values): |
| 51 | + if verbose: |
| 52 | + print(' copying version ', versionValueTuple[0]) |
| 53 | + putReply = dstStub.Put(proto.PutRequest(collection=collection, key=key, version=versionValueTuple[0], value=versionValueTuple[1])) |
| 54 | + assertSuccess(putReply) |
| 55 | + putCount += 1 |
| 56 | + if (verbose and putCount % 10 == 0) or putCount % 10000 == 0: |
| 57 | + print("total put count:", putCount) |
| 58 | + |
| 59 | + lastKey = listKeysReply.keys[-1] |
| 60 | + print("Done. total put count:", putCount) |
| 61 | + |
| 62 | +def testHealth(stub, label): |
| 63 | + try: |
| 64 | + reply = stub.Health(proto.HealthRequest()) |
| 65 | + assertSuccess(reply) |
| 66 | + print('successfully connected to ' + label) |
| 67 | + except Exception as e: |
| 68 | + print('failed to connect to ' + label + ': ' + str(e)) |
| 69 | + sys.exit(1) |
| 70 | + |
| 71 | +def assertSuccess(reply): |
| 72 | + if not reply.success: |
| 73 | + raise Exception("reply.success failed: " + reply.errorMessage) |
| 74 | + |
| 75 | +if __name__ == '__main__': |
| 76 | + main() |
0 commit comments