运行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已经得到社区足够的关注。你同意吗?
任何想法或建议将不胜感激。
感谢。
答案 0 :(得分:1)
我在两种情况下遇到了这个问题。
sudo ./cassandra
,它只为超级用户创建了必需的数据/日志/缓存目录,然后重新启动cassandra并以普通用户身份运行该进程(因此没有权限使用超级用户运行的进程创建的目录中的文件)。我知道你解决了这个问题,但这可能对其他开发人员有用。