我最近开始使用Cassandra数据库.我已经安装single node cluster在我当地的盒子里.我正在与之合作Cassandra 1.2.3.
我正在网上阅读这篇文章,我发现这条线 -
Cassandra写入首先写入提交日志(用于持久性),然后写入称为memtable的内存表结构.写入提交日志和内存后写入成功,因此写入时磁盘I/O非常小.写入在内存中进行批处理,并定期写入磁盘到称为SSTable(已排序的字符串表)的持久表结构.
因此,为了理解上述内容,我编写了一个简单的程序,它将使用Cassandra数据库写入Pelops client.我能够在Cassandra数据库中插入数据.
现在我想看看我的数据是如何写入的,commit log以及它在哪里commit log file?还有如何SSTables生成以及我可以在本地框中找到它以及它包含的内容.
我想看看这两个文件,以便我能更好地了解Cassandra在幕后的工作原理.
在我的cassandra.yaml文件中,我有类似的东西
# directories where Cassandra should store data on disk.
data_file_directories:
- S:\Apache Cassandra\apache-cassandra-1.2.3\storage\data
# commit log
commitlog_directory: S:\Apache Cassandra\apache-cassandra-1.2.3\storage\commitlog
# saved caches
saved_caches_directory: S:\Apache Cassandra\apache-cassandra-1.2.3\storage\savedcaches
Run Code Online (Sandbox Code Playgroud)
但是当我打开commitLog时,首先它有很多数据,所以我的记事本++无法正确打开它,如果它被打开,我无法正确看到因为某些编码或什么.在我的数据文件夹中,我找不到任何东西?
这个文件夹对我来说是空的 -
S:\Apache Cassandra\apache-cassandra-1.2.3\storage\data\my_keyspace\users
Run Code Online (Sandbox Code Playgroud)
这里有什么我想念的吗?任何人都可以解释我如何读取commitLog和SSTables文件以及我在哪里可以找到这两个文件?而且每当我写信给Cassandra数据库时,幕后究竟会发生什么.
更新:-
我用来插入Cassandra数据库的代码 -
public class MyPelops {
private static final Logger log = Logger.getLogger(MyPelops.class);
public static void main(String[] args) throws Exception {
// -------------------------------------------------------------
// -- Nodes, Pool, Keyspace, Column Family ---------------------
// -------------------------------------------------------------
// A comma separated List of Nodes
String NODES = "localhost";
// Thrift Connection Pool
String THRIFT_CONNECTION_POOL = "Test Cluster";
// Keyspace
String KEYSPACE = "my_keyspace";
// Column Family
String COLUMN_FAMILY = "users";
// -------------------------------------------------------------
// -- Cluster --------------------------------------------------
// -------------------------------------------------------------
Cluster cluster = new Cluster(NODES, 9160);
Pelops.addPool(THRIFT_CONNECTION_POOL, cluster, KEYSPACE);
// -------------------------------------------------------------
// -- Mutator --------------------------------------------------
// -------------------------------------------------------------
Mutator mutator = Pelops.createMutator(THRIFT_CONNECTION_POOL);
log.info("- Write Column -");
mutator.writeColumn(
COLUMN_FAMILY,
"Row1",
new Column().setName(" Name ".getBytes()).setValue(" Test One ".getBytes()).setTimestamp(new Date().getTime()));
mutator.writeColumn(
COLUMN_FAMILY,
"Row1",
new Column().setName(" Work ".getBytes()).setValue(" Engineer ".getBytes()).setTimestamp(new Date().getTime()));
log.info("- Execute -");
mutator.execute(ConsistencyLevel.ONE);
// -------------------------------------------------------------
// -- Selector -------------------------------------------------
// -------------------------------------------------------------
Selector selector = Pelops.createSelector(THRIFT_CONNECTION_POOL);
int columnCount = selector.getColumnCount(COLUMN_FAMILY, "Row1",
ConsistencyLevel.ONE);
System.out.println("- Column Count = " + columnCount);
List<Column> columnList = selector
.getColumnsFromRow(COLUMN_FAMILY, "Row1",
Selector.newColumnsPredicateAll(true, 10),
ConsistencyLevel.ONE);
System.out.println("- Size of Column List = " + columnList.size());
for (Column column : columnList) {
System.out.println("- Column: (" + new String(column.getName()) + ","
+ new String(column.getValue()) + ")");
}
System.out.println("- All Done. Exit -");
System.exit(0);
}
}
Run Code Online (Sandbox Code Playgroud)
我创建的Keyspace和Column系列 -
create keyspace my_keyspace with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' and strategy_options = {replication_factor:1};
use my_keyspace;
create column family users with column_type = 'Standard' and comparator = 'UTF8Type';
Run Code Online (Sandbox Code Playgroud)
abh*_*bhi 37
你的理解几乎就在那里.但是,遗漏了一些细节.
因此,以结构化的方式解释事物,cassandra写操作生命周期分为这些步骤
Cassandra写入首先写入提交日志(用于持久性),然后写入称为memtable的内存表结构.一旦写入写入提交日志和内存,写入就会成功,因此写入时磁盘I/O非常小.当memtable耗尽空间时,即当键的数量超过一定限度(默认值为128)或达到持续时间(簇时钟)时,它将被存储到sstable,immutable space(此机制称为Flushing)).一旦在SSTable上完成写入,您就可以在数据文件夹中看到相应的数据,在您的情况下S:\Apache Cassandra\apache-cassandra-1.2.3\storage\data.每个SSTable主要由2个文件组成 - 索引文件和数据文件
索引文件包含 - Bloom过滤器和Key-Offset对
数据文件包含实际的列数据
关于commitlog文件,这些是Cassandra内在维护的加密文件,您无法正常查看.
更新:
Memtable是内存缓存,内容存储为键/列(数据按键排序).每个列族都有一个单独的Memtable,并从密钥中检索列数据.所以现在我希望你能清楚地理解这个事实,为什么我们无法在磁盘中找到它们.
在您的情况下,您的记忆不完整,因为可记忆的阈值没有被漂白但导致没有刷新.您可以在此处了解有关MemtableThresholds的更多信息,但建议不要触摸该拨号.
SSTableStructure:
有关更多信息,请参阅sstable
| 归档时间: |
|
| 查看次数: |
11242 次 |
| 最近记录: |