Skip to content

Commit

Permalink
Modified on IdHolder and related classes
Browse files Browse the repository at this point in the history
Change-Id: If9709dd1fb8e584630c48db01edd2ce99b65636b
  • Loading branch information
Linary committed Mar 22, 2019
1 parent 15d7395 commit a565f26
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
package com.baidu.hugegraph.backend.page;

import java.util.Set;
import java.util.function.Supplier;
import java.util.function.Function;

import com.baidu.hugegraph.backend.id.Id;
import com.baidu.hugegraph.backend.query.Query;
import com.baidu.hugegraph.backend.query.ConditionQuery;
import com.baidu.hugegraph.util.E;

public final class IdHolder {

private final Query query;
private final Supplier<PageIds> idsFetcher;
private final ConditionQuery query;
private final Function<ConditionQuery, PageIds> idsFetcher;
private boolean exhausted;

private Set<Id> ids;
Expand All @@ -47,11 +47,12 @@ public IdHolder(Set<Id> ids) {
/**
* For paged situation
*/
public IdHolder(Query query, Supplier<PageIds> idsFetcher) {
public IdHolder(ConditionQuery query,
Function<ConditionQuery, PageIds> idsFetcher) {
E.checkArgument(query.paging(),
"Query '%s' must carry the page info in paged mode",
query);
this.query = query;
this.query = query.copy();
this.idsFetcher = idsFetcher;
this.exhausted = false;
this.ids = null;
Expand Down Expand Up @@ -85,7 +86,7 @@ public PageIds fetchNext(String page, long pageSize) {
this.query.page(page);
this.query.limit(pageSize);

PageIds result = this.idsFetcher.get();
PageIds result = this.idsFetcher.apply(this.query);

assert result != null;
this.ids = result.ids();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public boolean paging() {
public boolean add(IdHolder holder) {
E.checkArgument(this.paging == holder.paging(),
"The IdHolder to be linked must be " +
"IdHolder in paging mode");
"IdHolder in same paging mode");
if (this.paging || this.isEmpty()) {
super.add(holder);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private boolean fetch() {

@Override
public BackendEntry next() {
if (!this.results.iterator().hasNext() && !this.hasNext()) {
if (!this.hasNext()) {
throw new NoSuchElementException();
}
BackendEntry entry = this.results.iterator().next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,16 @@ private IdHolder doIndexQuery(IndexLabel indexLabel,
@Watched(prefix = "index")
private IdHolder doIndexQueryInPage(IndexLabel indexLabel,
ConditionQuery query) {
return new IdHolder(query, () -> {
return new IdHolder(query, (q) -> {
LockUtil.Locks locks = new LockUtil.Locks(this.graph().name());
try {
locks.lockReads(LockUtil.INDEX_LABEL_DELETE, indexLabel.id());
locks.lockReads(LockUtil.INDEX_LABEL_REBUILD, indexLabel.id());

Set<Id> ids = InsertionOrderUtil.newSet();
Iterator<BackendEntry> entries = super.query(query);
Iterator<BackendEntry> entries = super.query(q);
while (entries.hasNext()) {
HugeIndex index = this.serializer.readIndex(graph(), query,
HugeIndex index = this.serializer.readIndex(graph(), q,
entries.next());
ids.addAll(index.elementIds());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3458,7 +3458,7 @@ public void testQueryBySingleLabelInPage() {
@Test
public void testQueryByMultiLabelInPage() {
Assume.assumeTrue("Not support paging",
storeFeatures().supportsQueryByPage());
storeFeatures().supportsQueryByPage());

HugeGraph graph = graph();
GraphTraversalSource g = graph.traversal();
Expand Down

0 comments on commit a565f26

Please sign in to comment.