DataModel use case for logging in Cassandra

余生颓废 提交于 2019-12-11 07:32:02

问题


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.


回答1:


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)
);

This will allow to have single partition for every combination of the module & yyyymmdd values, so you won't have very wide partitions.

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?).

P.S. Are you using pure Cassandra, or DSE?



来源:https://stackoverflow.com/questions/48920971/datamodel-use-case-for-logging-in-cassandra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!