Ejemplo n.º 1
0
 def getr_negative_corrupted_vbucket_test(self):
     vbucket_state = self.input.param("vbucket_state", '')
     gen = DocumentGenerator('test_docs', '{{"age": {0}}}', xrange(5),
                             start=0, end=self.num_items)
     self.perform_docs_ops(self.master, [gen], 'create')
     self.log.info("Checking replica read")
     client = VBucketAwareMemcached(RestConnection(self.master), self.default_bucket_name)
     vbuckets_num = RestConnection(self.master).get_vbuckets(self.buckets[0])
     while gen.has_next():
         try:
             key, _ = gen.next()
             vBucketId = client._get_vBucket_id(key)
             mem = client.memcached_for_replica_vbucket(vBucketId)
             if vbucket_state:
                 mem.set_vbucket_state(vBucketId, vbucket_state)
                 msg = "Vbucket %s set to pending state" % vBucketId
                 mem_to_read = mem
             else:
                 wrong_vbucket = [v for v in client.vBucketMapReplica
                                if mem.host != client.vBucketMapReplica[v][0].split(':')[0] or\
                                str(mem.port) != client.vBucketMapReplica[v][0].split(':')[1]][0]
                 mem_to_read = client.memcached_for_replica_vbucket(wrong_vbucket)
                 msg = "Key: %s. Correct host is %s, test try to get from %s host. " %(
                                                     key, mem.host, mem_to_read.host)
                 msg += "Correct vbucket %s, wrong vbucket %s" % (vBucketId, wrong_vbucket)
             self.log.info(msg)
             client._send_op(mem_to_read.getr, key)
         except Exception, ex:
             if self.error and str(ex).find(self.error) != -1:
                 self.log.info("Expected error %s appeared as expected" % self.error)
             else:
                 raise ex
         else:
             if self.error:
                 self.fail("Expected error %s didn't appear as expected" % self.error)
Ejemplo n.º 2
0
    def test_vbucket_id_option(self):
        bucket = RestConnection(self.server_origin).get_bucket(self.buckets[0])
        self.num_items = self.num_items - (self.num_items % len(bucket.vbuckets))
        num_items_per_vb = self.num_items / len(bucket.vbuckets)
        template = '{{ "mutated" : 0, "age": {0}, "first_name": "{1}" }}'
        gen_load = DocumentGenerator('cbtransfer', template, range(5), ['james', 'john'], start=0, end=self.num_items)
        client = MemcachedClient(self.server_origin.ip,
                                 int(bucket.vbuckets[0].master.split(':')[1]))
        kv_value_dict = {}
        vb_id_to_check = bucket.vbuckets[-1].id
        for vb_id in xrange(len(bucket.vbuckets)):
            cur_items_per_vb = 0
            while cur_items_per_vb < num_items_per_vb:
                key, value = gen_load.next()

                client.set(key, 0, 0, value, vb_id)
                if vb_id_to_check == vb_id:
                    kv_value_dict[key] = value
                cur_items_per_vb += 1

        transfer_source = 'http://%s:%s' % (self.server_origin.ip, self.server_origin.port)
        transfer_destination = 'http://%s:%s' % (self.server_recovery.ip, self.server_recovery.port)
        output = self.shell.execute_cbtransfer(transfer_source, transfer_destination,
                                      "-b %s -B %s -i %s" % (bucket.name, bucket.name, vb_id_to_check))
        client = MemcachedClient(self.server_recovery.ip,
                                 int(bucket.vbuckets[0].master.split(':')[1]))
        for key, value in kv_value_dict.iteritems():
            _, _, d = client.get(key, vbucket=vb_id_to_check)
            self.assertEquals(d, value, 'Key: %s expected. Value expected %s. Value actual %s' % (
                                        key, value, d))
Ejemplo n.º 3
0
    def test_vbucket_id_option(self):
        bucket = RestConnection(self.server_origin).get_bucket(self.buckets[0])
        self.num_items = self.num_items - (self.num_items % len(bucket.vbuckets))
        num_items_per_vb = self.num_items / len(bucket.vbuckets)
        template = '{{ "mutated" : 0, "age": {0}, "first_name": "{1}" }}'
        gen_load = DocumentGenerator('cbtransfer', template, range(5), ['james', 'john'], start=0, end=self.num_items)
        client = MemcachedClient(self.server_origin.ip,
                                 int(bucket.vbuckets[0].master.split(':')[1]))
        kv_value_dict = {}
        vb_id_to_check = bucket.vbuckets[-1].id
        for vb_id in xrange(len(bucket.vbuckets)):
            cur_items_per_vb = 0
            while cur_items_per_vb < num_items_per_vb:
                key, value = gen_load.next()

                client.set(key, 0, 0, value, vb_id)
                if vb_id_to_check == vb_id:
                    kv_value_dict[key] = value
                cur_items_per_vb += 1

        transfer_source = 'http://%s:%s' % (self.server_origin.ip, self.server_origin.port)
        transfer_destination = 'http://%s:%s' % (self.server_recovery.ip, self.server_recovery.port)
        output = self.shell.execute_cbtransfer(transfer_source, transfer_destination,
                                      "-b %s -B %s -i %s" % (bucket.name, bucket.name, vb_id_to_check))
        client = MemcachedClient(self.server_recovery.ip,
                                 int(bucket.vbuckets[0].master.split(':')[1]))
        for key, value in kv_value_dict.iteritems():
            _, _, d = client.get(key, vbucket=vb_id_to_check)
            self.assertEquals(d, value, 'Key: %s expected. Value expected %s. Value actual %s' % (
                                        key, value, d))
