Skip to content

Commit

Permalink
IGNITE-7823 Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
xtern committed Apr 3, 2018
1 parent cd4978b commit 6d65fc6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 52 deletions.
Expand Up @@ -748,11 +748,7 @@ private FieldsResult executeFieldsQuery(GridCacheQueryAdapter<?> qry, @Nullable
* @return Cache set items iterator.
*/
private GridCloseableIterator<IgniteBiTuple<K, V>> setIterator(GridCacheQueryAdapter<?> qry) {
final GridSetQueryPredicate filter = (GridSetQueryPredicate)qry.scanFilter();

filter.init(cctx);

IgniteUuid id = filter.setId();
IgniteUuid id = ((GridSetQueryPredicate)qry.scanFilter()).setId();

Collection<SetItemKey> data = cctx.dataStructures().setData(id);

Expand All @@ -766,12 +762,7 @@ private GridCloseableIterator<IgniteBiTuple<K, V>> setIterator(GridCacheQueryAda
return new IgniteBiTuple<>((K)e.item(), (V)Boolean.TRUE);
}
},
true,
new P1<SetItemKey>() {
@Override public boolean apply(SetItemKey e) {
return filter.apply(e, null);
}
});
true);

return new GridCloseableIteratorAdapter<IgniteBiTuple<K, V>>() {
@Override protected boolean onHasNext() {
Expand Down
Expand Up @@ -1511,7 +1511,7 @@ else if (reentrantLock != null) {
/**
* @param name Set name.
* @param cctx Set cache context.
* @param collocated Collocated flag.
* @param collocated Collocation flag.
* @throws IgniteCheckedException If failed.
*/
public void removeSet(final String name, final GridCacheContext cctx,
Expand Down
Expand Up @@ -167,7 +167,7 @@ public boolean checkHeader() throws IgniteCheckedException {
}

CacheQuery qry = new GridCacheQueryAdapter<>(ctx, SET, null, null,
new GridSetQueryPredicate<>(id, collocated), null, false, false);
new GridSetQueryPredicate<>(id), null, false, false);

Collection<ClusterNode> nodes = dataNodes(ctx.affinity().affinityTopologyVersion());

Expand Down Expand Up @@ -418,12 +418,16 @@ private GridCloseableIterator<T> closeableIterator() {
return collocated ? iteratorCollocated() : iterator0();
}

/** {@inheritDoc} */
/**
* Get iterator for collocated igniteSet.
*
* @return iterator for collocated igniteSet.
*/
@SuppressWarnings("unchecked")
private GridCloseableIterator<T> iteratorCollocated() {
try {
CacheQuery qry = new GridCacheQueryAdapter<>(ctx, SET, null, null,
new GridSetQueryPredicate<>(id, collocated), null, false, false);
new GridSetQueryPredicate<>(id), null, false, false);

Collection<ClusterNode> nodes = dataNodes(ctx.affinity().affinityTopologyVersion());

Expand Down Expand Up @@ -455,6 +459,11 @@ private GridCloseableIterator<T> iteratorCollocated() {
}
}

/**
* Get iterator for non-collocated igniteSet.
*
* @return iterator for non-collocated igniteSet.
*/
@SuppressWarnings("unchecked")
private GridCloseableIterator<T> iterator0() {
GridCacheContext ctx0 = ctx.isNear() ? ctx.near().dht().context() : ctx;
Expand Down
Expand Up @@ -39,15 +39,9 @@ public class GridSetQueryPredicate<K, V> implements IgniteBiPredicate<K, V>, Ext
/** */
private IgniteUuid setId;

/** */
private boolean collocated;

/** */
private GridCacheContext ctx;

/** */
private boolean filter;

/**
* Required by {@link Externalizable}.
*/
Expand All @@ -57,28 +51,9 @@ public GridSetQueryPredicate() {

/**
* @param setId Set ID.
* @param collocated Collocation flag.
*/
public GridSetQueryPredicate(IgniteUuid setId, boolean collocated) {
public GridSetQueryPredicate(IgniteUuid setId) {
this.setId = setId;
this.collocated = collocated;
}

/**
* @param ctx Cache context.
*/
public void init(GridCacheContext ctx) {
this.ctx = ctx;

filter = filterKeys();
}

/**
*
* @return Collocation flag.
*/
public boolean collocated() {
return collocated;
}

/**
Expand All @@ -91,27 +66,18 @@ public IgniteUuid setId() {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public boolean apply(K k, V v) {
return !filter || ctx.affinity().primaryByKey(ctx.localNode(), k, ctx.affinity().affinityTopologyVersion());
return true;
}

/**
* @return {@code True} if need to filter out non-primary keys during processing of set data query.
*/
private boolean filterKeys() {
return !collocated && !(ctx.isLocal() || ctx.isReplicated()) &&
(ctx.config().getBackups() > 0 || CU.isNearEnabled(ctx));
}

/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
U.writeGridUuid(out, setId);
out.writeBoolean(collocated);
}

/** {@inheritDoc} */
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
setId = U.readGridUuid(in);
collocated = in.readBoolean();
}

/** {@inheritDoc} */
Expand Down
Expand Up @@ -516,7 +516,7 @@ private void testIteratorClose(boolean collocated) throws Exception {
assert set0.size() == 0 : set0.size();

for (int i = 0; i < 5000; i++)
assertTrue(String.valueOf(i), set0.add(i));
assertTrue(set0.add(i));

createIterators(set0);

Expand Down

0 comments on commit 6d65fc6

Please sign in to comment.