Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-2526

get() from a REPLICATED cache for a non-existing key on a non-primary node causes a get() to the primary node

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 1.5.0.final
    • 1.6
    • cache
    • None

    Description

      import org.apache.ignite.Ignite;
      import org.apache.ignite.IgniteCache;
      import org.apache.ignite.Ignition;
      import org.apache.ignite.cache.CacheMode;
      import org.apache.ignite.cache.affinity.Affinity;
      import org.apache.ignite.configuration.CacheConfiguration;
      import org.apache.ignite.configuration.IgniteConfiguration;
      import org.apache.ignite.lang.IgniteUuid;
      
      public class Main {
          private static CacheConfiguration<Object, Object> CACHE_CONFIG = new CacheConfiguration<>()
                  .setName("test")
                  .setCacheMode(CacheMode.REPLICATED);
          static {
              CACHE_CONFIG.setStatisticsEnabled(true);
          }
      
          private static Object getKeyInNode(Ignite ignite) {
              Affinity<Object> affinity = ignite.affinity(CACHE_CONFIG.getName());
      
              IgniteUuid uuid = IgniteUuid.randomUuid();
              while (!affinity.isPrimary(ignite.cluster().localNode(), uuid)) {
                  uuid = IgniteUuid.randomUuid();
              }
      
              return uuid;
          }
      
          public static void main(String[] args) throws InterruptedException {
              Ignite ignite1 = Ignition.start(new IgniteConfiguration().setGridName("1"));
              Ignite ignite2 = Ignition.start(new IgniteConfiguration().setGridName("2"));
              Ignite ignite3 = Ignition.start(new IgniteConfiguration().setGridName("3"));
      
              IgniteCache<Object, Object> cache1 = ignite1.getOrCreateCache(CACHE_CONFIG);
              IgniteCache<Object, Object> cache2 = ignite2.getOrCreateCache(CACHE_CONFIG);
              IgniteCache<Object, Object> cache3 = ignite3.getOrCreateCache(CACHE_CONFIG);
      
              Thread.sleep(3_000);
      
              Object cache2Key = getKeyInNode(ignite2);
      
              System.out.printf("initial:  cache1gets:%d cache2gets:%d cache3gets:%d\n",
                      cache1.metrics().getCacheGets(), cache2.metrics().getCacheGets(), cache3.metrics().getCacheGets());
      
              cache1.get(cache2Key);
              cache3.get(cache2Key);
      
              System.out.printf("status:   cache1gets:%d cache2gets:%d cache3gets:%d\n",
                      cache1.metrics().getCacheGets(), cache2.metrics().getCacheGets(), cache3.metrics().getCacheGets());
              System.out.printf("expected: cache1gets:1 cache2gets:0 cache3gets:1\n");
      
              Ignition.stopAll(false);
          }
      }
      

      Output:

      initial:  cache1gets:0 cache2gets:0 cache3gets:0
      status:   cache1gets:0 cache2gets:2 cache3gets:0
      expected: cache1gets:1 cache2gets:0 cache3gets:1
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              noliran Noam Liran
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: