示例#1
0
def main():
    handler = MyHandler()
    client = DcpClient()
    args = parse_arguments(sys.argv[1:])
    endpoint = 'http://{}:8091/pools/default/buckets/{}'.format(args.host,
                                                                args.bucket)
    vb_map = json.loads(urllib2.urlopen(endpoint).read())['vBucketServerMap']
    replicas = get_replica_vbuckets(vb_map, args.host)
    client.connect(args.host, 8091, args.bucket, args.username, args.password,
                   handler)
    while True:
        for i in replicas:
            result = client.add_stream(i, args.host, 0, 0, 1, 0, 0, 0)
            while result['status'] == 2:
                time.sleep(0.5)
                result = client.add_stream(i, args.host, 0, 0, 1, 0, 0, 0)
            if result['status'] != 0:
                print 'Stream request to vb %d failed due to error %d' % \
                      (i, result['status'])

    client.close()
示例#2
0
文件: wgen.py 项目: woodysign/spring
class DcpWorker(Worker):

    def __init__(self, workload_settings, target_settings,
                 shutdown_event=None):
        super(DcpWorker, self).__init__(workload_settings, target_settings,
                                        shutdown_event)

    def init_db(self, params):
        pass

    def run(self, sid, lock):
        self.sid = sid
        host, port = self.ts.node.split(':')

        try:
            self.handler = DcpHandler()
            self.dcp_client = DcpClient()
            self.dcp_client.connect(host, int(port), self.ts.bucket,
                                    'Administrator', 'password',
                                    self.handler)
        except:
            logger.info('Connection Error: dcp-worker-{}'.format(self.sid))
            return

        logger.info('Started: query-worker-{}'.format(self.sid))
        for vb in range(1024):
            start_seqno = 0
            end_seqno = 18446744073709551615  # 2^64 - 1
            result = self.dcp_client.add_stream(vb, 0, start_seqno, end_seqno,
                                                0, 0, 0)
            if result['status'] != 0:
                logger.warn('Stream failed for vb {} due to error {}'
                            .format(vb, result['status']))

        no_items = 0
        last_item_count = 0
        while no_items < 10:
            time.sleep(1)
            cur_items = self.handler.get_num_items()
            if cur_items == last_item_count:
                no_items += 1
            else:
                no_items = 0
            last_item_count = cur_items

        self.dcp_client.close()

        logger.info('Finished: dcp-worker-{}, read {} items'
                    .format(self.sid, last_item_count))
示例#3
0
def main():
    handler = MyHandler()
    client = DcpClient()
    client.connect('172.23.105.195', 8091, 'bucket-1', 'Administrator',
                   'password', handler)
    for i in range(8):
        result = client.add_stream(i, 0, 0, 10, 0, 0, 0)
        if result['status'] != 0:
            print 'Stream request to vb %d failed dur to error %d' %\
                (i, result['status'])

    while handler.has_active_streams():
        time.sleep(.25)

    print handler.get_num_items()
    client.close()
def main():
    handler = MyHandler()
    client = DcpClient()
    client.connect('172.23.105.195', 8091, 'bucket-1', 'Administrator', 'password',
                   handler)
    for i in range(8):
        result = client.add_stream(i, 0, 0, 10, 0, 0, 0)
        if result['status'] != 0:
            print 'Stream request to vb %d failed dur to error %d' %\
                (i, result['status'])

    while handler.has_active_streams():
        time.sleep(.25)

    print handler.get_num_items()
    client.close()