예제 #1
0
파일: node.py 프로젝트: EnigmaCurry/ccm
 def run_cqlsh(self, cmds=None, show_output=False, cqlsh_options=[]):
     cdir = self.get_cassandra_dir()
     cli = common.join_bin(cdir, 'bin', 'cqlsh')
     env = common.make_cassandra_env(cdir, self.get_path())
     host = self.network_interfaces['thrift'][0]
     if self.cluster.version() >= "2.1":
         port = self.network_interfaces['binary'][1]
     else:
         port = self.network_interfaces['thrift'][1]
     args = cqlsh_options + [ host, str(port) ]
     sys.stdout.flush()
     if cmds is None:
         os.execve(cli, [ common.platform_binary('cqlsh') ] + args, env)
     else:
         p = subprocess.Popen([ cli ] + args, env=env, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
         for cmd in cmds.split(';'):
             p.stdin.write(cmd + ';\n')
         p.stdin.write("quit;\n")
         p.wait()
         for err in p.stderr:
             print_("(EE) ", err, end='')
         if show_output:
             i = 0
             for log in p.stdout:
                 # first four lines are not interesting
                 if i >= 4:
                     print_(log, end='')
                 i = i + 1
예제 #2
0
 def get_env(self):
     update_conf = not self.__conf_updated
     if update_conf:
         self.__conf_updated = True
     return common.make_cassandra_env(self.get_install_cassandra_root(),
                                      self.get_node_cassandra_root(),
                                      update_conf=update_conf)
예제 #3
0
 def load_sstables_from_another_node(self, cluster, node_from, node_to, ks):
     cdir = node_to.get_install_dir()
     sstableloader = os.path.join(
         cdir, 'bin', ccmcommon.platform_binary('sstableloader'))
     env = ccmcommon.make_cassandra_env(cdir, node_to.get_path())
     host = node_to.address()
     ret = []
     for x in range(cluster.data_dir_count):
         sstable_dir = os.path.join(node_from.get_path(), 'data' + str(x),
                                    ks.strip('"'))
         for cf_dir in os.listdir(sstable_dir):
             full_cf_dir = os.path.join(sstable_dir, cf_dir)
             if os.path.isdir(full_cf_dir):
                 cmd_args = [
                     sstableloader, '--verbose', '--nodes', host,
                     full_cf_dir
                 ]
                 p = subprocess.Popen(cmd_args,
                                      stderr=subprocess.PIPE,
                                      stdout=subprocess.PIPE,
                                      env=env)
                 stdout, stderr = p.communicate()
                 exit_status = p.returncode
                 ret.append((exit_status, stdout.decode("utf-8"),
                             stderr.decode("utf-8")))
     return ret
예제 #4
0
파일: node.py 프로젝트: jsanda/ccm
 def run_cqlsh(self, cmds=None, show_output=False, cqlsh_options=[]):
     cdir = self.get_cassandra_dir()
     cli = common.join_bin(cdir, "bin", "cqlsh")
     env = common.make_cassandra_env(cdir, self.get_path())
     host = self.network_interfaces["thrift"][0]
     if self.cluster.version() >= "2.1":
         port = self.network_interfaces["binary"][1]
     else:
         port = self.network_interfaces["thrift"][1]
     args = cqlsh_options + [host, str(port)]
     sys.stdout.flush()
     if cmds is None:
         os.execve(cli, [common.platform_binary("cqlsh")] + args, env)
     else:
         p = subprocess.Popen(
             [cli] + args, env=env, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE
         )
         for cmd in cmds.split(";"):
             p.stdin.write(cmd + ";\n")
         p.stdin.write("quit;\n")
         p.wait()
         for err in p.stderr:
             print_("(EE) ", err, end="")
         if show_output:
             i = 0
             for log in p.stdout:
                 # first four lines are not interesting
                 if i >= 4:
                     print_(log, end="")
                 i = i + 1
예제 #5
0
    def _get_final_sstables(self, node, ks, table):
        """
        Return the node final sstable data files, excluding the temporary tables.
        If sstableutil exists (>= 3.0) then we rely on this tool since the table
        file names no longer contain tmp in their names (CASSANDRA-7066).
        """
        # Get all sstable data files
        allsstables = map(os.path.normcase, node.get_sstables(ks, table))

        # Remove any temporary files
        tool_bin = node.get_tool('sstableutil')
        if os.path.isfile(tool_bin):
            args = [tool_bin, '--type', 'tmp', ks, table]
            env = common.make_cassandra_env(node.get_install_cassandra_root(),
                                            node.get_node_cassandra_root())
            p = subprocess.Popen(args,
                                 env=env,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            (stdout, stderr) = p.communicate()
            tmpsstables = map(os.path.normcase, stdout.splitlines())

            ret = list(set(allsstables) - set(tmpsstables))
        else:
            ret = [
                sstable for sstable in allsstables if "tmp" not in sstable[50:]
            ]

        return ret
예제 #6
0
    def launch_standalone_scrub(self,
                                ks,
                                cf,
                                reinsert_overflowed_ttl=False,
                                no_validate=False):
        """
        Launch the standalone scrub
        """
        node1 = self.cluster.nodelist()[0]
        env = common.make_cassandra_env(node1.get_install_cassandra_root(),
                                        node1.get_node_cassandra_root())
        scrub_bin = node1.get_tool('sstablescrub')
        logger.debug(scrub_bin)

        args = [scrub_bin]
        if reinsert_overflowed_ttl:
            args += ['--reinsert-overflowed-ttl']
        if no_validate:
            args += ['--no-validate']
        args += [ks, cf] if reinsert_overflowed_ttl else [ks, cf]
        p = subprocess.Popen(args,
                             env=env,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        out, err = p.communicate()
        logger.debug(out.decode("utf-8"))
        # if we have less than 64G free space, we get this warning - ignore it
        if err and "Consider adding more capacity" not in err.decode("utf-8"):
            logger.debug(err.decode("utf-8"))
            assert_stderr_clean(err.decode("utf-8"))
예제 #7
0
    def _invoke_sstableutil(self, ks, table, type='all', oplogs=False, cleanup=False):
        """
        Invoke sstableutil and return the list of files, if any
        """
        debug("About to invoke sstableutil with type {}...".format(type))
        node1 = self.cluster.nodelist()[0]
        env = common.make_cassandra_env(node1.get_install_cassandra_root(), node1.get_node_cassandra_root())
        tool_bin = node1.get_tool('sstableutil')

        args = [tool_bin, '--type', type]

        if oplogs:
            args.extend(['--oplog'])
        if cleanup:
            args.extend(['--cleanup'])

        args.extend([ks, table])

        p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        (stdout, stderr) = p.communicate()

        self.assertEqual(p.returncode, 0, "Error invoking sstableutil; returned {code}".format(code=p.returncode))

        if stdout:
            debug(stdout)

        match = ks + os.sep + table + '-'
        ret = sorted(filter(lambda s: match in s, stdout.splitlines()))
        debug("Got {} files of type {}".format(len(ret), type))
        return ret
예제 #8
0
파일: node.py 프로젝트: alaalkhaldi/ccm
 def run_cli(self, cmds=None, show_output=False, cli_options=[]):
     cdir = self.get_cassandra_dir()
     cli = common.join_bin(cdir, 'bin', 'cassandra-cli')
     env = common.make_cassandra_env(cdir, self.get_path())
     host = self.network_interfaces['thrift'][0]
     port = self.network_interfaces['thrift'][1]
     args = [ '-h', host, '-p', str(port) , '--jmxport', str(self.jmx_port) ] + cli_options
     sys.stdout.flush()
     if cmds is None:
         os.execve(cli, [ common.platform_binary('cassandra-cli') ] + args, env)
     else:
         p = subprocess.Popen([ cli ] + args, env=env, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
         for cmd in cmds.split(';'):
             p.stdin.write(cmd + ';\n')
         p.stdin.write("quit;\n")
         p.wait()
         for err in p.stderr:
             print_("(EE) ", err, end='')
         if show_output:
             i = 0
             for log in p.stdout:
                 # first four lines are not interesting
                 if i >= 4:
                     print_(log, end='')
                 i = i + 1
    def _invoke_sstableutil(self, ks, table, type="all", oplogs=False, cleanup=False):
        """
        Invoke sstableutil and return the list of files, if any
        """
        debug("About to invoke sstableutil...")
        node1 = self.cluster.nodelist()[0]
        env = common.make_cassandra_env(node1.get_install_cassandra_root(), node1.get_node_cassandra_root())
        tool_bin = node1.get_tool("sstableutil")

        args = [tool_bin, "--type", type]

        if oplogs:
            args.extend(["--oplog"])
        if cleanup:
            args.extend(["--cleanup"])

        args.extend([ks, table])

        p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        (stdout, stderr) = p.communicate()

        if p.returncode != 0:
            debug(stderr)
            assert False, "Error invoking sstableutil; returned {code}".format(code=p.returncode)

        debug(stdout)
        match = ks + os.sep + table + "-"
        ret = sorted(filter(lambda s: match in s, stdout.splitlines()))
        debug("Got %d files" % (len(ret),))
        return ret
예제 #10
0
    def _invoke_sstableutil(self, ks, table, type='all', oplogs=False, cleanup=False):
        """
        Invoke sstableutil and return the list of files, if any
        """
        debug("About to invoke sstableutil...")
        node1 = self.cluster.nodelist()[0]
        env = common.make_cassandra_env(node1.get_install_cassandra_root(), node1.get_node_cassandra_root())
        tool_bin = node1.get_tool('sstableutil')

        args = [tool_bin, '--type', type]

        if oplogs:
            args.extend(['--oplog'])
        if cleanup:
            args.extend(['--cleanup'])

        args.extend([ks, table])

        p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        (stdin, stderr) = p.communicate()

        if len(stderr) > 0:
            debug(stderr)
            assert False, "Error invoking sstableutil"

        ret = stdin.splitlines()
        del ret[0]  # The first line is either "Listing files..." or "Cleaning up..."
        debug("Got %d files" % (len(ret),))
        return sorted(filter(None, ret))
 def load_sstables(self, cluster, node, ks):
     cdir = node.get_install_dir()
     sstableloader = os.path.join(
         cdir, 'bin', ccmcommon.platform_binary('sstableloader'))
     env = ccmcommon.make_cassandra_env(cdir, node.get_path())
     host = node.address()
     for x in xrange(0, cluster.data_dir_count):
         sstablecopy_dir = os.path.join(node.get_path(),
                                        'data{0}_copy'.format(x),
                                        ks.strip('"'))
         for cf_dir in os.listdir(sstablecopy_dir):
             full_cf_dir = os.path.join(sstablecopy_dir, cf_dir)
             if os.path.isdir(full_cf_dir):
                 cmd_args = [sstableloader, '--nodes', host, full_cf_dir]
                 p = subprocess.Popen(cmd_args,
                                      stderr=subprocess.PIPE,
                                      stdout=subprocess.PIPE,
                                      env=env)
                 exit_status = p.wait()
                 debug('stdout: {out}'.format(out=p.stdout))
                 debug('stderr: {err}'.format(err=p.stderr))
                 self.assertEqual(
                     0, exit_status,
                     "sstableloader exited with a non-zero status: {}".
                     format(exit_status))
예제 #12
0
파일: node.py 프로젝트: alaalkhaldi/ccm
 def cli(self):
     cdir = self.get_cassandra_dir()
     cli = common.join_bin(cdir, 'bin', 'cassandra-cli')
     env = common.make_cassandra_env(cdir, self.get_path())
     host = self.network_interfaces['thrift'][0]
     port = self.network_interfaces['thrift'][1]
     args = [ '-h', host, '-p', str(port) , '--jmxport', str(self.jmx_port) ]
     return CliSession(subprocess.Popen([ cli ] + args, env=env, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE))
예제 #13
0
파일: node.py 프로젝트: EnigmaCurry/ccm
 def cli(self):
     cdir = self.get_cassandra_dir()
     cli = common.join_bin(cdir, 'bin', 'cassandra-cli')
     env = common.make_cassandra_env(cdir, self.get_path())
     host = self.network_interfaces['thrift'][0]
     port = self.network_interfaces['thrift'][1]
     args = [ '-h', host, '-p', str(port) , '--jmxport', str(self.jmx_port) ]
     return CliSession(subprocess.Popen([ cli ] + args, env=env, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE))
예제 #14
0
파일: node.py 프로젝트: jsanda/ccm
 def nodetool(self, cmd):
     cdir = self.get_cassandra_dir()
     nodetool = common.join_bin(cdir, "bin", "nodetool")
     env = common.make_cassandra_env(cdir, self.get_path())
     host = self.address()
     args = [nodetool, "-h", host, "-p", str(self.jmx_port)]
     args += cmd.split()
     p = subprocess.Popen(args, env=env)
     p.wait()
예제 #15
0
파일: node.py 프로젝트: EnigmaCurry/ccm
 def nodetool(self, cmd):
     cdir = self.get_cassandra_dir()
     nodetool = common.join_bin(cdir, 'bin', 'nodetool')
     env = common.make_cassandra_env(cdir, self.get_path())
     host = self.address()
     args = [ nodetool, '-h', host, '-p', str(self.jmx_port)]
     args += cmd.split()
     p = subprocess.Popen(args, env=env)
     p.wait()
예제 #16
0
    def launch_standalone_scrub(self, ks, cf):
        node1 = self.cluster.nodelist()[0]
        env = common.make_cassandra_env(node1.get_install_cassandra_root(), node1.get_node_cassandra_root())
        scrub_bin = node1.get_tool('sstablescrub')
        debug(scrub_bin)

        args = [ scrub_bin, ks, cf]
        p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        response = p.communicate()
        debug(response)
예제 #17
0
파일: node.py 프로젝트: jsanda/ccm
 def cli(self):
     cdir = self.get_cassandra_dir()
     cli = common.join_bin(cdir, "bin", "cassandra-cli")
     env = common.make_cassandra_env(cdir, self.get_path())
     host = self.network_interfaces["thrift"][0]
     port = self.network_interfaces["thrift"][1]
     args = ["-h", host, "-p", str(port), "--jmxport", str(self.jmx_port)]
     return CliSession(
         subprocess.Popen(
             [cli] + args, env=env, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE
         )
     )
예제 #18
0
    def load(self, options):
        for itf in self.network_interfaces.values():
            if itf:
                common.check_socket_available(itf)

        cdir = self.get_cassandra_dir()
        loader_bin = common.join_bin(cdir, 'bin', 'sstableloader')
        env = common.make_cassandra_env(cdir, self.get_path())
        if not "-d" in options:
            l = [ node.network_interfaces['storage'][0] for node in self.cluster.nodes.values() if node.is_live() ]
            options = [ "-d",  ",".join(l) ] + options
        #print "Executing with", options
        os.execve(loader_bin, [ common.platform_binary('sstableloader') ] + options, env)
예제 #19
0
파일: node.py 프로젝트: EnigmaCurry/ccm
    def run_json2sstable(self, in_file, ks, cf, keyspace=None, datafile=None, column_families=None, enumerate_keys=False):
        cdir = self.get_cassandra_dir()
        if self.cluster.version() >= "2.1":
            json2sstable = common.join_bin(cdir, os.path.join('tools', 'bin'), 'json2sstable')
        else:
            json2sstable = common.join_bin(cdir, 'bin', 'json2sstable')
        env = common.make_cassandra_env(cdir, self.get_path())
        datafiles = self.__gather_sstables(datafile,keyspace,column_families)

        for datafile in datafiles:
            in_file_name = os.path.abspath(in_file.name)
            args = shlex.split("{json2sstable} -s -K {ks} -c {cf} {in_file_name} {datafile}".format(**locals()))
            subprocess.call(args, env=env)
예제 #20
0
파일: node.py 프로젝트: jsanda/ccm
    def run_sstable2json(self, keyspace=None, datafile=None, column_families=None, enumerate_keys=False):
        cdir = self.get_cassandra_dir()
        sstable2json = common.join_bin(cdir, "bin", "sstable2json")
        env = common.make_cassandra_env(cdir, self.get_path())
        datafiles = self.__gather_sstables(datafile, keyspace, column_families)

        for file in datafiles:
            print_("-- {0} -----".format(os.path.basename(file)))
            args = [sstable2json, file]
            if enumerate_keys:
                args = args + ["-e"]
            subprocess.call(args, env=env)
            print_("")
예제 #21
0
    def load(self, options):
        for itf in self.network_interfaces.values():
            if itf:
                common.check_socket_available(itf)

        cdir = self.get_cassandra_dir()
        loader_bin = common.join_bin(cdir, "bin", "sstableloader")
        env = common.make_cassandra_env(cdir, self.get_path())
        if not "-d" in options:
            l = [node.network_interfaces["storage"][0] for node in self.cluster.nodes.values() if node.is_live()]
            options = ["-d", ",".join(l)] + options
        # print "Executing with", options
        os.execve(loader_bin, [common.platform_binary("sstableloader")] + options, env)
예제 #22
0
def run_cqlsh(node, cmds, cqlsh_options=[]):
    cdir = node.get_cassandra_dir()
    cli = os.path.join(cdir, 'bin', 'cqlsh')
    env = common.make_cassandra_env(cdir, node.get_path())
    host = node.network_interfaces['thrift'][0]
    port = node.network_interfaces['thrift'][1]
    args = cqlsh_options + [ host, str(port) ]
    sys.stdout.flush()
    p = subprocess.Popen([ cli ] + args, env=env, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    for cmd in cmds.split(';'):
        p.stdin.write(cmd + ';\n')
    p.stdin.write("quit;\n")
    p.wait()
    return p.stdout.read()
예제 #23
0
def get_sstable_data_files(node, ks, table):
    """
    Read sstable data files by using sstableutil, so we ignore temporary files
    """
    env = common.make_cassandra_env(node.get_install_cassandra_root(), node.get_node_cassandra_root())
    args = [node.get_tool('sstableutil'), '--type', 'final', ks, table]

    p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = p.communicate()

    assert_equal(p.returncode, 0, "Error invoking sstableutil; returned {code}; {err}"
                 .format(code=p.returncode, err=stderr))

    ret = sorted(filter(lambda s: s.endswith('-Data.db'), stdout.splitlines()))
    return ret
예제 #24
0
파일: node.py 프로젝트: jsanda/ccm
    def run_sstablesplit(self, datafile=None, size=None, keyspace=None, column_families=None):
        cdir = self.get_cassandra_dir()
        sstablesplit = common.join_bin(cdir, "bin", "sstablesplit")
        env = common.make_cassandra_env(cdir, self.get_path())
        datafiles = self.__gather_sstables(datafile, keyspace, column_families)

        def do_split(f):
            print_("-- {0}-----".format(os.path.basename(f)))
            if size is not None:
                subprocess.call([sstablesplit, "-s", str(size), f], cwd=os.path.join(cdir, "bin"), env=env)
            else:
                subprocess.call([sstablesplit, f], cwd=os.path.join(cdir, "bin"), env=env)

        for datafile in datafiles:
            do_split(datafile)
예제 #25
0
파일: node.py 프로젝트: EnigmaCurry/ccm
    def run_sstable2json(self, out_file=sys.__stdout__, keyspace=None, datafile=None, column_families=None, enumerate_keys=False):
        cdir = self.get_cassandra_dir()
        if self.cluster.version() >= "2.1":
            sstable2json = common.join_bin(cdir, os.path.join('tools', 'bin'), 'sstable2json')
        else:
            sstable2json = common.join_bin(cdir, 'bin', 'sstable2json')
        env = common.make_cassandra_env(cdir, self.get_path())
        datafiles = self.__gather_sstables(datafile,keyspace,column_families)

        for datafile in datafiles:
            print_("-- {0} -----".format(os.path.basename(datafile)))
            args = [ sstable2json , datafile ]
            if enumerate_keys:
                args = args + ["-e"]
            subprocess.call(args, env=env, stdout=out_file)
            print_("")
예제 #26
0
    def launch_standalone_scrub(self, ks, cf):
        """
        Launch the standalone scrub
        """
        node1 = self.cluster.nodelist()[0]
        env = common.make_cassandra_env(node1.get_install_cassandra_root(), node1.get_node_cassandra_root())
        scrub_bin = node1.get_tool('sstablescrub')
        debug(scrub_bin)

        args = [scrub_bin, ks, cf]
        p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = p.communicate()
        debug(out)
        if err:
            debug(err)
            assert False, 'sstablescrub failed'
예제 #27
0
    def launch_standalone_scrub(self, ks, cf):
        """
        Launch the standalone scrub
        """
        node1 = self.cluster.nodelist()[0]
        env = common.make_cassandra_env(node1.get_install_cassandra_root(), node1.get_node_cassandra_root())
        scrub_bin = node1.get_tool('sstablescrub')
        debug(scrub_bin)

        args = [scrub_bin, ks, cf]
        p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = p.communicate()
        debug(out)
        if err:
            debug(err)
            assert False, 'sstablescrub failed'
예제 #28
0
    def launch_standalone_scrub(self, ks, cf):
        """
        Launch the standalone scrub
        """
        node1 = self.cluster.nodelist()[0]
        env = common.make_cassandra_env(node1.get_install_cassandra_root(), node1.get_node_cassandra_root())
        scrub_bin = node1.get_tool('sstablescrub')
        debug(scrub_bin)

        args = [scrub_bin, ks, cf]
        p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = p.communicate()
        debug(out)
        # if we have less than 64G free space, we get this warning - ignore it
        if err and "Consider adding more capacity" not in err:
            debug(err)
            assert False, 'sstablescrub failed'
 def load_sstables(self, cluster, node, ks):
     cdir = node.get_install_dir()
     sstableloader = os.path.join(cdir, 'bin', ccmcommon.platform_binary('sstableloader'))
     env = ccmcommon.make_cassandra_env(cdir, node.get_path())
     host = node.address()
     for x in xrange(0, cluster.data_dir_count):
         sstablecopy_dir = os.path.join(node.get_path(), 'data{0}_copy'.format(x), ks.strip('"'))
         for cf_dir in os.listdir(sstablecopy_dir):
             full_cf_dir = os.path.join(sstablecopy_dir, cf_dir)
             if os.path.isdir(full_cf_dir):
                 cmd_args = [sstableloader, '--nodes', host, full_cf_dir]
                 p = subprocess.Popen(cmd_args, stderr=subprocess.PIPE, stdout=subprocess.PIPE, env=env)
                 exit_status = p.wait()
                 debug('stdout: {out}'.format(out=p.stdout))
                 debug('stderr: {err}'.format(err=p.stderr))
                 self.assertEqual(0, exit_status,
                                  "sstableloader exited with a non-zero status: {}".format(exit_status))
예제 #30
0
    def launch_standalone_scrub(self, ks, cf):
        """
        Launch the standalone scrub
        """
        node1 = self.cluster.nodelist()[0]
        env = common.make_cassandra_env(node1.get_install_cassandra_root(), node1.get_node_cassandra_root())
        scrub_bin = node1.get_tool('sstablescrub')
        debug(scrub_bin)

        args = [scrub_bin, ks, cf]
        p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = p.communicate()
        debug(out)
        # if we have less than 64G free space, we get this warning - ignore it
        if err and "Consider adding more capacity" not in err:
            debug(err)
            self.fail('sstablescrub failed')
예제 #31
0
파일: node.py 프로젝트: jsanda/ccm
    def run_sstable2json(self,
                         keyspace=None,
                         datafile=None,
                         column_families=None,
                         enumerate_keys=False):
        cdir = self.get_cassandra_dir()
        sstable2json = common.join_bin(cdir, 'bin', 'sstable2json')
        env = common.make_cassandra_env(cdir, self.get_path())
        datafiles = self.__gather_sstables(datafile, keyspace, column_families)

        for file in datafiles:
            print_("-- {0} -----".format(os.path.basename(file)))
            args = [sstable2json, file]
            if enumerate_keys:
                args = args + ["-e"]
            subprocess.call(args, env=env)
            print_("")
예제 #32
0
파일: node.py 프로젝트: EnigmaCurry/ccm
    def run_sstablesplit(self, datafile=None,  size=None, keyspace=None, column_families=None):
        cdir = self.get_cassandra_dir()
        if self.cluster.version() >= "2.1":
            sstablesplit = common.join_bin(cdir, os.path.join('tools', 'bin'), 'sstablesplit')
        else:
            sstablesplit = common.join_bin(cdir, 'bin', 'sstablesplit')
        env = common.make_cassandra_env(cdir, self.get_path())
        datafiles = self.__gather_sstables(datafile, keyspace, column_families)

        def do_split(f):
            print_("-- {0}-----".format(os.path.basename(f)))
            if size is not None:
                subprocess.call( [sstablesplit, '-s', str(size), f], cwd=os.path.join(cdir, 'bin'), env=env )
            else:
                subprocess.call( [sstablesplit, f], cwd=os.path.join(cdir, 'bin'), env=env )

        for datafile in datafiles:
            do_split(datafile)
예제 #33
0
 def run_cqlsh(self, node, cmds, cqlsh_options=[]):
     cdir = node.get_cassandra_dir()
     cli = os.path.join(cdir, 'bin', 'cqlsh')
     env = common.make_cassandra_env(cdir, node.get_path())
     env['LANG'] = 'en_US.UTF-8'
     if LooseVersion(self.cluster.version()) >= LooseVersion('2.1'):
         host = node.network_interfaces['binary'][0]
         port = node.network_interfaces['binary'][1]
     else:
         host = node.network_interfaces['thrift'][0]
         port = node.network_interfaces['thrift'][1]
     args = cqlsh_options + [ host, str(port) ]
     sys.stdout.flush()
     p = subprocess.Popen([ cli ] + args, env=env, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
     for cmd in cmds.split(';'):
         p.stdin.write(cmd + ';\n')
     p.stdin.write("quit;\n")
     return p.communicate()[0]
예제 #34
0
def get_sstable_data_files(node, ks, table):
    """
    Read sstable data files by using sstableutil, so we ignore temporary files
    """
    env = common.make_cassandra_env(node.get_install_cassandra_root(),
                                    node.get_node_cassandra_root())
    args = [node.get_tool('sstableutil'), '--type', 'final', ks, table]

    p = subprocess.Popen(args,
                         env=env,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    stdout, stderr = p.communicate()

    assert_equal(
        p.returncode, 0,
        "Error invoking sstableutil; returned {code}; {err}".format(
            code=p.returncode, err=stderr))

    ret = sorted(filter(lambda s: s.endswith('-Data.db'), stdout.splitlines()))
    return ret
예제 #35
0
    def launch_standalone_scrub(self, ks, cf, reinsert_overflowed_ttl=False, no_validate=False):
        """
        Launch the standalone scrub
        """
        node1 = self.cluster.nodelist()[0]
        env = common.make_cassandra_env(node1.get_install_cassandra_root(), node1.get_node_cassandra_root())
        scrub_bin = node1.get_tool('sstablescrub')
        logger.debug(scrub_bin)

        args = [scrub_bin]
        if reinsert_overflowed_ttl:
            args += ['--reinsert-overflowed-ttl']
        if no_validate:
            args += ['--no-validate']
        args += [ks, cf] if reinsert_overflowed_ttl else [ks, cf]
        p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = p.communicate()
        logger.debug(out.decode("utf-8"))
        # if we have less than 64G free space, we get this warning - ignore it
        if err and "Consider adding more capacity" not in err.decode("utf-8"):
            logger.debug(err.decode("utf-8"))
            assert_stderr_clean(err.decode("utf-8"))
예제 #36
0
 def run_cqlsh(self, node, cmds, cqlsh_options=[]):
     cdir = node.get_install_dir()
     cli = os.path.join(cdir, 'bin', common.platform_binary('cqlsh'))
     env = common.make_cassandra_env(cdir, node.get_path())
     env['LANG'] = 'en_US.UTF-8'
     if LooseVersion(self.cluster.version()) >= LooseVersion('2.1'):
         host = node.network_interfaces['binary'][0]
         port = node.network_interfaces['binary'][1]
     else:
         host = node.network_interfaces['thrift'][0]
         port = node.network_interfaces['thrift'][1]
     args = cqlsh_options + [host, str(port)]
     sys.stdout.flush()
     p = subprocess.Popen([cli] + args,
                          env=env,
                          stdin=subprocess.PIPE,
                          stderr=subprocess.PIPE,
                          stdout=subprocess.PIPE)
     for cmd in cmds.split(';'):
         p.stdin.write(cmd + ';\n')
     p.stdin.write("quit;\n")
     return p.communicate()
    def _get_final_sstables(self, node, ks, table):
        """
        Return the node final sstable data files, excluding the temporary tables.
        If sstablelister exists (>= 3.0) then we rely on this tool since the table
        file names no longer contain tmp in their names (CASSANDRA-7066).
        """
        # Get all sstable data files
        allsstables = node.get_sstables(ks, table)

        # Remove any temporary files
        tool_bin = node.get_tool('sstablelister')
        if os.path.isfile(tool_bin):
            args = [ tool_bin, '--type', 'tmp', ks, table]
            env = common.make_cassandra_env(node.get_install_cassandra_root(), node.get_node_cassandra_root())
            p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            (stdin, stderr) = p.communicate()
            tmpsstables = stdin.split('\n')
            ret = list(set(allsstables) - set(tmpsstables))
        else:
            ret = [sstable for sstable in allsstables if "tmp" not in sstable[50:]]

        return ret
예제 #38
0
    def _list_sstable_files(self, ks, table, type='all', oplogs=False):
        debug("About to invoke sstablelister...")
        node1 = self.cluster.nodelist()[0]
        env = common.make_cassandra_env(node1.get_install_cassandra_root(), node1.get_node_cassandra_root())
        tool_bin = node1.get_tool('sstablelister')

        if oplogs:
            args = [ tool_bin, '--type', type, '--oplog', ks, table]
        else:
            args = [ tool_bin, '--type', type, ks, table]

        p = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        (stdin, stderr) = p.communicate()

        if len(stderr) > 0:
            debug(stderr)
            assert False, "Error invoking sstablelister"

        ret = stdin.split('\n')
        debug("Got %d files" % (len(ret),))
        return sorted(filter(None, ret))
예제 #39
0
파일: node.py 프로젝트: EnigmaCurry/ccm
 def scrub(self, options):
     cdir = self.get_cassandra_dir()
     scrub_bin = common.join_bin(cdir, 'bin', 'sstablescrub')
     env = common.make_cassandra_env(cdir, self.get_path())
     os.execve(scrub_bin, [ common.platform_binary('sstablescrub') ] + options, env)
    def load_sstable_with_configuration(self, pre_compression=None, post_compression=None, ks="ks", create_schema=create_schema):
        """
        tests that the sstableloader works by using it to load data.
        Compression of the columnfamilies being loaded, and loaded into
        can be specified.

        pre_compression and post_compression can be these values:
        None, 'Snappy', or 'Deflate'.
        """
        NUM_KEYS = 1000

        for compression_option in (pre_compression, post_compression):
            assert compression_option in (None, 'Snappy', 'Deflate')

        debug("Testing sstableloader with pre_compression=%s and post_compression=%s" % (pre_compression, post_compression))
        if self.upgrade_from:
            debug("Testing sstableloader with upgrade_from=%s and compact=%s" % (self.upgrade_from, self.compact))

        cluster = self.cluster
        if self.upgrade_from:
            debug("Generating sstables with version %s" % (self.upgrade_from))
            default_install_dir = self.cluster.get_install_dir()
            # Forcing cluster version on purpose
            cluster.set_install_dir(version=self.upgrade_from)
        debug("Using jvm_args=%s" % self.jvm_args)
        cluster.populate(2).start(jvm_args=self.jvm_args)
        node1, node2 = cluster.nodelist()
        time.sleep(.5)

        debug("creating keyspace and inserting")
        session = self.cql_connection(node1)
        self.create_schema(session, ks, pre_compression)

        for i in range(NUM_KEYS):
            session.execute("UPDATE standard1 SET v='%d' WHERE KEY='%d' AND c='col'" % (i, i))
            session.execute("UPDATE counter1 SET v=v+1 WHERE KEY='%d'" % i)

        node1.nodetool('drain')
        node1.stop()
        node2.nodetool('drain')
        node2.stop()

        debug("Making a copy of the sstables")
        # make a copy of the sstables
        for x in xrange(0, cluster.data_dir_count):
            data_dir = os.path.join(node1.get_path(), 'data{0}'.format(x))
            copy_root = os.path.join(node1.get_path(), 'data{0}_copy'.format(x))
            for ddir in os.listdir(data_dir):
                keyspace_dir = os.path.join(data_dir, ddir)
                if os.path.isdir(keyspace_dir) and ddir != 'system':
                    copy_dir = os.path.join(copy_root, ddir)
                    dir_util.copy_tree(keyspace_dir, copy_dir)

        debug("Wiping out the data and restarting cluster")
        # wipe out the node data.
        cluster.clear()

        if self.upgrade_from:
            debug("Running sstableloader with version from %s" % (default_install_dir))
            # Return to previous version
            cluster.set_install_dir(install_dir=default_install_dir)

        cluster.start(jvm_args=self.jvm_args)
        time.sleep(5)  # let gossip figure out what is going on

        debug("re-creating the keyspace and column families.")
        session = self.cql_connection(node1)
        self.create_schema(session, ks, post_compression)
        time.sleep(2)

        debug("Calling sstableloader")
        # call sstableloader to re-load each cf.
        cdir = node1.get_install_dir()
        sstableloader = os.path.join(cdir, 'bin', ccmcommon.platform_binary('sstableloader'))
        env = ccmcommon.make_cassandra_env(cdir, node1.get_path())
        host = node1.address()
        for x in xrange(0, cluster.data_dir_count):
            sstablecopy_dir = os.path.join(node1.get_path(), 'data{0}_copy'.format(x), ks.strip('"'))
            for cf_dir in os.listdir(sstablecopy_dir):
                full_cf_dir = os.path.join(sstablecopy_dir, cf_dir)
                if os.path.isdir(full_cf_dir):
                    cmd_args = [sstableloader, '--nodes', host, full_cf_dir]
                    p = subprocess.Popen(cmd_args, env=env)
                    exit_status = p.wait()
                    self.assertEqual(0, exit_status,
                                     "sstableloader exited with a non-zero status: %d" % exit_status)

        def read_and_validate_data(session):
            for i in range(NUM_KEYS):
                rows = list(session.execute("SELECT * FROM standard1 WHERE KEY='%d'" % i))
                self.assertEquals([str(i), 'col', str(i)], list(rows[0]))
                rows = list(session.execute("SELECT * FROM counter1 WHERE KEY='%d'" % i))
                self.assertEquals([str(i), 1], list(rows[0]))

        debug("Reading data back")
        # Now we should have sstables with the loaded data, and the existing
        # data. Lets read it all to make sure it is all there.
        read_and_validate_data(session)

        debug("scrubbing, compacting, and repairing")
        # do some operations and try reading the data again.
        node1.nodetool('scrub')
        node1.nodetool('compact')
        node1.nodetool('repair')

        debug("Reading data back one more time")
        read_and_validate_data(session)

        # check that RewindableDataInputStreamPlus spill files are properly cleaned up
        if self.upgrade_from:
            for x in xrange(0, cluster.data_dir_count):
                data_dir = os.path.join(node1.get_path(), 'data{0}'.format(x))
                for ddir in os.listdir(data_dir):
                    keyspace_dir = os.path.join(data_dir, ddir)
                    temp_files = self.glob_data_dirs(os.path.join(keyspace_dir, '*', "tmp", "*.dat"))
                    debug("temp files: " + str(temp_files))
                    self.assertEquals(0, len(temp_files), "Temporary files were not cleaned up.")
예제 #41
0
    def load_sstable_with_configuration(self, pre_compression=None, post_compression=None, ks="ks", create_schema=create_schema):
        """
        tests that the sstableloader works by using it to load data.
        Compression of the columnfamilies being loaded, and loaded into
        can be specified.

        pre_compression and post_compression can be these values:
        None, 'Snappy', or 'Deflate'.
        """
        NUM_KEYS = 1000

        for compression_option in (pre_compression, post_compression):
            self.assertIn(compression_option, (None, 'Snappy', 'Deflate'))

        debug("Testing sstableloader with pre_compression=%s and post_compression=%s" % (pre_compression, post_compression))
        if self.upgrade_from:
            debug("Testing sstableloader with upgrade_from=%s and compact=%s" % (self.upgrade_from, self.compact))

        cluster = self.cluster
        if self.upgrade_from:
            debug("Generating sstables with version %s" % (self.upgrade_from))
            default_install_dir = self.cluster.get_install_dir()
            # Forcing cluster version on purpose
            cluster.set_install_dir(version=self.upgrade_from)
        debug("Using jvm_args=%s" % self.jvm_args)
        cluster.populate(2).start(jvm_args=self.jvm_args)
        node1, node2 = cluster.nodelist()
        time.sleep(.5)

        debug("creating keyspace and inserting")
        session = self.cql_connection(node1)
        self.create_schema(session, ks, pre_compression)

        for i in range(NUM_KEYS):
            session.execute("UPDATE standard1 SET v='{}' WHERE KEY='{}' AND c='col'".format(i, i))
            session.execute("UPDATE counter1 SET v=v+1 WHERE KEY='{}'".format(i))

        node1.nodetool('drain')
        node1.stop()
        node2.nodetool('drain')
        node2.stop()

        debug("Making a copy of the sstables")
        # make a copy of the sstables
        for x in xrange(0, cluster.data_dir_count):
            data_dir = os.path.join(node1.get_path(), 'data{0}'.format(x))
            copy_root = os.path.join(node1.get_path(), 'data{0}_copy'.format(x))
            for ddir in os.listdir(data_dir):
                keyspace_dir = os.path.join(data_dir, ddir)
                if os.path.isdir(keyspace_dir) and ddir != 'system':
                    copy_dir = os.path.join(copy_root, ddir)
                    dir_util.copy_tree(keyspace_dir, copy_dir)

        debug("Wiping out the data and restarting cluster")
        # wipe out the node data.
        cluster.clear()

        if self.upgrade_from:
            debug("Running sstableloader with version from %s" % (default_install_dir))
            # Return to previous version
            cluster.set_install_dir(install_dir=default_install_dir)

        cluster.start(jvm_args=self.jvm_args)
        time.sleep(5)  # let gossip figure out what is going on

        debug("re-creating the keyspace and column families.")
        session = self.cql_connection(node1)
        self.create_schema(session, ks, post_compression)
        time.sleep(2)

        debug("Calling sstableloader")
        # call sstableloader to re-load each cf.
        cdir = node1.get_install_dir()
        sstableloader = os.path.join(cdir, 'bin', ccmcommon.platform_binary('sstableloader'))
        env = ccmcommon.make_cassandra_env(cdir, node1.get_path())
        host = node1.address()
        for x in xrange(0, cluster.data_dir_count):
            sstablecopy_dir = os.path.join(node1.get_path(), 'data{0}_copy'.format(x), ks.strip('"'))
            for cf_dir in os.listdir(sstablecopy_dir):
                full_cf_dir = os.path.join(sstablecopy_dir, cf_dir)
                if os.path.isdir(full_cf_dir):
                    cmd_args = [sstableloader, '--nodes', host, full_cf_dir]
                    p = subprocess.Popen(cmd_args, stderr=subprocess.PIPE, stdout=subprocess.PIPE, env=env)
                    exit_status = p.wait()
                    debug('stdout: {out}'.format(out=p.stdout))
                    debug('stderr: {err}'.format(err=p.stderr))
                    self.assertEqual(0, exit_status,
                                     "sstableloader exited with a non-zero status: {}".format(exit_status))

        def read_and_validate_data(session):
            for i in range(NUM_KEYS):
                query = "SELECT * FROM standard1 WHERE KEY='{}'".format(i)
                assert_one(session, query, [str(i), 'col', str(i)])
                query = "SELECT * FROM counter1 WHERE KEY='{}'".format(i)
                assert_one(session, query, [str(i), 1])

        debug("Reading data back")
        # Now we should have sstables with the loaded data, and the existing
        # data. Lets read it all to make sure it is all there.
        read_and_validate_data(session)

        debug("scrubbing, compacting, and repairing")
        # do some operations and try reading the data again.
        node1.nodetool('scrub')
        node1.nodetool('compact')
        node1.nodetool('repair')

        debug("Reading data back one more time")
        read_and_validate_data(session)

        # check that RewindableDataInputStreamPlus spill files are properly cleaned up
        if self.upgrade_from:
            for x in xrange(0, cluster.data_dir_count):
                data_dir = os.path.join(node1.get_path(), 'data{0}'.format(x))
                for ddir in os.listdir(data_dir):
                    keyspace_dir = os.path.join(data_dir, ddir)
                    temp_files = self.glob_data_dirs(os.path.join(keyspace_dir, '*', "tmp", "*.dat"))
                    debug("temp files: " + str(temp_files))
                    self.assertEquals(0, len(temp_files), "Temporary files were not cleaned up.")
    def load_sstable_with_configuration(self, pre_compression=None, post_compression=None):
        """
        tests that the sstableloader works by using it to load data.
        Compression of the columnfamilies being loaded, and loaded into
        can be specified.

        pre_compression and post_compression can be these values:
        None, 'SnappyCompressor', or 'DeflateCompressor'.
        """
        NUM_KEYS = 1000

        def read_and_validate_data():
            debug("READ")
            node1.stress(['--operation=READ', '--num-keys=%d'%NUM_KEYS])
            debug("RANGE_SLICE")
            node1.stress(['--operation=RANGE_SLICE', '--num-keys=%d'%NUM_KEYS])
            debug("READ SUPER")
            node1.stress(['--operation=READ', '--num-keys=%d'%NUM_KEYS, '--family-type=Super'])
            debug("COUNTER GET")
            node1.stress(['--operation=COUNTER_GET', '--num-keys=%d'%NUM_KEYS])
            debug("COUNTER GET SUPER")
            node1.stress(['--operation=COUNTER_GET', '--num-keys=%d'%NUM_KEYS, '--family-type=Super'])
            

        assert pre_compression in (None, 'SnappyCompressor', 'DeflateCompressor'), 'Invalid input pre_compression: ' + str(pre_compression)
        assert post_compression in (None, 'SnappyCompressor', 'DeflateCompressor'), 'Invalid input post_compression: ' + str(post_compression)

        debug("Testing sstableloader with pre_compression=%s and post_compression=%s" % (pre_compression, post_compression))

        cluster = self.cluster
        cluster.populate(2).start()
        [node1, node2] = cluster.nodelist()
        time.sleep(.5)

        compression_str = '--compression='+pre_compression if pre_compression else ''

        debug("creating keyspace and inserting")
        # create the keyspace
        node1.stress(['--replication-factor=2', '--num-keys=1', compression_str])
        node1.stress(['--num-keys=%d'%NUM_KEYS, compression_str])
        node1.stress(['--num-keys=%d'%NUM_KEYS, '--family-type=Super', compression_str])
        node1.stress(['--num-keys=%d'%NUM_KEYS, '--operation=COUNTER_ADD', compression_str])
        node1.stress(['--num-keys=%d'%NUM_KEYS, '--family-type=Super', '--operation=COUNTER_ADD', compression_str])
        time.sleep(2)
        
        node1.nodetool('drain')
        node1.stop()
        node2.nodetool('drain')
        node2.stop()

        debug("Making a copy of the sstables")
        # make a copy of the sstables
        data_dir = os.path.join(node1.get_path(), 'data')
        copy_root = os.path.join(node1.get_path(), 'data_copy')
        for ddir in os.listdir(data_dir):
            keyspace_dir = os.path.join(data_dir, ddir)
            if os.path.isdir(keyspace_dir) and ddir != 'system':
                copy_dir = os.path.join(copy_root, ddir)
                dir_util.copy_tree(keyspace_dir, copy_dir)


        debug("Wiping out the data and restarting cluster")
        # wipe out the node data.
        node1.clear()
        node2.clear()
        node1.start()
        node2.start()
        time.sleep(20) # let gossip figure out what is going on

        debug("re-creating the keyspace and column families.")
        # now re-create the keyspace and column families, but don't insert much data.
        # we'll want this data to get overwritten.
        compression_str = '--compression='+post_compression if post_compression else ''
        node1.stress(['--replication-factor=1', '--num-keys=1', compression_str])
        node1.stress(['--num-keys=1', compression_str])
        node1.stress(['--num-keys=1', '--family-type=Super', compression_str])
        node1.stress(['--num-keys=1', '--operation=COUNTER_ADD', compression_str])
        node1.stress(['--num-keys=1', '--family-type=Super', '--operation=COUNTER_ADD', compression_str])
        time.sleep(2)

        debug("Calling sstableloader")
        # call sstableloader to re-load each cf.
        cdir = node1.get_cassandra_dir()
        sstableloader = os.path.join(cdir, 'bin', 'sstableloader')
        env = ccmcommon.make_cassandra_env(cdir, node1.get_path())
        host = node1.address()
        for cf_dir in os.listdir(copy_dir):
            full_cf_dir = os.path.join(copy_dir, cf_dir)
            if os.path.isdir(full_cf_dir):
                cmd_args = [sstableloader, '--nodes', host, full_cf_dir]
                p = subprocess.Popen(cmd_args, env=env)
                p.wait()

        debug("Reading data back")
        # Now we should have sstables with the loaded data, and the existing
        # data. Lets read it all to make sure it is all there.
        read_and_validate_data()

        debug("scrubbing, compacting, and repairing")
        # do some operations and try reading the data again.
        node1.nodetool('scrub')
        node1.nodetool('compact')
        node1.nodetool('repair')

        debug("Reading data back one more time")
        read_and_validate_data()
예제 #43
0
 def get_env(self):
     return common.make_cassandra_env(self.get_install_cassandra_root(),
                                      self.get_node_cassandra_root())
예제 #44
0
파일: node.py 프로젝트: EnigmaCurry/ccm
    def start(self,
              join_ring=True,
              no_wait=False,
              verbose=False,
              update_pid=True,
              wait_other_notice=False,
              replace_token=None,
              replace_address=None,
              jvm_args=[],
              wait_for_binary_proto=False,
              profile_options=None,
              use_jna=False):
        """
        Start the node. Options includes:
          - join_ring: if false, start the node with -Dcassandra.join_ring=False
          - no_wait: by default, this method returns when the node is started and listening to clients.
            If no_wait=True, the method returns sooner.
          - wait_other_notice: if True, this method returns only when all other live node of the cluster
            have marked this node UP.
          - replace_token: start the node with the -Dcassandra.replace_token option.
          - replace_address: start the node with the -Dcassandra.replace_address option.
        """
        if self.is_running():
            raise NodeError("%s is already running" % self.name)

        for itf in list(self.network_interfaces.values()):
            if itf is not None and replace_address is None:
                common.check_socket_available(itf)

        if wait_other_notice:
            marks = [ (node, node.mark_log()) for node in list(self.cluster.nodes.values()) if node.is_running() ]

        cdir = self.get_cassandra_dir()
        cass_bin = common.join_bin(cdir, 'bin', 'cassandra')

        # Copy back the cassandra scripts since profiling may have modified it the previous time
        shutil.copy(cass_bin, self.get_bin_dir())
        cass_bin = common.join_bin(self.get_path(), 'bin', 'cassandra')

        # If Windows, change entries in .bat file to split conf from binaries
        if common.is_win():
            self.__clean_bat()

        if profile_options is not None:
            config = common.get_config()
            if not 'yourkit_agent' in config:
                raise NodeError("Cannot enable profile. You need to set 'yourkit_agent' to the path of your agent in a ~/.ccm/config")
            cmd = '-agentpath:%s' % config['yourkit_agent']
            if 'options' in profile_options:
                cmd = cmd + '=' + profile_options['options']
            print_(cmd)
            # Yes, it's fragile as shit
            pattern=r'cassandra_parms="-Dlog4j.configuration=log4j-server.properties -Dlog4j.defaultInitOverride=true'
            common.replace_in_file(cass_bin, pattern, '    ' + pattern + ' ' + cmd + '"')

        os.chmod(cass_bin, os.stat(cass_bin).st_mode | stat.S_IEXEC)

        env = common.make_cassandra_env(cdir, self.get_path())
        if common.is_win():
            self._clean_win_jmx();
        
        pidfile = os.path.join(self.get_path(), 'cassandra.pid')
        args = [ cass_bin, '-p', pidfile, '-Dcassandra.join_ring=%s' % str(join_ring) ]
        if replace_token is not None:
            args.append('-Dcassandra.replace_token=%s' % str(replace_token))
        if replace_address is not None:
            args.append('-Dcassandra.replace_address=%s' % str(replace_address))
        if use_jna is False:
            args.append('-Dcassandra.boot_without_jna=true')
        args = args + jvm_args

        process = None
        if common.is_win():
            # clean up any old dirty_pid files from prior runs
            if (os.path.isfile(self.get_path() + "/dirty_pid.tmp")):
                os.remove(self.get_path() + "/dirty_pid.tmp")
            process = subprocess.Popen(args, cwd=self.get_bin_dir(), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        else:
            process = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        # Our modified batch file writes a dirty output with more than just the pid - clean it to get in parity
        # with *nix operation here.
        if common.is_win():
            self.__clean_win_pid()
            self._update_pid(process)
        elif update_pid:
            if no_wait:
                time.sleep(2) # waiting 2 seconds nevertheless to check for early errors and for the pid to be set
            else:
                for line in process.stdout:
                    if verbose:
                        print_(line.rstrip('\n'))

            self._update_pid(process)

            if not self.is_running():
                raise NodeError("Error starting node %s" % self.name, process)

        if wait_other_notice:
            for node, mark in marks:
                node.watch_log_for_alive(self, from_mark=mark)

        if wait_for_binary_proto:
            self.watch_log_for("Starting listening for CQL clients")
            # we're probably fine at that point but just wait some tiny bit more because
            # the msg is logged just before starting the binary protocol server
            time.sleep(0.2)

        return process
예제 #45
0
파일: node.py 프로젝트: jsanda/ccm
    def start(
        self,
        join_ring=True,
        no_wait=False,
        verbose=False,
        update_pid=True,
        wait_other_notice=False,
        replace_token=None,
        replace_address=None,
        jvm_args=[],
        wait_for_binary_proto=False,
        profile_options=None,
        use_jna=False,
    ):
        """
        Start the node. Options includes:
          - join_ring: if false, start the node with -Dcassandra.join_ring=False
          - no_wait: by default, this method returns when the node is started and listening to clients.
            If no_wait=True, the method returns sooner.
          - wait_other_notice: if True, this method returns only when all other live node of the cluster
            have marked this node UP.
          - replace_token: start the node with the -Dcassandra.replace_token option.
          - replace_address: start the node with the -Dcassandra.replace_address option.
        """
        if self.is_running():
            raise NodeError("%s is already running" % self.name)

        for itf in list(self.network_interfaces.values()):
            if itf is not None and replace_address is None:
                common.check_socket_available(itf)

        if wait_other_notice:
            marks = [(node, node.mark_log()) for node in list(self.cluster.nodes.values()) if node.is_running()]

        cdir = self.get_cassandra_dir()
        cass_bin = common.join_bin(cdir, "bin", "cassandra")

        # Copy back the cassandra scripts since profiling may have modified it the previous time
        shutil.copy(cass_bin, self.get_bin_dir())
        cass_bin = common.join_bin(self.get_path(), "bin", "cassandra")

        # If Windows, change entries in .bat file to split conf from binaries
        if common.is_win():
            self.__clean_bat()

        if profile_options is not None:
            config = common.get_config()
            if not "yourkit_agent" in config:
                raise NodeError(
                    "Cannot enable profile. You need to set 'yourkit_agent' to the path of your agent in a ~/.ccm/config"
                )
            cmd = "-agentpath:%s" % config["yourkit_agent"]
            if "options" in profile_options:
                cmd = cmd + "=" + profile_options["options"]
            print_(cmd)
            # Yes, it's fragile as shit
            pattern = r'cassandra_parms="-Dlog4j.configuration=log4j-server.properties -Dlog4j.defaultInitOverride=true'
            common.replace_in_file(cass_bin, pattern, "    " + pattern + " " + cmd + '"')

        os.chmod(cass_bin, os.stat(cass_bin).st_mode | stat.S_IEXEC)

        env = common.make_cassandra_env(cdir, self.get_path())
        pidfile = os.path.join(self.get_path(), "cassandra.pid")
        args = [cass_bin, "-p", pidfile, "-Dcassandra.join_ring=%s" % str(join_ring)]
        if replace_token is not None:
            args.append("-Dcassandra.replace_token=%s" % str(replace_token))
        if replace_address is not None:
            args.append("-Dcassandra.replace_address=%s" % str(replace_address))
        if use_jna is False:
            args.append("-Dcassandra.boot_without_jna=true")
        args = args + jvm_args

        process = None
        if common.is_win():
            # clean up any old dirty_pid files from prior runs
            if os.path.isfile(self.get_path() + "/dirty_pid.tmp"):
                os.remove(self.get_path() + "/dirty_pid.tmp")
            process = subprocess.Popen(
                args, cwd=self.get_bin_dir(), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE
            )
        else:
            process = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        # Our modified batch file writes a dirty output with more than just the pid - clean it to get in parity
        # with *nix operation here.
        if common.is_win():
            self.__clean_win_pid()
            self._update_pid(process)
        elif update_pid:
            if no_wait:
                time.sleep(2)  # waiting 2 seconds nevertheless to check for early errors and for the pid to be set
            else:
                for line in process.stdout:
                    if verbose:
                        print_(line.rstrip("\n"))

            self._update_pid(process)

            if not self.is_running():
                raise NodeError("Error starting node %s" % self.name, process)

        if wait_other_notice:
            for node, mark in marks:
                node.watch_log_for_alive(self, from_mark=mark)

        if wait_for_binary_proto:
            self.watch_log_for("Starting listening for CQL clients")
            # we're probably fine at that point but just wait some tiny bit more because
            # the msg is logged just before starting the binary protocol server
            time.sleep(0.2)

        return process
예제 #46
0
    def load_sstable_with_configuration(self, pre_compression=None, post_compression=None):
        """
        tests that the sstableloader works by using it to load data.
        Compression of the columnfamilies being loaded, and loaded into
        can be specified.

        pre_compression and post_compression can be these values:
        None, 'Snappy', or 'Deflate'.
        """
        NUM_KEYS = 1000

        for compression_option in (pre_compression, post_compression):
            assert compression_option in (None, 'Snappy', 'Deflate')

        debug("Testing sstableloader with pre_compression=%s and post_compression=%s" % (pre_compression, post_compression))

        cluster = self.cluster
        cluster.populate(2).start()
        node1, node2 = cluster.nodelist()
        time.sleep(.5)

        def create_schema(session, compression):
            self.create_ks(session, "ks", rf=2)
            self.create_cf(session, "standard1", compression=compression)
            self.create_cf(session, "counter1", compression=compression, columns={'v': 'counter'})

        debug("creating keyspace and inserting")
        session = self.cql_connection(node1)
        create_schema(session, pre_compression)

        for i in range(NUM_KEYS):
            session.execute("UPDATE standard1 SET v='%d' WHERE KEY='%d' AND c='col'" % (i, i))
            session.execute("UPDATE counter1 SET v=v+1 WHERE KEY='%d'" % i)

        node1.nodetool('drain')
        node1.stop()
        node2.nodetool('drain')
        node2.stop()

        debug("Making a copy of the sstables")
        # make a copy of the sstables
        data_dir = os.path.join(node1.get_path(), 'data')
        copy_root = os.path.join(node1.get_path(), 'data_copy')
        for ddir in os.listdir(data_dir):
            keyspace_dir = os.path.join(data_dir, ddir)
            if os.path.isdir(keyspace_dir) and ddir != 'system':
                copy_dir = os.path.join(copy_root, ddir)
                dir_util.copy_tree(keyspace_dir, copy_dir)

        debug("Wiping out the data and restarting cluster")
        # wipe out the node data.
        cluster.clear()
        cluster.start()
        time.sleep(5)  # let gossip figure out what is going on

        debug("re-creating the keyspace and column families.")
        session = self.cql_connection(node1)
        create_schema(session, post_compression)
        time.sleep(2)

        debug("Calling sstableloader")
        # call sstableloader to re-load each cf.
        cdir = node1.get_install_dir()
        sstableloader = os.path.join(cdir, 'bin', ccmcommon.platform_binary('sstableloader'))
        env = ccmcommon.make_cassandra_env(cdir, node1.get_path())
        host = node1.address()
        sstablecopy_dir = copy_root + '/ks'
        for cf_dir in os.listdir(sstablecopy_dir):
            full_cf_dir = os.path.join(sstablecopy_dir, cf_dir)
            if os.path.isdir(full_cf_dir):
                cmd_args = [sstableloader, '--nodes', host, full_cf_dir]
                p = subprocess.Popen(cmd_args, env=env)
                exit_status = p.wait()
                self.assertEqual(0, exit_status,
                                 "sstableloader exited with a non-zero status: %d" % exit_status)

        def read_and_validate_data(session):
            for i in range(NUM_KEYS):
                rows = list(session.execute("SELECT * FROM standard1 WHERE KEY='%d'" % i))
                self.assertEquals([str(i), 'col', str(i)], list(rows[0]))
                rows = list(session.execute("SELECT * FROM counter1 WHERE KEY='%d'" % i))
                self.assertEquals([str(i), 1], list(rows[0]))

        debug("Reading data back")
        # Now we should have sstables with the loaded data, and the existing
        # data. Lets read it all to make sure it is all there.
        read_and_validate_data(session)

        debug("scrubbing, compacting, and repairing")
        # do some operations and try reading the data again.
        node1.nodetool('scrub')
        node1.nodetool('compact')
        node1.nodetool('repair')

        debug("Reading data back one more time")
        read_and_validate_data(session)
예제 #47
0
파일: node.py 프로젝트: jsanda/ccm
 def scrub(self, options):
     cdir = self.get_cassandra_dir()
     scrub_bin = common.join_bin(cdir, "bin", "sstablescrub")
     env = common.make_cassandra_env(cdir, self.get_path())
     os.execve(scrub_bin, [common.platform_binary("sstablescrub")] + options, env)