带分区键的cassandra getendpoints有空格

时间:2017-03-20 12:43:31

标签: cassandra datastax cql3 distributed-database

我的分区键是id(int)和name(text)。 下面的命令工作正常,直到名称(文本)中没有空格。 nodetool getendpoints test testtable2 1:aaa;

如果使用的话 nodetool getendpoints test testtable2 3:aac cc; 它会抛出一个错误: nodetool:getendpoints需要键空间,表和分区键参数 请参阅节点工具帮助'或者' nodetool help'。

我通过执行获得了令牌 SELECT id,name,token(id,name)FROM test.testtable2 where name =' aac cc' AND id = 3; 并试图搜索 nodetool getendpoints test testtable2 -7072928299163215694; 错误:对于输入字符串:" -7072928299163215694" - 堆栈跟踪 - java.lang.NumberFormatException:对于输入字符串:" -7072928299163215694"

我如何搜索分区键(名称)是否有空格?

2 个答案:

答案 0 :(得分:0)

您使用的是哪个Cassandra版本。

我已经从Cassandra 2.x和Cassandra 3.x版本测试过它。它运作正常。

root@cqlsh:test_db> SELECT token(name) from test_temp ;

 system.token(name)
---------------------
 -907920378987128470

nodetool getendpoints test_db test_temp -907920378987128470;
192.168.8.52

更新的答案:得到了问题

当分区键的第一部分为int时生成问题。

CREATE TABLE test6 (
    age int PRIMARY KEY,
    name text
);

bin/nodetool getendpoints test test6 -7072928299163215694
error: For input string: "-7072928299163215694"java.lang.NumberFormatException: For input string:"-
7072928299163215694"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:583)
    at java.lang.Integer.parseInt(Integer.java:615)

但适用于以下输入

bin/nodetool getendpoints test test6 -7072
127.0.0.1

来自DataStax Doc:

  
    

提供拥有分区键的端点。分区程序返回密钥的标记。无论该标记的标识节点上是否存在数据,Cassandra都将返回端点。     ** key是您想要获得的端点的分区键。

  

nodetool getendpoints实际上将分区键的值作为输入。在这种情况下' -7072928299163215694'它将其解析为整数,从而最终导致异常。它工作为long或String(它将' -7072928299163215694'值作为字符串)因为它将此值作为键的值而非实际令牌。它不是解析令牌。因此,将令牌作为输入提供将不起作用。

getendpoints根据密钥的值生成令牌,并为您提供密钥所在的端点(节点)。

请检查此链接: What node does Cassandra store data on?

为此提供了补丁:

https://issues.apache.org/jira/browse/CASSANDRA-4551

希望这有帮助。

答案 1 :(得分:0)

这是nodetool命令的问题。

我修改了nodetool脚本并创建getendpoints脚本以支持分区键有空格的getendpoints

以下是getendpoints代码:

#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if [ "`basename "$0"`" = 'nodeprobe' ]; then
    echo "***************************************************************" >&2
    echo "WARNING: $0 is obsolete, use `dirname "$0"`/nodetool instead" >&2
    echo "***************************************************************" >&2
fi

if [ "x$CASSANDRA_INCLUDE" = "x" ]; then
    for include in "`dirname "$0"`/cassandra.in.sh" \
                   "$HOME/.cassandra.in.sh" \
                   /usr/share/cassandra/cassandra.in.sh \
                   /usr/local/share/cassandra/cassandra.in.sh \
                   /opt/cassandra/cassandra.in.sh; do
        if [ -r "$include" ]; then
            . "$include"
            break
        fi
    done
elif [ -r "$CASSANDRA_INCLUDE" ]; then
    . "$CASSANDRA_INCLUDE"
fi

# Use JAVA_HOME if set, otherwise look for java in PATH
if [ -x "$JAVA_HOME/bin/java" ]; then
    JAVA="$JAVA_HOME/bin/java"
else
    JAVA="`which java`"
fi

if [ -z "$CASSANDRA_CONF" -o -z "$CLASSPATH" ]; then
    echo "You must set the CASSANDRA_CONF and CLASSPATH vars" >&2
    exit 1
fi

# Run cassandra-env.sh to pick up JMX_PORT
if [ -f "$CASSANDRA_CONF/cassandra-env.sh" ]; then
    . "$CASSANDRA_CONF/cassandra-env.sh"
fi

# JMX Port passed via cmd line args (-p 9999 / --port 9999 / --port=9999)
# should override the value from cassandra-env.sh
ARGS=""
JVM_ARGS=""
SSL_FILE=$HOME/.cassandra/nodetool-ssl.properties
KS=""
CF=""
KEY=""

while true
do
  if [ ! $1 ]; then break; fi
  case $1 in
    -p)
      JMX_PORT=$2
      shift
      ;;
    --port=*)
      JMX_PORT=$(echo $1 | cut -d '=' -f 2)
      ;;
    --port)
      JMX_PORT=$2
      shift
      ;;
    --ssl)
      if [ -f $SSL_FILE ]
      then 
          SSL_ARGS=$(cat $SSL_FILE | tr '\n' ' ')
      fi
      JVM_ARGS="$JVM_ARGS -Dssl.enable=true $SSL_ARGS"
      ;;
    -D*)
      JVM_ARGS="$JVM_ARGS $1"
      ;;
    -k)
      KS=$2
      shift
      ;;
    -t)
      CF=$2
      shift
      ;;
    *)
      if [ ! $KEY ]; then 
    KEY="$1"
      else
    KEY="$KEY $1"
      fi
      ;;
  esac
  shift
done

# Special-case path variables.
case "`uname`" in
    CYGWIN*) 
        CLASSPATH="`cygpath -p -w "$CLASSPATH"`"
        CASSANDRA_CONF="`cygpath -p -w "$CASSANDRA_CONF"`"
    ;;
esac

"$JAVA" $JAVA_AGENT -cp "$CLASSPATH" \
      -Xmx128m \
      -Dcassandra.storagedir="$cassandra_storagedir" \
      -Dlogback.configurationFile=logback-tools.xml \
      -Dstorage-config="$CASSANDRA_CONF" \
      $JVM_ARGS \
      org.apache.cassandra.tools.NodeTool -p $JMX_PORT getendpoints $KS $CF "$KEY"

getendpoints文件放在$CASSANDRA_HOME/bin目录下。

现在您可以使用nodetool参数以及下面的参数

运行此文件
getendpoints -k keyspace_name -t table_name key

示例:

getendpoints -k test -t testtable2 3:aac cc