具有分区键的 cassandra getendpoints 具有 space
cassandra getendpoints with partition key has space
我的分区键是 id(int) 和 name(text)。
在 name(text) 中没有 space 之前,下面的命令工作正常。
nodetool getendpoints 测试测试table2 1:aaa;
如果我正在使用
nodetool getendpoints 测试测试table2 3:aac cc;
它抛出一个错误:nodetool: getendpoints requires keyspace, table and partition key arguments
参见 'nodetool help' 或 'nodetool help '。
我通过执行获得了令牌
SELECT id,name, token(id,name) FROM test.testtable2 where name='aac cc'AND id=3;
并试图搜索
nodetool getendpoints 测试测试table2 -7072928299163215694;
错误:对于输入字符串:“-7072928299163215694”
- 堆栈跟踪 -
java.lang.NumberFormatException:对于输入字符串:“-7072928299163215694”
我如何搜索分区键(名称)是否有 space?
您使用的是哪个 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 文档:
Provides the end points that own the partition key. The partitioner returns a token for the key. Cassandra will return an endpoint whether or not data exists on the identified node for that token.
** key is the partition key of the end points you want to get.
nodetool getendpoints 实际上将分区键的值作为输入。在这种情况下,'-7072928299163215694' 将其解析为整数,因此最终抛出异常。它适用于 long 或 String(它将“-7072928299163215694”值作为字符串),因为它已将此作为键的值而不是实际令牌。它不解析令牌。所以提供令牌作为输入是行不通的。
getendpoints 根据密钥的值生成令牌,并为您提供密钥所在的端点(节点)。
请检查此 link:
已为此提供补丁:
https://issues.apache.org/jira/browse/CASSANDRA-4551
希望对您有所帮助。
这是 nodetool
命令的问题。
我修改了 nodetool
脚本并创建了 getendpoints
脚本来支持 getendpoints 分区键有 space
这是 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 "[=10=]"`" = 'nodeprobe' ]; then
echo "***************************************************************" >&2
echo "WARNING: [=10=] is obsolete, use `dirname "[=10=]"`/nodetool instead" >&2
echo "***************************************************************" >&2
fi
if [ "x$CASSANDRA_INCLUDE" = "x" ]; then
for include in "`dirname "[=10=]"`/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 [ ! ]; then break; fi
case in
-p)
JMX_PORT=
shift
;;
--port=*)
JMX_PORT=$(echo | cut -d '=' -f 2)
;;
--port)
JMX_PORT=
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 "
;;
-k)
KS=
shift
;;
-t)
CF=
shift
;;
*)
if [ ! $KEY ]; then
KEY=""
else
KEY="$KEY "
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
我的分区键是 id(int) 和 name(text)。 在 name(text) 中没有 space 之前,下面的命令工作正常。 nodetool getendpoints 测试测试table2 1:aaa;
如果我正在使用 nodetool getendpoints 测试测试table2 3:aac cc; 它抛出一个错误:nodetool: getendpoints requires keyspace, table and partition key arguments 参见 'nodetool help' 或 'nodetool help '。
我通过执行获得了令牌 SELECT id,name, token(id,name) FROM test.testtable2 where name='aac cc'AND id=3; 并试图搜索 nodetool getendpoints 测试测试table2 -7072928299163215694; 错误:对于输入字符串:“-7072928299163215694” - 堆栈跟踪 - java.lang.NumberFormatException:对于输入字符串:“-7072928299163215694”
我如何搜索分区键(名称)是否有 space?
您使用的是哪个 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 文档:
Provides the end points that own the partition key. The partitioner returns a token for the key. Cassandra will return an endpoint whether or not data exists on the identified node for that token. ** key is the partition key of the end points you want to get.
nodetool getendpoints 实际上将分区键的值作为输入。在这种情况下,'-7072928299163215694' 将其解析为整数,因此最终抛出异常。它适用于 long 或 String(它将“-7072928299163215694”值作为字符串),因为它已将此作为键的值而不是实际令牌。它不解析令牌。所以提供令牌作为输入是行不通的。
getendpoints 根据密钥的值生成令牌,并为您提供密钥所在的端点(节点)。
请检查此 link:
已为此提供补丁:
https://issues.apache.org/jira/browse/CASSANDRA-4551
希望对您有所帮助。
这是 nodetool
命令的问题。
我修改了 nodetool
脚本并创建了 getendpoints
脚本来支持 getendpoints 分区键有 space
这是 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 "[=10=]"`" = 'nodeprobe' ]; then
echo "***************************************************************" >&2
echo "WARNING: [=10=] is obsolete, use `dirname "[=10=]"`/nodetool instead" >&2
echo "***************************************************************" >&2
fi
if [ "x$CASSANDRA_INCLUDE" = "x" ]; then
for include in "`dirname "[=10=]"`/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 [ ! ]; then break; fi
case in
-p)
JMX_PORT=
shift
;;
--port=*)
JMX_PORT=$(echo | cut -d '=' -f 2)
;;
--port)
JMX_PORT=
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 "
;;
-k)
KS=
shift
;;
-t)
CF=
shift
;;
*)
if [ ! $KEY ]; then
KEY=""
else
KEY="$KEY "
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