Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inefficient Usages of Java Collections #134

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -178,7 +178,7 @@ public Status addStorageEngines(AddStorageEnginesReq req) {
return RpcUtils.ACCESS_DENY;
}
List<StorageEngine> storageEngines = req.getStorageEngines();
List<StorageEngineMeta> storageEngineMetas = new ArrayList<>();
LinkedList<StorageEngineMeta> storageEngineMetas = new LinkedList<>();

Map<cn.edu.tsinghua.iginx.db.StorageEngine, Method> checkConnectionMethods = new HashMap<>();
String[] driverInfos = ConfigDescriptor.getInstance().getConfig().getDatabaseClassNames().split(",");
Expand Down Expand Up @@ -219,7 +219,7 @@ public Status addStorageEngines(AddStorageEnginesReq req) {
Status status = RpcUtils.SUCCESS;
// 检测是否与已有的存储单元冲突
List<StorageEngineMeta> currentStorageEngines = metaManager.getStorageEngineList();
List<StorageEngineMeta> duplicatedStorageEngine = new ArrayList<>();
List<StorageEngineMeta> duplicatedStorageEngine = new LinkedList<>();
for (StorageEngineMeta storageEngine: storageEngineMetas) {
for (StorageEngineMeta currentStorageEngine: currentStorageEngines) {
if (currentStorageEngine.getIp().equals(storageEngine.getIp()) && currentStorageEngine.getPort() == storageEngine.getPort()) {
Expand All @@ -238,7 +238,7 @@ public Status addStorageEngines(AddStorageEnginesReq req) {
status.setMessage("unexpected repeated add");
}
if (!storageEngineMetas.isEmpty()) {
storageEngineMetas.get(storageEngineMetas.size() - 1).setLastOfBatch(true); // 每一批最后一个是 true,表示需要进行扩容
storageEngineMetas.getLast().setLastOfBatch(true); // 每一批最后一个是 true,表示需要进行扩容
}
if (!metaManager.addStorageEngines(storageEngineMetas)) {
status = RpcUtils.FAILURE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -105,7 +106,7 @@ private DefaultMetaManager() {
break;
}

storageEngineChangeHooks = Collections.synchronizedList(new ArrayList<>());
storageEngineChangeHooks = Collections.synchronizedList(new LinkedList<>());

try {
initIginx();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Deque;
import java.util.List;
import java.util.Map;
Expand All @@ -28,7 +29,7 @@ public class BooleanExpression {
private String boolExpression;
private List<Element> postfixExpression;
private TreeNode root;
private List<String> timeseries = new ArrayList<>();
private List<String> timeseries = new LinkedList<>();

public BooleanExpression(String str) {
boolExpression = str;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.io.Reader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand All @@ -46,7 +47,7 @@ public class DataPointsParser {
private final IMetaManager metaManager = DefaultMetaManager.getInstance();
private Reader inputStream = null;
private ObjectMapper mapper = new ObjectMapper();
private List<Metric> metricList = new ArrayList<>();
private List<Metric> metricList = new LinkedList<>();
private RestSession session = new RestSession();

public DataPointsParser() {
Expand Down Expand Up @@ -347,4 +348,4 @@ DataType findType(List<String> values) {
}
return DataType.DOUBLE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import cn.edu.tsinghua.iginx.rest.query.aggregator.QueryAggregator;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
Expand All @@ -29,7 +30,7 @@ public class QueryMetric {
private String name;
private Long limit;
private Map<String, List<String>> tags = new TreeMap();
private List<QueryAggregator> aggregators = new ArrayList<>();
private List<QueryAggregator> aggregators = new LinkedList<>();
private Boolean annotation = false;
private AnnotationLimit annotationLimit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private String sampleSizeToString(int num) {
private Map<String, List<String>> getTagsFromPaths(String name, List<String> paths) throws Exception {
List<Map<String, Integer>> dup = new ArrayList<>();
Map<String, List<String>> ret = new TreeMap<>();
Map<Integer, String> pos2path = new TreeMap<>();
Map<Integer, String> pos2path = new HashMap<>();
Map<String, Integer> metricschema = metaManager.getSchemaMapping(name);
if (metricschema == null) {
throw new Exception("No metadata found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import cn.edu.tsinghua.iginx.session.SessionQueryDataSet;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class QueryAggregatorSaveAs extends QueryAggregator {
Expand All @@ -35,7 +36,7 @@ public QueryAggregatorSaveAs() {
@Override
public QueryResultDataset doAggregate(RestSession session, List<String> paths, long startTimestamp, long endTimestamp) {
DataPointsParser parser = new DataPointsParser();
List<Metric> metrics = new ArrayList<>();
List<Metric> metrics = new LinkedList<>();
Metric ins = new Metric();
String name = paths.get(0).split("\\.")[paths.get(0).split("\\.").length - 1];
ins.setName(getMetric_name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import cn.edu.tsinghua.iginx.utils.RpcUtils;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -41,7 +42,7 @@ public class SelectOperator extends Operator {
public SelectOperator() {
this.operatorType = OperatorType.SELECT;
this.queryType = QueryType.Unknown;
selectedFuncsAndPaths = new ArrayList<>();
selectedFuncsAndPaths = new LinkedList<>();
funcTypeSet = new HashSet<>();
fromPath = "";
startTime = Long.MIN_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class IginXPreparedStatement extends IginXStatement implements PreparedStatement {

private String sql;
private final Map<Integer, String> params = new LinkedHashMap<>();
private final Map<Integer, String> params = new HashMap<>();

public IginXPreparedStatement(IginXConnection connection, Session session, String sql) {
super(connection, session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import cn.edu.tsinghua.iginx.thrift.LastQueryResp;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import static cn.edu.tsinghua.iginx.utils.ByteUtils.getLongArrayFromByteBuffer;
Expand All @@ -36,7 +37,7 @@ public class LastQueryDataSet {
}

LastQueryDataSet(LastQueryResp resp) {
points = new ArrayList<>();
points = new LinkedList<>();
List<String> paths = resp.getPaths();
List<DataType> dataTypes = resp.getDataTypeList();
long[] timestamps = getLongArrayFromByteBuffer(resp.timestamps);
Expand Down