To reproduce
- start standalone server
- run test, it should work fine.
- run test with changed filter code, it will return same results.


On Wed, Apr 5, 2017 at 11:40 AM, Valentin Kulichenko <
valentin.kuliche...@gmail.com> wrote:

> Can you provide the test?
>
> -Val
>
> On Wed, Apr 5, 2017 at 1:37 AM, Andrey Mashenkov <
> andrey.mashen...@gmail.com
> > wrote:
>
> > Hi Val,
> >
> > I run test with no filter class in server classpath. I've got an error
> > wiith peerClassLoading disabled, which is ok as server can't unmarshal
> > filter object.
> > But with peerClassLoading enabled, query works fine but looks like filter
> > class won't be updated on server.
> >
> > On Wed, Apr 5, 2017 at 11:14 AM, Valentin Kulichenko <
> > valentin.kuliche...@gmail.com> wrote:
> >
> > > Andrey,
> > >
> > > Marshaller cache does not store classes, only class names. So I'm not
> > sure
> > > what you mean by this.
> > >
> > > I looked at the code and it seems I was wrong - peer class loading does
> > > work for scan query filter, which is good. But as I mentioned before,
> if
> > > the class is available on local classpath, it will never be dynamically
> > > loaded, even if peer class loading is enabled. Therefore server will
> not
> > > know about any changes happening to the class definition on the client.
> > > This is correct behavior.
> > >
> > > -Val
> > >
> > > On Wed, Apr 5, 2017 at 12:01 AM, Andrey Mashenkov <
> > > andrey.mashen...@gmail.com> wrote:
> > >
> > > > Hi Val,
> > > >
> > > > Filter object serialized and send inside GridCacheQueryRequest, and
> > then
> > > it
> > > > is deserialized on server side and loaded by cache class loader.
> > > > Looks like filter class is cached in marshaller cache.
> > > >
> > > >
> > > > On Tue, Apr 4, 2017 at 4:43 PM, Valentin Kulichenko <
> > > > valentin.kuliche...@gmail.com> wrote:
> > > >
> > > > > Andrey,
> > > > >
> > > > > To my knowledge, peer class loading is not supported for scan query
> > > > > filters, but I'm not sure though. Can you please check?
> > > > >
> > > > > Note that this actually doesn't matter if the class is available on
> > > > > server's local classpath. In this case it will be always used
> > > regardless
> > > > of
> > > > > any changes done on a client (i.e. will never be dynamically
> loaded).
> > > > This
> > > > > is true for any functionality, including Compute Grid.
> > > > >
> > > > > -Val
> > > > >
> > > > > On Mon, Apr 3, 2017 at 10:19 AM, Andrey Mashenkov <
> > > > > andrey.mashen...@gmail.com> wrote:
> > > > >
> > > > > > Crossposted to dev:
> > > > > >
> > > > > > Guys,
> > > > > >
> > > > > > ScanQuery filter code (see IgniteBiPredicate implementation
> below)
> > > can
> > > > be
> > > > > > cached on server side
> > > > > > that can cause unexpected results.
> > > > > > The main point here is server node never restarts while client
> does
> > > it
> > > > > with
> > > > > > filter code changed.
> > > > > >
> > > > > > Is it ok?
> > > > > >
> > > > > > I try to add *serialVersionUID* and it was useless. The only
> class
> > > > > renaming
> > > > > > was helpful.
> > > > > >
> > > > > >
> > > > > > ---------- Forwarded message ----------
> > > > > > From: David Li <david.li...@gmail.com>
> > > > > > Date: Mon, Apr 3, 2017 at 9:24 AM
> > > > > > Subject: Re: ScanQuery With BinaryObject
> > > > > > To: u...@ignite.apache.org
> > > > > >
> > > > > >
> > > > > > Sorry, please ignore the previous email, it was sent by mistake.
> > > > > >
> > > > > > 1. I download apache-ignite-fabric-1.9.0-bin.zip, and unzip it.
> > > > > > 2. In terminal, I start an ignite instance by *bin/ignite.sh
> > > > > > examples/config/example-ignite.xml*
> > > > > > 3. I create a Java application, source code as below:
> > > > > >
> > > > > > public static void main(String[] args) {
> > > > > >     String ORG_CACHE = "org_cache_remote";
> > > > > >    * Ignition.setClientMode(true);*
> > > > > >     Ignite ignite = Ignition.start("example-ignite.xml");
> > > > > >     CacheConfiguration<Long, Organization> orgCacheCfg = new
> > > > > > CacheConfiguration<>(ORG_CACHE);
> > > > > >     orgCacheCfg.setIndexedTypes(Long.class, Organization.class);
> > > > > >     ignite.destroyCache(ORG_CACHE);
> > > > > >     IgniteCache<Long, Organization> cache = ignite.createCache(
> > > > > > orgCacheCfg);
> > > > > >     cache.put(1L, new Organization(1L, "org1", true, "jurong
> east",
> > > > > > "1111"));
> > > > > >     cache.put(2L, new Organization(2L, "org2", false, "orchard",
> > > > > "2222"));
> > > > > >     cache.put(3L, new Organization(3L, "org3", true, "jurong
> west",
> > > > > > "3333"));
> > > > > >     cache.put(4L, new Organization(4L, "org4", false,
> "woodlands",
> > > > > > "4444"));
> > > > > >     cache.put(5L, new Organization(5L, "org5", false, "changi",
> > > > "5555"));
> > > > > >     // cache.put(6L, new Organization(6L, "org6", true, "jurong
> > > > island",
> > > > > > "6666"));
> > > > > >
> > > > > >     IgniteCache<Long, BinaryObject> binaryCache =
> > > > cache.withKeepBinary();
> > > > > >
> > > > > >     List<Cache.Entry<Long, BinaryObject>> result;
> > > > > >
> > > > > >     System.out.println("Scan by address");
> > > > > >     ScanQuery<Long, BinaryObject> scanAddress = new ScanQuery<>(
> > > > > >         new IgniteBiPredicate<Long, BinaryObject>() {
> > > > > >             @Override
> > > > > >             public boolean apply(Long aLong, BinaryObject
> > > > binaryObject) {
> > > > > >                 *// first time filter by jurong, got two entries,
> > > org1
> > > > > and
> > > > > > org3*
> > > > > > *                // second time filter by changi, got two
> entries,
> > > org1
> > > > > and
> > > > > > org3*
> > > > > > *                // third time filter by changi as well,
> uncomment
> > > > org6,
> > > > > > got three entries, org1, org3 and org6*
> > > > > > *                return
> > > > > > binaryObject.<String>field("address").startsWith("jurong");*
> > > > > >             }
> > > > > >         }
> > > > > >     );
> > > > > >     result = binaryCache.query(scanAddress).getAll();
> > > > > >     System.out.println("result: " + result.size());
> > > > > >     for (Cache.Entry<Long, BinaryObject> entry : result) {
> > > > > >         System.out.println(entry.getValue().deserialize().
> > > toString());
> > > > > >     }
> > > > > >
> > > > > >     ignite.close();
> > > > > > }
> > > > > >
> > > > > > Here what I want to do is start a client node, connect to the
> > server
> > > > node
> > > > > > started in step 2. Then I create a cache, put some data inside,
> > > > > > then try to run a scan query to find entries by its address.
> > > > > > The problem is when I run this program first time, it will return
> > two
> > > > > > entries, their addresses are started with "jurong", which is
> > correct.
> > > > > > When I run the program again, with changed value, eg. "changi",
> it
> > > > should
> > > > > > return one entry, somehow, it still return two entries with
> address
> > > > > started
> > > > > > with "jurong", rather than "changi".
> > > > > > When I uncomment the line of "org6", and run the program again,
> it
> > > will
> > > > > > return three entries, all of their addresses are started with
> > > "jurong".
> > > > > >
> > > > > > I have no idea what is going on.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Best regards,
> > > > > > Andrey V. Mashenkov
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Best regards,
> > > > Andrey V. Mashenkov
> > > >
> > >
> >
> >
> >
> > --
> > Best regards,
> > Andrey V. Mashenkov
> >
>



