Skip to content

Commit

Permalink
Handle error on query for HD path correctly (#18084)
Browse files Browse the repository at this point in the history
HDQuery was not handling thrown Errors correctly.
The Error is not catched and therefore not delegated back to the
caller. A caller in that case hangs indefinetely.

fixes #18052

(cherry picked from commit 882cd5c)
  • Loading branch information
sancar committed Jan 28, 2021
1 parent 5c9d0b5 commit 8896690
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void run() {
Result result
= queryRunner.runPartitionIndexOrPartitionScanQueryOnGivenOwnedPartition(query, partitionId);
future.addResult(partitionId, result);
} catch (Exception ex) {
} catch (Throwable ex) {
future.completeExceptionally(ex);
}
}
Expand All @@ -285,7 +285,7 @@ public void accept(AtomicReferenceArray<Result> response, Throwable throwable) {
Result combinedResult = queryRunner.populateEmptyResult(query, Collections.emptyList());
populateResult(response, combinedResult);
QueryOperation.this.sendResponse(combinedResult);
} catch (Exception e) {
} catch (Throwable e) {
QueryOperation.this.sendResponse(e);
throw rethrow(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2008-2020, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hazelcast.map.impl.query;

import com.hazelcast.query.Predicate;

import java.io.Serializable;
import java.util.Map;

public class ErrorThrowingPredicate implements Predicate, Serializable {
@Override
public boolean apply(Map.Entry mapEntry) {
throw new NoClassDefFoundError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.hazelcast.config.IndexConfig;
import com.hazelcast.config.IndexType;
import com.hazelcast.config.MapStoreConfig;
import com.hazelcast.core.HazelcastException;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.internal.util.RootCauseMatcher;
import com.hazelcast.map.IMap;
import com.hazelcast.map.MapStoreAdapter;
import com.hazelcast.map.listener.EntryExpiredListener;
Expand All @@ -37,8 +39,10 @@
import com.hazelcast.test.TestHazelcastInstanceFactory;
import com.hazelcast.test.annotation.ParallelJVMTest;
import com.hazelcast.test.annotation.QuickTest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;

import java.io.IOException;
Expand All @@ -59,6 +63,9 @@
@Category({QuickTest.class, ParallelJVMTest.class})
public class QueryAdvancedTest extends HazelcastTestSupport {

@Rule
public ExpectedException expected = ExpectedException.none();

@Override
protected Config getConfig() {
return smallInstanceConfig();
Expand Down Expand Up @@ -114,7 +121,7 @@ public void testQueryWithTTL() {

String mapName = "default";
config.getMapConfig(mapName)
.setTimeToLiveSeconds(3);
.setTimeToLiveSeconds(3);

HazelcastInstance instance = createHazelcastInstance(config);

Expand Down Expand Up @@ -520,8 +527,8 @@ public void testUnknownPortableField_notCausesQueryException_withIndex() {
Config config = getConfig();
config.getSerializationConfig().addPortableFactory(666, classId -> new PortableEmployee());
config.getMapConfig(mapName)
.addIndexConfig(new IndexConfig(IndexType.HASH, "notExist"))
.addIndexConfig(new IndexConfig(IndexType.HASH, "n"));
.addIndexConfig(new IndexConfig(IndexType.HASH, "notExist"))
.addIndexConfig(new IndexConfig(IndexType.HASH, "n"));

HazelcastInstance hazelcastInstance = createHazelcastInstance(config);

Expand All @@ -533,4 +540,20 @@ public void testUnknownPortableField_notCausesQueryException_withIndex() {
Collection values = map.values(Predicates.sql("n = name_2 OR notExist = name_0"));
assertEquals(1, values.size());
}

@Test
public void testClassNotFoundErrorDelegatedToCallerOnQuery() {
Config config = getConfig();
HazelcastInstance hazelcastInstance = createHazelcastInstance(config);

IMap<Integer, Integer> map = hazelcastInstance.getMap("map");

map.put(1, 1);
//A remote predicate can throw Error in case of Usercodeployment and missing sub classes
//See the issue for actual problem https://github.com/hazelcast/hazelcast/issues/18052
//We are throwing error to see if the error is delegated to the caller
expected.expect(HazelcastException.class);
expected.expectCause(new RootCauseMatcher(NoClassDefFoundError.class));
map.values(new ErrorThrowingPredicate());
}
}

0 comments on commit 8896690

Please sign in to comment.