Skip to content

Commit

Permalink
Uniform variable name: vertexes to vertices (#529)
Browse files Browse the repository at this point in the history
Change-Id: I05c0f52438e3ab74360b396d1c3a278d885a5426
  • Loading branch information
Linary authored and zhoney committed May 27, 2019
1 parent f86a716 commit 9db6d6a
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public List<HugeVertex> sourcesVertices(HugeGraph g) {
}
iter = g.vertices(sourceIds.toArray());
E.checkArgument(iter.hasNext(),
"Not exist source vertexes with ids %s",
"Not exist source vertices with ids %s",
this.ids);
} else {
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public User authenticate(final Map<String, String> credentials)

/**
* Verify if a user is legal
* @param username
* @param password
* @param username the username for authentication
* @param password the password for authentication
* @return String No permission if return ROLE_NONE else return a role
*/
public String authenticate(final String username, final String password) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void checkCapacity(long count) throws LimitExceedException {
query = query.substring(0, MAX_CHARS) + "...";
}
throw new LimitExceedException(
"Too many records(must <=%s) for the query: %s",
"Too many records(must <= %s) for the query: %s",
this.capacity, query);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public class GraphTransaction extends IndexableTransaction {

private final GraphIndexTransaction indexTx;

private Map<Id, HugeVertex> addedVertexes;
private Map<Id, HugeVertex> removedVertexes;
private Map<Id, HugeVertex> addedVertices;
private Map<Id, HugeVertex> removedVertices;

private Map<Id, HugeEdge> addedEdges;
private Map<Id, HugeEdge> removedEdges;
Expand All @@ -104,15 +104,15 @@ public class GraphTransaction extends IndexableTransaction {
* These are used to rollback state
* NOTE: props updates will be put into mutation directly(due to difficult)
*/
private Map<Id, HugeVertex> updatedVertexes;
private Map<Id, HugeVertex> updatedVertices;
private Map<Id, HugeEdge> updatedEdges;
private Set<HugeProperty<?>> updatedProps; // Oldest props

private LockUtil.LocksTable locksTable;

private final boolean checkVertexExist;

private final int vertexesCapacity;
private final int verticesCapacity;
private final int edgesCapacity;

public GraphTransaction(HugeGraph graph, BackendStore store) {
Expand All @@ -124,7 +124,7 @@ public GraphTransaction(HugeGraph graph, BackendStore store) {
final HugeConfig conf = graph.configuration();
this.checkVertexExist = conf.get(
CoreOptions.VERTEX_CHECK_CUSTOMIZED_ID_EXIST);
this.vertexesCapacity = conf.get(CoreOptions.VERTEX_TX_CAPACITY);
this.verticesCapacity = conf.get(CoreOptions.VERTEX_TX_CAPACITY);
this.edgesCapacity = conf.get(CoreOptions.EDGE_TX_CAPACITY);
this.locksTable = new LockUtil.LocksTable(graph.name());
}
Expand All @@ -144,9 +144,9 @@ protected void reset() {
super.reset();

// Clear mutation
this.addedVertexes = InsertionOrderUtil.newMap();
this.removedVertexes = InsertionOrderUtil.newMap();
this.updatedVertexes = InsertionOrderUtil.newMap();
this.addedVertices = InsertionOrderUtil.newMap();
this.removedVertices = InsertionOrderUtil.newMap();
this.updatedVertices = InsertionOrderUtil.newMap();

this.addedEdges = InsertionOrderUtil.newMap();
this.removedEdges = InsertionOrderUtil.newMap();
Expand All @@ -169,9 +169,9 @@ protected void beforeWrite() {
}

protected final int verticesInTxSize() {
return this.addedVertexes.size() +
this.removedVertexes.size() +
this.updatedVertexes.size();
return this.addedVertices.size() +
this.removedVertices.size() +
this.updatedVertices.size();
}

protected final int edgesInTxSize() {
Expand All @@ -181,19 +181,19 @@ protected final int edgesInTxSize() {
}

protected final Collection<HugeVertex> verticesInTxUpdated() {
int size = this.addedVertexes.size() + this.updatedVertexes.size();
int size = this.addedVertices.size() + this.updatedVertices.size();
List<HugeVertex> vertices = new ArrayList<>(size);
vertices.addAll(this.addedVertexes.values());
vertices.addAll(this.updatedVertexes.values());
vertices.addAll(this.addedVertices.values());
vertices.addAll(this.updatedVertices.values());
return vertices;
}

protected final Collection<HugeVertex> verticesInTxRemoved() {
return new ArrayList<>(this.removedVertexes.values());
return new ArrayList<>(this.removedVertices.values());
}

protected final boolean removingEdgeOwner(HugeEdge edge) {
for (HugeVertex vertex : this.removedVertexes.values()) {
for (HugeVertex vertex : this.removedVertices.values()) {
if (edge.belongToVertex(vertex)) {
return true;
}
Expand All @@ -205,23 +205,23 @@ protected final boolean removingEdgeOwner(HugeEdge edge) {
@Override
protected BackendMutation prepareCommit() {
// Serialize and add updates into super.deletions
if (this.removedVertexes.size() > 0 || this.removedEdges.size() > 0) {
this.prepareDeletions(this.removedVertexes, this.removedEdges);
if (this.removedVertices.size() > 0 || this.removedEdges.size() > 0) {
this.prepareDeletions(this.removedVertices, this.removedEdges);
}
// Serialize and add updates into super.additions
if (this.addedVertexes.size() > 0 || this.addedEdges.size() > 0) {
this.prepareAdditions(this.addedVertexes, this.addedEdges);
if (this.addedVertices.size() > 0 || this.addedEdges.size() > 0) {
this.prepareAdditions(this.addedVertices, this.addedEdges);
}
return this.mutation();
}

protected void prepareAdditions(Map<Id, HugeVertex> addedVertexes,
protected void prepareAdditions(Map<Id, HugeVertex> addedVertices,
Map<Id, HugeEdge> addedEdges) {
if (this.checkVertexExist) {
this.checkVertexExistIfCustomizedId(addedVertexes);
this.checkVertexExistIfCustomizedId(addedVertices);
}
// Do vertex update
for (HugeVertex v : addedVertexes.values()) {
for (HugeVertex v : addedVertices.values()) {
assert !v.removed();
v.committed();
// Add vertex entry
Expand All @@ -248,10 +248,10 @@ protected void prepareAdditions(Map<Id, HugeVertex> addedVertexes,
}
}

protected void prepareDeletions(Map<Id, HugeVertex> removedVertexes,
protected void prepareDeletions(Map<Id, HugeVertex> removedVertices,
Map<Id, HugeEdge> removedEdges) {
// Remove related edges of each vertex
for (HugeVertex v : removedVertexes.values()) {
for (HugeVertex v : removedVertices.values()) {
// Query all edges of the vertex and remove them
Query query = constructEdgesQuery(v.id(), Directions.BOTH);
Iterator<HugeEdge> vedges = this.queryEdgesFromBackend(query);
Expand All @@ -263,8 +263,8 @@ protected void prepareDeletions(Map<Id, HugeVertex> removedVertexes,
}
}

// Remove vertexes
for (HugeVertex v : removedVertexes.values()) {
// Remove vertices
for (HugeVertex v : removedVertices.values()) {
/*
* If the backend stores vertex together with edges, it's edges
* would be removed after removing vertex. Otherwise, if the
Expand Down Expand Up @@ -345,8 +345,8 @@ public HugeVertex addVertex(Object... keyValues) {
public HugeVertex addVertex(HugeVertex vertex) {
this.checkOwnerThread();

// Override vertexes in local `removedVertexes`
this.removedVertexes.remove(vertex.id());
// Override vertices in local `removedVertices`
this.removedVertices.remove(vertex.id());
try {
this.locksTable.lockReads(LockUtil.VERTEX_LABEL_DELETE,
vertex.schemaLabel().id());
Expand All @@ -360,7 +360,7 @@ public HugeVertex addVertex(HugeVertex vertex) {
* unconcerned with add vertex
*/
this.beforeWrite();
this.addedVertexes.put(vertex.id(), vertex);
this.addedVertices.put(vertex.id(), vertex);
this.afterWrite();
} catch (Throwable e){
this.locksTable.unlock();
Expand Down Expand Up @@ -408,11 +408,11 @@ public void removeVertex(HugeVertex vertex) {

this.beforeWrite();

// Override vertexes in local `addedVertexes`
this.addedVertexes.remove(vertex.id());
// Override vertices in local `addedVertices`
this.addedVertices.remove(vertex.id());

// Collect the removed vertex
this.removedVertexes.put(vertex.id(), vertex);
this.removedVertices.put(vertex.id(), vertex);

this.afterWrite();
}
Expand Down Expand Up @@ -440,11 +440,11 @@ public Iterator<Vertex> queryVertices(Object... vertexIds) {
for (Object vertexId : vertexIds) {
HugeVertex vertex;
Id id = HugeVertex.getIdValue(vertexId);
if (id == null || this.removedVertexes.containsKey(id)) {
if (id == null || this.removedVertices.containsKey(id)) {
// The record has been deleted
continue;
} else if ((vertex = this.addedVertexes.get(id)) != null ||
(vertex = this.updatedVertexes.get(id)) != null) {
} else if ((vertex = this.addedVertices.get(id)) != null ||
(vertex = this.updatedVertices.get(id)) != null) {
// Found from local tx
vertices.put(vertex.id(), vertex);
} else {
Expand Down Expand Up @@ -645,7 +645,7 @@ public Iterator<Edge> queryEdges(Query query) {

@SuppressWarnings("unchecked")
Iterator<Edge> r = (Iterator<Edge>) joinTxEdges(query, results,
this.removedVertexes);
this.removedVertices);
return r;
}

Expand Down Expand Up @@ -681,12 +681,12 @@ public <V> void addVertexProperty(HugeVertexProperty<V> prop) {
return;
}
// Check is updating property of added/removed vertex
E.checkArgument(!this.addedVertexes.containsKey(vertex.id()) ||
this.updatedVertexes.containsKey(vertex.id()),
E.checkArgument(!this.addedVertices.containsKey(vertex.id()) ||
this.updatedVertices.containsKey(vertex.id()),
"Can't update property '%s' for adding-state vertex",
prop.key());
E.checkArgument(!vertex.removed() &&
!this.removedVertexes.containsKey(vertex.id()),
!this.removedVertices.containsKey(vertex.id()),
"Can't update property '%s' for removing-state vertex",
prop.key());
// Check is updating primary key
Expand Down Expand Up @@ -736,11 +736,11 @@ public <V> void removeVertexProperty(HugeVertexProperty<V> prop) {
return;
}
// Check is updating property of added/removed vertex
E.checkArgument(!this.addedVertexes.containsKey(vertex.id()) ||
this.updatedVertexes.containsKey(vertex.id()),
E.checkArgument(!this.addedVertices.containsKey(vertex.id()) ||
this.updatedVertices.containsKey(vertex.id()),
"Can't remove property '%s' for adding-state vertex",
prop.key());
E.checkArgument(!this.removedVertexes.containsKey(vertex.id()),
E.checkArgument(!this.removedVertices.containsKey(vertex.id()),
"Can't remove property '%s' for removing-state vertex",
prop.key());

Expand Down Expand Up @@ -1232,12 +1232,12 @@ private Iterator<?> joinTxVertices(Query query,
assert query.resultType().isVertex();
return this.joinTxRecords(query, vertices,
(q, v) -> q.test(v) ? v : null,
this.addedVertexes, this.removedVertexes,
this.updatedVertexes);
this.addedVertices, this.removedVertices,
this.updatedVertices);
}

private Iterator<?> joinTxEdges(Query query, Iterator<HugeEdge> edges,
Map<Id, HugeVertex> removingVertexes) {
Map<Id, HugeVertex> removingVertices) {
assert query.resultType().isEdge();
final BiFunction<Query, HugeEdge, HugeEdge> matchTxEdges = (q, e) -> {
assert q.resultType() == HugeType.EDGE;
Expand All @@ -1246,12 +1246,12 @@ private Iterator<?> joinTxEdges(Query query, Iterator<HugeEdge> edges,
edges = this.joinTxRecords(query, edges, matchTxEdges,
this.addedEdges, this.removedEdges,
this.updatedEdges);
if (removingVertexes.isEmpty()) {
if (removingVertices.isEmpty()) {
return edges;
}
// Filter edges that belong to deleted vertex
return new FilterIterator<HugeEdge>(edges, edge -> {
for (HugeVertex v : removingVertexes.values()) {
for (HugeVertex v : removingVertices.values()) {
if (edge.belongToVertex(v)) {
return false;
}
Expand Down Expand Up @@ -1308,10 +1308,10 @@ private <V extends HugeElement> Iterator<V> joinTxRecords(
}

private void checkTxVerticesCapacity() throws LimitExceedException {
if (this.verticesInTxSize() >= this.vertexesCapacity) {
if (this.verticesInTxSize() >= this.verticesCapacity) {
throw new LimitExceedException(
"Vertices size has reached tx capacity %d",
this.vertexesCapacity);
this.verticesCapacity);
}
}

Expand All @@ -1324,7 +1324,7 @@ private void checkTxEdgesCapacity() throws LimitExceedException {
}

private void propertyUpdated(HugeVertex vertex, HugeProperty<?> property) {
this.updatedVertexes.put(vertex.id(), vertex);
this.updatedVertices.put(vertex.id(), vertex);
if (property != null) {
this.updatedProps.add(property);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public boolean supportsUserSuppliedIds() {
return false;
}

@Override
public boolean willAllowId(Object id) {
if(!this.supportsUserSuppliedIds()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public static int writeAsciiString(byte[] array,
int c = attribute.charAt(i);
assert c <= 127;
byte b = (byte) c;
if (++i == len)
if (++i == len) {
b |= 0x80; // End marker
}
array[startPos++] = b;
} while (i < len);

Expand All @@ -54,8 +55,9 @@ public static String readAsciiString(byte[] array, int startPos) {
int c = 0;
do {
c = 0xFF & array[startPos++];
if (c != 0x80)
if (c != 0x80) {
sb.append((char) (c & 0x7F));
}
} while ((c & 0x80) <= 0);
return sb.toString();
}
Expand Down
Loading

0 comments on commit 9db6d6a

Please sign in to comment.