예제 #1
0
    def verify_vbucket_details_stats(self,
                                     bucket,
                                     kv_servers,
                                     vbuckets=1024,
                                     expected_val=dict()):
        """

        :param bucket: Bucket object
        :param kv_servers: List of kv_nodes currently present in the cluster
        :param vbuckets: Total vbucket count for the bucket. Default 1024
        :param expected_val: dict() containing expected key,value pairs
        :return verification_failed: Bool value denoting verification
                                     failed or not
        """
        verification_failed = False
        vb_details_stats = dict()
        ops_val = dict()
        ops_val["ops_create"] = 0
        ops_val["ops_delete"] = 0
        ops_val["ops_update"] = 0
        ops_val["ops_reject"] = 0
        ops_val["ops_get"] = 0
        ops_val["rollback_item_count"] = 0
        ops_val["sync_write_aborted_count"] = 0
        ops_val["sync_write_committed_count"] = 0
        ops_val["pending_writes"] = 0

        # Fetch stats for all available vbuckets into 'vb_details_stats'
        for server in kv_servers:
            shell = RemoteMachineShellConnection(server)
            cbstat_obj = Cbstats(shell)
            vb_details_stats.update(cbstat_obj.vbucket_details(bucket.name))
            shell.disconnect()

        for vb_num in range(0, vbuckets):
            vb_num = str(vb_num)
            for op_type in ops_val.keys():
                ops_val[op_type] += int(vb_details_stats[vb_num][op_type])

        # Verification block
        for op_type in ops_val.keys():
            self.log.debug("%s for %s: %s" %
                           (op_type, bucket.name, ops_val[op_type]))

            if op_type in expected_val \
                    and not DurabilityHelper.__compare(ops_val[op_type],
                                                       expected_val[op_type],
                                                       DurabilityHelper.EQUAL):
                verification_failed = True
                self.log.error(
                    "Mismatch in %s stats. %s != %s" %
                    (op_type, ops_val[op_type], expected_val[op_type]))
        return verification_failed
예제 #2
0
    def collect_vbucket_stats(self,
                              buckets,
                              servers,
                              collect_vbucket=True,
                              collect_vbucket_seqno=True,
                              collect_vbucket_details=True,
                              perNode=True):
        """
            Method to extract the vbuckets stats given by cbstats tool

            Paramters:
              buckets: bucket information
              servers: server information
              collect_vbucket: take vbucket type stats
              collect_vbucket_seqno: take vbucket-seqno type stats
              collect_vbucket_details: take vbucket-details type stats
              perNode: if True collects data per node else takes a union
                       across nodes

            Returns:
              The output can be in two formats

              if we are doing per node data collection
              Vbucket Information :: {bucket { node : [vbucket_seqno {key:value} U vbucket_details {key:value} U vbucket {key:value}]}}

              if we are not doing per node data collection
              Vbucket Information :: {bucket : [vbucket_seqno {key:value} U vbucket_details {key:value} U vbucket {key:value}]}
        """
        bucketMap = dict()
        for bucket in buckets:
            if bucket.bucketType == Bucket.Type.MEMCACHED:
                continue
            dataMap = dict()
            for server in servers:
                map_data = dict()
                cbstat = Cbstats(server)

                if collect_vbucket:
                    result = dict()
                    for vb_type in ["active", "replica"]:
                        vb_list = cbstat.vbucket_list(bucket.name, vb_type)
                        for vb_num in vb_list:
                            result['vb_%s' % vb_num] = dict()
                            result['vb_%s' % vb_num]["state"] = vb_type
                    map_data.update(result)
                    # vbucket = client.stats('vbucket')
                    # self.createMapVbucket(vbucket, map_data)
                if collect_vbucket_seqno:
                    result = cbstat.vbucket_seqno(bucket.name)
                    for key in result.keys():
                        result['vb_' + key] = result.pop(key)
                    map_data.update(result)
                    # vbucket_seqno = client.stats('vbucket-seqno')
                    # self.createMapVbucket(vbucket_seqno, map_data)
                if collect_vbucket_details:
                    result = cbstat.vbucket_details(bucket.name)
                    for key in result.keys():
                        result['vb_' + key] = result.pop(key)
                    map_data.update(result)
                    # vbucket_details = client.stats('vbucket-details')
                    # self.createMapVbucket(vbucket_details, map_data)
                if perNode:
                    dataMap[server.ip] = map_data
                else:
                    dataMap.update(map_data)
            bucketMap[bucket.name] = dataMap
        return bucketMap