-- 
Best regards,
Andrey V. Mashenkov
package userlist.repro;

import java.util.Collections;
import java.util.List;
import javax.cache.Cache;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.cache.query.ScanQuery;
import org.apache.ignite.cache.query.annotations.QuerySqlField;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.lang.IgniteBiPredicate;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;

/**
 *
 */
public class ScanQueryFilter {
    /** */
    public static void main(String[] args) {
        String ORG_CACHE = "org_cache_remote";

        final TcpDiscoveryVmIpFinder finder = new TcpDiscoveryVmIpFinder();
        finder.setAddresses(Collections.singletonList("127.0.0.1"));

        Ignite ignite = Ignition.start(
            new IgniteConfiguration()
                .setGridName("client")
                .setClientMode(true)
                .setPeerClassLoadingEnabled(true)
                .setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(finder)));

        CacheConfiguration<Long, Organization> orgCacheCfg = new CacheConfiguration<>(ORG_CACHE);
        orgCacheCfg.setIndexedTypes(Long.class, Organization.class);
        ignite.destroyCache(ORG_CACHE);
        IgniteCache<Long, Organization> cache = ignite.createCache(orgCacheCfg);
        cache.put(1L, new Organization(1L, "org1", true, "jurong east", "1111"));
        cache.put(2L, new Organization(2L, "org2", false, "orchard", "2222"));
        cache.put(3L, new Organization(3L, "org3", true, "jurong west", "3333"));
        cache.put(4L, new Organization(4L, "org4", false, "woodlands", "4444"));
        cache.put(5L, new Organization(5L, "org5", false, "changi", "5555"));
        // cache.put(6L, new Organization(6L, "org6", true, "jurong island", "6666"));

        IgniteCache<Long, BinaryObject> binaryCache = cache.withKeepBinary();

        List<Cache.Entry<Long, BinaryObject>> result;

        System.out.println("Scan by address");
        ScanQuery<Long, BinaryObject> scanAddress = new ScanQuery<>(
            new IgniteBiPredicate<Long, BinaryObject>() {
                @Override
                public boolean apply(Long aLong, BinaryObject binaryObject) {
                    // first time filter by jurong, got two entries, org1 and org3
                    // second time filter by changi, got two entries, org1 and org3
                    // third time filter by changi as well, uncomment org6, got three entries, org1, org3 and org6
                    return binaryObject.<String>field("address").startsWith("jurong");
                }
            }
        );
        result = binaryCache.query(scanAddress).getAll();
        System.out.println("result: " + result.size());
        for (Cache.Entry<Long, BinaryObject> entry : result) {
            System.out.println(entry.getValue().deserialize().toString());
        }

        ignite.close();
    }

    /**
     *
     */
    private static class MyObject {
        /** */
        String name;

        /** */
        public MyObject(String name) {
            this.name = name;
        }
    }

    private static class Organization {
        long id;

        @QuerySqlField(index = true)
        String address;

        public Organization(long l, String org1, boolean b, String s, String s1) {
            id = l;
            address = s;
        }

        @Override public String toString() {
            return "Organization{" +
                "id=" + id +
                ", address='" + address + '\'' +
                '}';
        }
    }
}

Reply via email to