Ejemplo n.º 4
0
 def _load_by_vbuckets(self, bucket):
     bucket = RestConnection(self.master).get_bucket(bucket)
     self.num_items = self.num_items - (self.num_items % len(bucket.vbuckets))
     num_items_per_vb = self.num_items / len(bucket.vbuckets)
     template = '{{ "mutated" : 0, "age": {0}, "first_name": "{1}" }}'
     gen_load = DocumentGenerator("vbuckettool", template, range(5), ["james", "john"], start=0, end=self.num_items)
     self._get_clients(bucket)
     for vb in bucket.vbuckets:
         self.keys_per_vbuckets_dict[vb] = []
     for i in xrange(gen_load.end):
         key, value = gen_load.next()
         vb_id = self._get_vBucket_id(key)
         self.clients[vb.master].set(key, 0, 0, value, vb_id)
         self.keys_per_vbuckets_dict[vb_id].append(key)
Ejemplo n.º 5
0
 def getr_rebalance_test(self):
     gen = DocumentGenerator('test_docs', '{{"age": {0}}}', xrange(5),
                                   start=0, end=self.num_items)
     self.perform_docs_ops(self.master, [gen], 'create')
     self.log.info("Checking replica read")
     client = VBucketAwareMemcached(RestConnection(self.master), self.default_bucket_name)
     rebalance = self.cluster.async_rebalance(self.servers[:self.nodes_init],
                         self.servers[self.nodes_init : self.nodes_init + self.nodes_in],
                         [])
     try:
         while gen.has_next():
             key, _ = gen.next()
             o, c, d = client.getr(key)
     finally:
         rebalance.result()
Ejemplo n.º 6
0
 def _load_by_vbuckets(self, bucket):
     bucket = RestConnection(self.master).get_bucket(bucket)
     self.num_items = self.num_items - (self.num_items % len(bucket.vbuckets))
     num_items_per_vb = self.num_items/len(bucket.vbuckets)
     template = '{{ "mutated" : 0, "age": {0}, "first_name": "{1}" }}'
     gen_load = DocumentGenerator('vbuckettool', template, range(5), ['james', 'john'],
                                  start=0, end=self.num_items)
     self._get_clients(bucket)
     for vb in bucket.vbuckets:
         self.keys_per_vbuckets_dict[vb] = []
     for i in xrange(gen_load.end):
         key, value = gen_load.next()
         vb_id = self._get_vBucket_id(key)
         self.clients[vb.master].set(key, 0, 0, value, vb_id)
         self.keys_per_vbuckets_dict[vb_id].append(key)
Ejemplo n.º 7
0
 def getr_negative_corrupted_vbucket_test(self):
     vbucket_state = self.input.param("vbucket_state", '')
     gen = DocumentGenerator('test_docs',
                             '{{"age": {0}}}',
                             xrange(5),
                             start=0,
                             end=self.num_items)
     self.perform_docs_ops(self.master, [gen], 'create')
     self.log.info("Checking replica read")
     client = VBucketAwareMemcached(RestConnection(self.master),
                                    self.default_bucket_name)
     vbuckets_num = RestConnection(self.master).get_vbuckets(
         self.buckets[0])
     while gen.has_next():
         try:
             key, _ = gen.next()
             vBucketId = client._get_vBucket_id(key)
             mem = client.memcached_for_replica_vbucket(vBucketId)
             if vbucket_state:
                 mem.set_vbucket_state(vBucketId, vbucket_state)
                 msg = "Vbucket %s set to pending state" % vBucketId
                 mem_to_read = mem
             else:
                 wrong_vbucket = [v for v in client.vBucketMapReplica
                                if mem.host != client.vBucketMapReplica[v][0].split(':')[0] or\
                                str(mem.port) != client.vBucketMapReplica[v][0].split(':')[1]][0]
                 mem_to_read = client.memcached_for_replica_vbucket(
                     wrong_vbucket)
                 msg = "Key: %s. Correct host is %s, test try to get from %s host. " % (
                     key, mem.host, mem_to_read.host)
                 msg += "Correct vbucket %s, wrong vbucket %s" % (
                     vBucketId, wrong_vbucket)
             self.log.info(msg)
             client._send_op(mem_to_read.getr, key)
         except Exception, ex:
             if self.error and str(ex).find(self.error) != -1:
                 self.log.info("Expected error %s appeared as expected" %
                               self.error)
             else:
                 raise ex
         else:
             if self.error:
                 self.fail("Expected error %s didn't appear as expected" %
                           self.error)
Ejemplo n.º 8
0
 def getr_rebalance_test(self):
     gen = DocumentGenerator('test_docs',
                             '{{"age": {0}}}',
                             xrange(5),
                             start=0,
                             end=self.num_items)
     self.perform_docs_ops(self.master, [gen], 'create')
     self.log.info("Checking replica read")
     client = VBucketAwareMemcached(RestConnection(self.master),
                                    self.default_bucket_name)
     rebalance = self.cluster.async_rebalance(
         self.servers[:self.nodes_init],
         self.servers[self.nodes_init:self.nodes_init + self.nodes_in], [])
     try:
         while gen.has_next():
             key, _ = gen.next()
             o, c, d = client.getr(key)
     finally:
         rebalance.result()