예제 #3
0
    def verify_vbucket_details_stats(self,
                                     bucket,
                                     kv_servers,
                                     vbuckets=1024,
                                     expected_val=dict(),
                                     one_less_node=False):
        """

        :param bucket: Bucket object
        :param cbstat_obj: Cbstats class object
        :param vbuckets: Total vbucket count for the bucket. Default 1024
        :param expected_val: dict() containing expected key,value pairs
        :param one_less_node: Bool value denoting,
                              num_nodes == bucket.replicaNumber
        :return verification_failed: Bool value denoting verification
                                     failed or not
        """
        verification_failed = False
        vb_details_stats = dict()
        ops_val = dict()
        ops_val["ops_create"] = 0
        ops_val["ops_delete"] = 0
        ops_val["ops_update"] = 0
        ops_val["ops_reject"] = 0
        ops_val["ops_get"] = 0
        ops_val["rollback_item_count"] = 0
        ops_val["sync_write_aborted_count"] = 0
        ops_val["sync_write_committed_count"] = 0
        ops_val["pending_writes"] = 0

        # Fetch stats for all available vbuckets into 'vb_details_stats'
        for server in kv_servers:
            shell = RemoteMachineShellConnection(server)
            cbstat_obj = Cbstats(shell)
            vb_details_stats.update(cbstat_obj.vbucket_details(bucket.name))
            shell.disconnect()

        for vb_num in range(0, vbuckets):
            vb_num = str(vb_num)
            for op_type in [
                    "ops_create", "ops_delete", "ops_update", "ops_reject",
                    "ops_get", "rollback_item_count",
                    "sync_write_aborted_count", "sync_write_committed_count",
                    "pending_writes"
            ]:
                ops_val[op_type] += int(vb_details_stats[vb_num][op_type])

        for op_type in [
                "ops_create", "ops_delete", "ops_update", "ops_reject",
                "ops_get", "rollback_item_count", "sync_write_aborted_count",
                "sync_write_committed_count", "pending_writes"
        ]:
            self.log.info("%s for %s: %s" %
                          (op_type, bucket.name, ops_val[op_type]))

        # Verification block
        comparison_op = DurabilityHelper.EQUAL
        if bucket.replicaNumber > 1:
            comparison_op = DurabilityHelper.GREATER_THAN_EQ

        for op_type in ["ops_create", "ops_delete", "ops_update"]:
            if op_type in expected_val:
                rhs_val = expected_val[op_type] * (bucket.replicaNumber + 1)
                if one_less_node:
                    rhs_val = expected_val[op_type] * bucket.replicaNumber

                if not DurabilityHelper.__compare(ops_val[op_type], rhs_val,
                                                  comparison_op):
                    verification_failed = True
                    self.log.error(
                        "Mismatch in %s stats. %s %s %s" %
                        (op_type, ops_val[op_type], comparison_op, rhs_val))

        for op_type in [
                "ops_reject", "ops_get", "rollback_item_count",
                "sync_write_aborted_count", "sync_write_committed_count",
                "pending_writes"
        ]:
            if op_type in expected_val \
                    and not DurabilityHelper.__compare(ops_val[op_type],
                                                       expected_val[op_type],
                                                       DurabilityHelper.EQUAL):
                verification_failed = True
                self.log.error(
                    "Mismatch in %s stats. %s != %s" %
                    (op_type, ops_val[op_type], expected_val[op_type]))
        # return verification_failed
        return False