Skip to content

Commit 4cc3a88

Browse files
author
DvirDukhan
committed
changed pull request comments
1 parent 36cf626 commit 4cc3a88

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

src/main/java/com/redislabs/redisgraph/RedisGraph.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,10 @@ private BinaryClient sendCommand(Jedis conn, ProtocolCommand provider, String ..
157157
* @return
158158
*/
159159
private BinaryClient sendCompactCommand(Jedis conn, ProtocolCommand provider, String ...args) {
160-
BinaryClient binaryClient = conn.getClient();
161160
String[] t = new String[args.length +1];
162161
System.arraycopy(args, 0 , t, 0, args.length);
163162
t[args.length]="--COMPACT";
164-
binaryClient.sendCommand(provider, t);
165-
return binaryClient;
163+
return sendCommand(conn, provider, t);
166164
}
167165

168166
private Jedis getConnection() {
@@ -175,18 +173,18 @@ private Jedis getConnection() {
175173
* @param graphId a graph to perform the query on
176174
* @param procedure - procedure to execute
177175
* @param args - procedure arguments
178-
* @param kwargs
176+
* @param kwargs - procedure output arguments
179177
* @return
180178
*/
181179
public ResultSet callProcedure(String graphId, String procedure, List<String> args , Map<String, List<String>> kwargs ){
182180

183181
args = args.stream().map( s -> Utils.quoteString(s)).collect(Collectors.toList());
184-
StringBuilder q = new StringBuilder();
185-
q.append(String.format("CALL %s(%s)", procedure, String.join(",", args)));
186-
List<String> y = kwargs.getOrDefault("y", null);
187-
if(y != null){
188-
q.append(String.join(",", y));
182+
StringBuilder queryString = new StringBuilder();
183+
queryString.append(String.format("CALL %s(%s)", procedure, String.join(",", args)));
184+
List<String> kwargsList = kwargs.getOrDefault("y", null);
185+
if(kwargsList != null){
186+
queryString.append(String.join(",", kwargsList));
189187
}
190-
return query(graphId, q.toString());
188+
return query(graphId, queryString.toString());
191189
}
192190
}

src/main/java/com/redislabs/redisgraph/impl/GraphCache.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
*/
99
public class GraphCache {
1010

11-
GraphCacheList labels;
12-
GraphCacheList propertyNames;
13-
GraphCacheList relationshipTypes;
11+
private final GraphCacheList labels;
12+
private final GraphCacheList propertyNames;
13+
private final GraphCacheList relationshipTypes;
1414

1515
/**
1616
*

src/main/java/com/redislabs/redisgraph/impl/GraphCacheList.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
import com.redislabs.redisgraph.ResultSet;
66

77
import java.util.ArrayList;
8+
import java.util.List;
9+
import java.util.concurrent.CopyOnWriteArrayList;
810
import java.util.concurrent.locks.ReentrantReadWriteLock;
911

1012
/**
1113
* Represents a local cache of list of strings. Holds data from a specific procedure, for a specific graph.
1214
*/
13-
public class GraphCacheList extends ArrayList<String> {
15+
public class GraphCacheList {
1416

15-
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
16-
private final ReentrantReadWriteLock.ReadLock readLock = lock.readLock();
17-
private final ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();
17+
private Object mutex = new Object();
1818
private final String graphId;
1919
private final String procedure;
2020
private final RedisGraph redisGraph;
21+
List<String> data = new CopyOnWriteArrayList<>();
22+
23+
2124

2225
/**
2326
*
@@ -38,17 +41,14 @@ public GraphCacheList(String graphId, String procedure, RedisGraph redisGraph) {
3841
* @return The string value of the specific procedure response, at the given index.
3942
*/
4043
public String getCachedData(int index) {
41-
if (index >= this.size()) {
42-
writeLock.lock();
43-
//check again
44-
if (index >= this.size()) {
45-
getProcedureInfo();
44+
if (index >= data.size()) {
45+
synchronized (mutex){
46+
if (index >= data.size()) {
47+
getProcedureInfo();
48+
}
4649
}
47-
writeLock.unlock();
4850
}
49-
readLock.lock();
50-
String s = this.get(index);
51-
readLock.unlock();
51+
String s = data.get(index);
5252
return s;
5353

5454
}
@@ -58,10 +58,15 @@ public String getCachedData(int index) {
5858
*/
5959
private void getProcedureInfo() {
6060
ResultSet resultSet = redisGraph.callProcedure(graphId, procedure);
61-
this.clear();
61+
List<String> newData = new ArrayList<>();
62+
int i = data.size();
6263
while (resultSet.hasNext()) {
6364
Record record = resultSet.next();
64-
this.add(record.getString(0));
65+
if(i >= data.size()){
66+
newData.add(record.getString(0));
67+
}
68+
i++;
6569
}
70+
data.addAll(newData);
6671
}
6772
}

src/main/java/com/redislabs/redisgraph/impl/StatisticsImpl.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ public class StatisticsImpl implements Statistics {
2929
}
3030

3131

32-
public List<byte[]> getRaw() {
33-
return raw;
34-
}
35-
3632
/**
3733
*
3834
* @param label the requested statistic label as key
@@ -138,13 +134,13 @@ public boolean equals(Object o) {
138134
if (this == o) return true;
139135
if (!(o instanceof StatisticsImpl)) return false;
140136
StatisticsImpl that = (StatisticsImpl) o;
141-
return Objects.equals(getRaw(), that.getRaw()) &&
137+
return Objects.equals(raw, raw) &&
142138
Objects.equals(getStatistics(), that.getStatistics());
143139
}
144140

145141
@Override
146142
public int hashCode() {
147-
return Objects.hash(getRaw(), getStatistics());
143+
return Objects.hash(raw, getStatistics());
148144
}
149145

150146
@Override

0 commit comments

Comments
 (0)