在运行 Cassandra Daemon 时,我遇到了以下异常。我从 1.2 主干运行。
WARN 14:47:51,038 error reading saved cache /home/manuzhang/cassandra/saved_caches/system-local-KeyCache-b.db
java.lang.NullPointerException
at org.apache.cassandra.cache.AutoSavingCache.loadSaved(AutoSavingCache.java:141)
at org.apache.cassandra.db.ColumnFamilyStore.<init>(ColumnFamilyStore.java:237)
at org.apache.cassandra.db.ColumnFamilyStore.createColumnFamilyStore(ColumnFamilyStore.java:340)
at org.apache.cassandra.db.ColumnFamilyStore.createColumnFamilyStore(ColumnFamilyStore.java:312)
at org.apache.cassandra.db.Table.initCf(Table.java:332)
at org.apache.cassandra.db.Table.<init>(Table.java:265)
at org.apache.cassandra.db.Table.open(Table.java:110)
at org.apache.cassandra.db.Table.open(Table.java:88)
at org.apache.cassandra.db.SystemTable.checkHealth(SystemTable.java:284)
at org.apache.cassandra.service.CassandraDaemon.setup(CassandraDaemon.java:168)
at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:318)
at org.apache.cassandra.service.CassandraDaemon.main(CassandraDaemon.java:361)
这是保存缓存的地方:
manuzhang@manuzhang-U24E:~/cassandra/saved_caches$ ls -l
total 12
-rw-rw-r-- 1 manuzhang manuzhang 156 Aug 7 13:09 system-local-KeyCache-b.db
-rw-rw-r-- 1 manuzhang manuzhang 60 Aug 7 13:09 system-schema_columnfamilies-KeyCache-b.db
-rw-rw-r-- 1 manuzhang manuzhang 60 Aug 7 13:09 system-schema_columns-KeyCache-b.db
此外,无法加载系统表文件。
ERROR 17:03:16,637 Fatal exception during initialization
org.apache.cassandra.config.ConfigurationException: Found system table files, but they couldn't be loaded!
at org.apache.cassandra.db.SystemTable.checkHealth(SystemTable.java:303)
at org.apache.cassandra.service.CassandraDaemon.setup(CassandraDaemon.java:201)
at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:349)
at org.apache.cassandra.service.CassandraDaemon.main(CassandraDaemon.java:392)
现在我能够重现每运行三轮Cassandra 的加载系统表故障(之后我清理了所有文件)。这里抛出异常:
/**
* One of three things will happen if you try to read the system table:
* 1. files are present and you can read them: great
* 2. no files are there: great (new node is assumed)
* 3. files are present but you can't read them: bad
* @throws ConfigurationException
*/
public static void checkHealth() throws ConfigurationException
{
Table table;
try
{
table = Table.open(Table.SYSTEM_TABLE);
}
catch (AssertionError err)
{
// this happens when a user switches from OPP to RP.
ConfigurationException ex = new ConfigurationException("Could not read system table!");
ex.initCause(err);
throw ex;
}
ColumnFamilyStore cfs = table.getColumnFamilyStore(LOCAL_CF);
String req = "SELECT cluster_name FROM system.%s WHERE key='%s'";
UntypedResultSet result = processInternal(String.format(req, LOCAL_CF, LOCAL_KEY));
if (result.isEmpty() || !result.one().has("cluster_name"))
{
// this is a brand new node
if (!cfs.getSSTables().isEmpty())
throw new ConfigurationException("Found system table files, but they couldn't be loaded!");
// no system files. this is a new node.
req = "INSERT INTO system.%s (key, cluster_name) VALUES ('%s', '%s')";
processInternal(String.format(req, LOCAL_CF, LOCAL_KEY, DatabaseDescriptor.getClusterName()));
return;
}
String savedClusterName = result.one().getString("cluster_name");
if (!DatabaseDescriptor.getClusterName().equals(savedClusterName))
throw new ConfigurationException("Saved cluster name " + savedClusterName + " != configured name " + DatabaseDescriptor.getClusterName());
}
这三个运行与评论中的三个条件完全对应。
第一次运行时“没有文件”,因为它是一个全新的节点。
在第二次运行中,“文件在那里,您可以阅读它们”。
在第三次运行中,“文件在那里,但您无法读取它们”,我已经检查了两者result.isEmpty()
并result.one.has("cluster_name")
返回false
.
实际上,我对“无法加载”的异常感到困惑。这是什么意思?我认为这不是文件系统权限问题,因为当前用户已授予 r/w 权限。
删除所有相关文件后,上述问题就消失了,但我不想每次运行 Cassandra 时都这样做。
这一直困扰着我很长一段时间。
一个不相关的问题是我认为 Cassandra@stackoverflow 没有得到社区足够的关注。你同意吗?
任何想法或建议将不胜感激。
谢谢。