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

ISPN-5729 Remote query - org/apache/lucene/uninverting/UninvertingRea… #4758

Merged
merged 4 commits into from Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,7 +1,5 @@
package org.infinispan.client.hotrod;

import java.util.Properties;

import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.commons.api.BasicCacheContainer;
import org.infinispan.commons.marshall.Marshaller;
Expand Down
Expand Up @@ -28,7 +28,7 @@ public class AuthenticationConfigurationBuilder extends AbstractSecurityConfigur
private CallbackHandler callbackHandler;
private boolean enabled = false;
private String serverName;
private Map<String, String> saslProperties = new HashMap<String, String>();
private Map<String, String> saslProperties = new HashMap<>();
private String saslMechanism;
private Subject clientSubject;

Expand Down
Expand Up @@ -117,7 +117,7 @@ private static final class ClientEntryListener<K, C> {
@ClientCacheEntryExpired
public void handleEvent(ClientCacheEntryCustomEvent<byte[]> event) throws IOException {
byte[] eventData = event.getEventData();
ContinuousQueryResult cqr = (ContinuousQueryResult) ProtobufUtil.fromWrappedByteArray(serializationContext, eventData);
ContinuousQueryResult cqr = ProtobufUtil.fromWrappedByteArray(serializationContext, eventData);
Object key = ProtobufUtil.fromWrappedByteArray(serializationContext, cqr.getKey());
Object value = cqr.getValue() != null ? ProtobufUtil.fromWrappedByteArray(serializationContext, cqr.getValue()) : cqr.getProjection();

Expand Down
Expand Up @@ -4,8 +4,6 @@
import static org.infinispan.client.hotrod.filter.Filters.makeFactoryParams;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -39,15 +37,13 @@
import org.infinispan.client.hotrod.impl.operations.ExecuteOperation;
import org.infinispan.client.hotrod.impl.operations.GetAllParallelOperation;
import org.infinispan.client.hotrod.impl.operations.GetOperation;
import org.infinispan.client.hotrod.impl.operations.GetStreamOperation;
import org.infinispan.client.hotrod.impl.operations.GetWithMetadataOperation;
import org.infinispan.client.hotrod.impl.operations.GetWithVersionOperation;
import org.infinispan.client.hotrod.impl.operations.OperationsFactory;
import org.infinispan.client.hotrod.impl.operations.PingOperation;
import org.infinispan.client.hotrod.impl.operations.PutAllParallelOperation;
import org.infinispan.client.hotrod.impl.operations.PutIfAbsentOperation;
import org.infinispan.client.hotrod.impl.operations.PutOperation;
import org.infinispan.client.hotrod.impl.operations.PutStreamOperation;
import org.infinispan.client.hotrod.impl.operations.RemoveClientListenerOperation;
import org.infinispan.client.hotrod.impl.operations.RemoveIfUnmodifiedOperation;
import org.infinispan.client.hotrod.impl.operations.RemoveOperation;
Expand Down
Expand Up @@ -2,7 +2,6 @@

import java.util.Properties;

import org.infinispan.client.hotrod.configuration.ClientIntelligence;
import org.infinispan.client.hotrod.logging.Log;
import org.infinispan.client.hotrod.logging.LogFactory;
import org.infinispan.commons.util.StringPropertyReplacer;
Expand Down
@@ -1,6 +1,5 @@
package org.infinispan.client.hotrod.impl.transport.tcp;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.Collection;
Expand Down
Expand Up @@ -18,7 +18,6 @@
import org.infinispan.client.hotrod.event.EventLogListener;
import org.infinispan.client.hotrod.exceptions.HotRodClientException;
import org.infinispan.client.hotrod.test.MultiHotRodServersTest;
import org.infinispan.commons.equivalence.AnyServerEquivalence;
import org.infinispan.commons.marshall.jboss.GenericJBossMarshaller;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.ConfigurationBuilder;
Expand Down
Expand Up @@ -6,7 +6,6 @@
import java.util.concurrent.TimeUnit;

import org.infinispan.client.hotrod.test.MultiHotRodServersTest;
import org.infinispan.commons.equivalence.AnyServerEquivalence;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.testng.annotations.Test;
Expand Down
Expand Up @@ -14,7 +14,6 @@

import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.exceptions.HotRodClientException;
import org.infinispan.commons.equivalence.AnyServerEquivalence;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.global.GlobalAuthorizationConfigurationBuilder;
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
Expand Down
Expand Up @@ -311,7 +311,7 @@ public ClientEntryListener(SerializationContext serializationContext) {
@ClientCacheEntryCreated
public void handleClientCacheEntryCreatedEvent(ClientCacheEntryCustomEvent event) throws IOException {
byte[] eventData = (byte[]) event.getEventData();
FilterResult r = (FilterResult) ProtobufUtil.fromWrappedByteArray(serializationContext, eventData);
FilterResult r = ProtobufUtil.fromWrappedByteArray(serializationContext, eventData);
createEvents.add(r);

log.debugf("handleClientCacheEntryCreatedEvent instance=%s projection=%s sortProjection=%s\n",
Expand All @@ -323,7 +323,7 @@ public void handleClientCacheEntryCreatedEvent(ClientCacheEntryCustomEvent event
@ClientCacheEntryModified
public void handleClientCacheEntryModifiedEvent(ClientCacheEntryCustomEvent event) throws IOException {
byte[] eventData = (byte[]) event.getEventData();
FilterResult r = (FilterResult) ProtobufUtil.fromWrappedByteArray(serializationContext, eventData);
FilterResult r = ProtobufUtil.fromWrappedByteArray(serializationContext, eventData);
modifyEvents.add(r);

log.debugf("handleClientCacheEntryModifiedEvent instance=%s projection=%s sortProjection=%s\n",
Expand Down
Expand Up @@ -327,7 +327,7 @@ public ClientEntryListener(SerializationContext serializationContext) {

@ClientCacheEntryCreated
public void handleClientCacheEntryCreatedEvent(ClientCacheEntryCustomEvent event) throws IOException {
FilterResult r = (FilterResult) ProtobufUtil.fromWrappedByteArray(serializationContext, (byte[]) event.getEventData());
FilterResult r = ProtobufUtil.fromWrappedByteArray(serializationContext, (byte[]) event.getEventData());
createEvents.add(r);

log.debugf("handleClientCacheEntryCreatedEvent instance=%s projection=%s sortProjection=%s\n",
Expand All @@ -338,7 +338,7 @@ public void handleClientCacheEntryCreatedEvent(ClientCacheEntryCustomEvent event

@ClientCacheEntryModified
public void handleClientCacheEntryModifiedEvent(ClientCacheEntryCustomEvent event) throws IOException {
FilterResult r = (FilterResult) ProtobufUtil.fromWrappedByteArray(serializationContext, (byte[]) event.getEventData());
FilterResult r = ProtobufUtil.fromWrappedByteArray(serializationContext, (byte[]) event.getEventData());
modifyEvents.add(r);

log.debugf("handleClientCacheEntryModifiedEvent instance=%s projection=%s sortProjection=%s\n",
Expand Down
Expand Up @@ -31,13 +31,13 @@ public Class<UserPB> getJavaClass() {
@Override
public UserPB readFrom(ProtoStreamReader reader) throws IOException {
int id = reader.readInt("id");
Set<Integer> accountIds = reader.readCollection("accountIds", new HashSet<Integer>(), Integer.class);
Set<Integer> accountIds = reader.readCollection("accountIds", new HashSet<>(), Integer.class);

// Read them out of order. It still works but logs a warning!
String surname = reader.readString("surname");
String name = reader.readString("name");

List<Address> addresses = reader.readCollection("addresses", new ArrayList<Address>(), AddressPB.class);
List<Address> addresses = reader.readCollection("addresses", new ArrayList<>(), AddressPB.class);

Integer age = reader.readInt("age");
User.Gender gender = reader.readObject("gender", User.Gender.class);
Expand Down
Expand Up @@ -23,4 +23,3 @@ timeBetweenEvictionRunsMillis=120000
minEvictableIdleTimeMillis=300000
testWhileIdle = true
minIdle = 1

Expand Up @@ -68,4 +68,35 @@ public void testRemoteQuery() throws Exception {

rcm.stop();
}

/**
* Sorting on a field that does not contain DocValues so Hibernate Search is forced to uninvert it.
* @see <a href="https://issues.jboss.org/browse/ISPN-5729">https://issues.jboss.org/browse/ISPN-5729</a>
*/
@Test
public void testUninverting() throws Exception {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's maybe not trivial to figure out what this test is doing, maybe put a comment like "Using a sort on a field that does not contain DocValues so Lucene is forced to uninvert it" to the posterity?

RemoteCacheManager rcm = createCacheManager();

SerializationContext serializationContext = ProtoStreamMarshaller.getSerializationContext(rcm);
ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
String protoFile = protoSchemaBuilder.fileName("test.proto")
.addClass(Person.class)
.build(serializationContext);

RemoteCache<String, String> metadataCache = rcm.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
metadataCache.put("test.proto", protoFile);
assertFalse(metadataCache.containsKey(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX));

RemoteCache<String, Person> cache = rcm.getCache();
cache.clear();

QueryFactory qf = Search.getQueryFactory(cache);
Query query = qf.from(Person.class)
.having("name").eq("John")
.orderBy("id")
.build();
assertEquals(0, query.list().size());

rcm.stop();
}
}
Expand Up @@ -7,10 +7,18 @@ public class Person {
@ProtoField(number = 1)
public String name;

@ProtoField(number = 2)
public Integer id;

public Person(String name) {
this.name = name;
}

public Person(String name, Integer id) {
this.name = name;
this.id = id;
}

public Person() {
}
}
Expand Up @@ -19,9 +19,9 @@ public Person readFrom(ProtoStreamReader reader) throws IOException {
person.setName(reader.readString("name"));
person.setSurname(reader.readString("surname"));
person.setAddress(reader.readObject("address", Address.class));
person.setPhoneNumbers(reader.readCollection("phoneNumbers", new ArrayList<PhoneNumber>(), PhoneNumber.class));
person.setPhoneNumbers(reader.readCollection("phoneNumbers", new ArrayList<>(), PhoneNumber.class));
person.setAge(reader.readInt("age"));
person.setFavouriteNumbers(reader.readCollection("favouriteNumbers", new ArrayList<Integer>(), Integer.class));
person.setFavouriteNumbers(reader.readCollection("favouriteNumbers", new ArrayList<>(), Integer.class));
person.setLicense(reader.readString("license"));
person.setGender(reader.readObject("gender", Person.Gender.class));
person.setLastUpdate(new Date(reader.readLong("lastUpdate")));
Expand Down
Expand Up @@ -10,8 +10,8 @@ public interface ContinuousQueryListener<K, V> {

/**
* Receives notification that a cache entry has joined the matching set. This is invoked initially when receiving the
* existing entries then match the query and later whenever a previously non-matching entry is updated and starts to
* match.
* existing entries that match the query and subsequently whenever a previously non-matching entry is updated and
* starts to match.
*
* @param key the key of the joining entry
* @param value the joining entry or the Object[] projection if a projection was specified
Expand All @@ -21,7 +21,7 @@ default void resultJoining(K key, V value) {

/**
* Receives notification that a cache entry from the matching set was updated and continues to match the query. The
* modified attributes are not necessarily part of the query.
* modified attributes causing this update are not necessarily part of the query.
*
* @param key the key of the joining entry
* @param value the joining entry or the Object[] projection if specified
Expand Down
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.lucene.store.LockObtainFailedException;
import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.exception.ErrorContext;
import org.hibernate.search.exception.ErrorHandler;
Expand All @@ -13,7 +12,7 @@
import org.infinispan.util.logging.LogFactory;

/**
* Unveils {@link LockObtainFailedException} from the Hibernate Search backend and presents it
* Unveils {@link org.apache.lucene.store.LockObtainFailedException} from the Hibernate Search backend and presents it
*
* @since 9.0
*/
Expand Down
Expand Up @@ -7,10 +7,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;

import javax.transaction.InvalidTransactionException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;

import org.infinispan.AdvancedCache;
import org.infinispan.Cache;
Expand Down
Expand Up @@ -10,7 +10,6 @@

import org.infinispan.Cache;
import org.infinispan.commons.marshall.AbstractExternalizer;
import org.infinispan.commons.marshall.WrappedByteArray;
import org.infinispan.compat.TypeConverter;
import org.infinispan.container.entries.CacheEntry;
import org.infinispan.context.Flag;
Expand Down
Expand Up @@ -14,7 +14,6 @@
import org.infinispan.commands.remote.BaseRpcCommand;
import org.infinispan.commons.CacheException;
import org.infinispan.commons.marshall.MarshallUtil;
import org.infinispan.context.InvocationContext;
import org.infinispan.query.Search;
import org.infinispan.query.SearchManager;
import org.infinispan.query.backend.KeyTransformationHandler;
Expand Down Expand Up @@ -77,7 +76,7 @@ public boolean isReturnValueExpected() {
}

/**
* This is invoked only on the receiving node, before {@link #perform(InvocationContext)}
* This is invoked only on the receiving node, before {@link #perform(org.infinispan.context.InvocationContext)}.
*/
@Override
public void fetchExecutionContext(CommandInitializer ci) {
Expand Down
Expand Up @@ -221,7 +221,7 @@ protected void populateCache() throws Exception {
getCacheForWrite().put("transaction_" + transaction.getId(), transaction);
}

// this value should be ignored gracefully
// this value should be ignored gracefully for indexing and querying because primitives are not currently supported
getCacheForWrite().put("dummy", "a primitive value cannot be queried");

getCacheForWrite().put("notIndexed1", new NotIndexed("testing 123"));
Expand Down
Expand Up @@ -7,15 +7,13 @@
import org.hibernate.search.bridge.builtin.impl.NullEncodingTwoWayFieldBridge;
import org.hibernate.search.bridge.util.impl.ToStringNullMarker;
import org.hibernate.search.bridge.util.impl.TwoWayString2FieldBridgeAdaptor;
import org.hibernate.search.engine.nulls.codec.impl.LuceneLongNullMarkerCodec;
import org.hibernate.search.engine.nulls.codec.impl.LuceneStringNullMarkerCodec;
import org.infinispan.commons.logging.LogFactory;
import org.infinispan.protostream.descriptors.Descriptor;
import org.infinispan.protostream.descriptors.FieldDescriptor;
import org.infinispan.query.dsl.embedded.impl.LuceneQueryMaker;
import org.infinispan.query.remote.impl.indexing.IndexingMetadata;
import org.infinispan.query.remote.impl.logging.Log;
import org.infinispan.server.core.QueryFacade;

/**
* @author anistor@redhat.com
Expand Down
Expand Up @@ -68,7 +68,7 @@ public void testIndexingWithWrapper() throws Exception {
List<ProtobufValueWrapper> list = sm.<ProtobufValueWrapper>getQuery(luceneQuery).list();
assertEquals(1, list.size());
ProtobufValueWrapper pvw = list.get(0);
User unwrapped = (User) ProtobufUtil.fromWrappedByteArray(ProtobufMetadataManagerImpl.getSerializationContextInternal(cacheManager), pvw.getBinary());
User unwrapped = ProtobufUtil.fromWrappedByteArray(ProtobufMetadataManagerImpl.getSerializationContextInternal(cacheManager), pvw.getBinary());
assertEquals("Adrian", unwrapped.getName());

// an alternative approach ...
Expand Down
Expand Up @@ -8,6 +8,7 @@
<module name="javax.transaction.api" />
<module name="org.hibernate.commons-annotations" />
<module name="org.apache.lucene" export="true" />
<module name="org.apache.lucene.internal" />
<module name="org.jboss.logging" />
<module name="org.infinispan.hibernate-search.directory-provider" services="import"/>
<module name="org.hibernate.search.elasticsearch" services="import"/>
Expand Down
Expand Up @@ -70,7 +70,7 @@ public void testEventFilter() throws Exception {
user1.setSurname("Doe");
user1.setGender(User.Gender.MALE);
user1.setAge(22);
user1.setAccountIds(new HashSet<Integer>(Arrays.asList(1, 2)));
user1.setAccountIds(new HashSet<>(Arrays.asList(1, 2)));
user1.setNotes("Lorem ipsum dolor sit amet");

Address address1 = new Address();
Expand Down Expand Up @@ -100,7 +100,7 @@ public void testEventFilter() throws Exception {
user3.setSurname("Woman");
user3.setGender(User.Gender.FEMALE);
user3.setAge(31);
user3.setAccountIds(Collections.<Integer>emptySet());
user3.setAccountIds(Collections.emptySet());

remoteCache.put(user1.getId(), user1);
remoteCache.put(user2.getId(), user2);
Expand Down Expand Up @@ -156,9 +156,9 @@ public static class ClientEntryListener {

private final Log log = LogFactory.getLog(getClass());

public final BlockingQueue<FilterResult> createEvents = new LinkedBlockingQueue<FilterResult>();
public final BlockingQueue<FilterResult> createEvents = new LinkedBlockingQueue<>();

public final BlockingQueue<FilterResult> modifyEvents = new LinkedBlockingQueue<FilterResult>();
public final BlockingQueue<FilterResult> modifyEvents = new LinkedBlockingQueue<>();

private final SerializationContext serializationContext;

Expand All @@ -168,7 +168,7 @@ public ClientEntryListener(SerializationContext serializationContext) {

@ClientCacheEntryCreated
public void handleClientCacheEntryCreatedEvent(ClientCacheEntryCustomEvent event) throws IOException {
FilterResult r = (FilterResult) ProtobufUtil.fromWrappedByteArray(serializationContext, (byte[]) event.getEventData());
FilterResult r = ProtobufUtil.fromWrappedByteArray(serializationContext, (byte[]) event.getEventData());
createEvents.add(r);

log.debugf("handleClientCacheEntryCreatedEvent instance=%s projection=%s sortProjection=%s\n",
Expand All @@ -179,7 +179,7 @@ public void handleClientCacheEntryCreatedEvent(ClientCacheEntryCustomEvent event

@ClientCacheEntryModified
public void handleClientCacheEntryModifiedEvent(ClientCacheEntryCustomEvent event) throws IOException {
FilterResult r = (FilterResult) ProtobufUtil.fromWrappedByteArray(serializationContext, (byte[]) event.getEventData());
FilterResult r = ProtobufUtil.fromWrappedByteArray(serializationContext, (byte[]) event.getEventData());
modifyEvents.add(r);

log.debugf("handleClientCacheEntryModifiedEvent instance=%s projection=%s sortProjection=%s\n",
Expand Down