用于登录Cassandra的DataModel用例 [英] DataModel use case for logging in Cassandra
问题描述
我正在尝试在Cassandra中设计应用程序日志表,
I am trying to design the application log table in Cassandra,
CREATE TABLE log(
yyyymmdd varchar,
created timeuuid,
logMessage text,
module text,
PRIMARY KEY(yyyymmdd, created)
);
现在,当我尝试执行以下查询时,它按预期运行,
Now when I try to perform the following queries it is working as expected,
select * from log where yymmdd = '20182302' LIMIT 50;
以上查询没有分组,是全局的。
Above query is without grouping, kind of global.
当前,我为模块做了一个二级索引,因此我能够执行以下操作,
Currently I did an secondary index for 'module' so I am able to perform the following,
select * from log where yymmdd = '20182302' WHERE module LIKE 'test' LIMIT 50;
现在,我担心的是没有做 二级索引 ,是否有基于模块查询和获取数据的有效方法(或)是否有更好的设计?
Now my concern is without doing the secondary index, Is there an efficient way to query based on the module and fetch the data (or) Is there a better design?
也请让我知道当前设计中的性能问题。
Also let me know the performance issue in current design.
推荐答案
对于基于模块
和日期的获取,您只能使用另一个表,如下所示:
For fetching based on module
and date, you can only use another table, like this:
CREATE TABLE module_log(
yyyymmdd varchar,
created timeuuid,
logMessage text,
module text,
PRIMARY KEY((module,yyyymmdd), created)
);
这将允许对模块的每种组合使用单个分区
& yyyymmdd
值,因此分区不会非常宽。
This will allow to have single partition for every combination of the module
& yyyymmdd
values, so you won't have very wide partitions.
此外,请注意,如果创建了仅在 module
字段上的二级索引-您可能会遇到分区太大的问题(我假设您的 module $ c数量非常有限$ c>值?)。
Also, take into account that if you created a secondary index only on module
field - you may get problems with too big partitions (I assume that you have very limited number of module
values?).
PS您使用的是纯Cassandra还是DSE?
P.S. Are you using pure Cassandra, or DSE?
这篇关于用于登录Cassandra的DataModel用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!