首页 > 解决方案 > 日志搜索服务的数据结构?

问题描述

几个月前,我被要求设计一个服务,它需要一个开始和结束时间间隔,并列出按异常类型/代码分组的异常/错误数量。基本上,目的是创建或使用现有数据结构进行有效搜索。这是我编码的。

public class ErrorDetail{
  private int code;
  private String message;
}

public class ExceptionSearchService
{
private Map<Long, ErrorDetail> s = new TreeMap<Long, ErrorDetail>();
public ArrayList<ErrorDetail> getErrors(long start, long end){
 ErrorDetail e1 = find(start, s);
 ErrorDetail e2 = find(end, s);
 //do an in order traversal between e1 and e2 and add it to an array list and return  
}

public void addError(long time, ErrorDetail e){
s.put(time,e);
}

}

我意识到我不应该提到 TreeMap,而是应该有我自己的类,比如 TreeNode,但我的想法是有一个树结构和一个分布式的,因为我们正在谈论成千上万的服务每分钟服务数百万个请求并产生错误.

在这种情况下我可以使用更好的数据结构吗?

标签: data-structures

解决方案


推荐阅读