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

Map index entries are not deleted on migration #308

Closed
rjanz opened this issue Oct 14, 2012 · 2 comments

Comments

Projects
None yet
2 participants
@rjanz
Copy link

commented Oct 14, 2012

when using SQLPredicate in the localKeySet method we noticed, that we get the same key on different nodes.

The problem seems to be, that keys that are migrated to different nodes remain in the index, although they are deleted from the local map on the source node (localKeySet without arguments is correct).

It happens on 2.1, 2.3 and 2.3.1 the only difference is, that 2.3.1 has a faster migration.

I have created a test case for that problem.

@rjanz

This comment has been minimized.

Copy link
Author

commented Oct 14, 2012

The test case starts up 3 instances does a localKeySet with predicate on all instances, then starts
a new instance to force migrations. After the first migration, the number of local keys returned with and without predicate will diverge, as there are duplicates

import java.io.Serializable; 
import java.util.Collections; 
import java.util.Set; 
import java.util.TreeSet; 

import org.junit.After; 
import org.junit.AfterClass; 
import org.junit.Before; 
import org.junit.Test; 

import com.hazelcast.config.Config; 
import com.hazelcast.config.MapConfig; 
import com.hazelcast.config.MapIndexConfig; 
import com.hazelcast.core.Hazelcast; 
import com.hazelcast.core.HazelcastInstance; 
import com.hazelcast.core.IMap; 
import com.hazelcast.query.SqlPredicate; 

public class IndexMigrationTest { 
    static final int INSTANCE_COUNT = 4; 
    static final int DELAY_INSTANCES = 1; 
    static HazelcastInstance[] instances = new HazelcastInstance[INSTANCE_COUNT]; 

public static class TestIndexBean implements Serializable { 
    private static final long serialVersionUID = 1; 

    public int index = 10;       
} 

    @Test 
    public void testIndexDuringMigration() throws Exception { 
        final Config config = new Config(); 
        final MapConfig mapConfig = new MapConfig(); 
        String mapName = "testIndex"; 
        mapConfig.setName(mapName); 
        MapIndexConfig mapIndexConfig = new MapIndexConfig(); 
        mapIndexConfig.setAttribute("index"); 
        mapConfig.addMapIndexConfig(mapIndexConfig); 
        //mapConfig.setReadBackupData(true); 
        config.setMapConfigs(Collections.singletonMap(mapConfig.getName(), mapConfig)); 
        for (int i = 0; i < INSTANCE_COUNT - DELAY_INSTANCES; i++) { 
            instances[i] = Hazelcast.newHazelcastInstance(config); 
        } 
        HazelcastInstance hi0 = instances[0]; 
        IMap<String, TestIndexBean> map = hi0.getMap(mapName); 
        int total = 100; 
        // FILLUP 
        for (int i = 0; i < total; i++) { 
            TestIndexBean tIB = new TestIndexBean(); 
            String oKey = "TEST" + i; 
            map.put(oKey, tIB); 
        } 
        for (int l = 0; l < 10000; l++) { 
            int count = 0; 

            if (l == 3 && DELAY_INSTANCES == 1) { 
                instances[INSTANCE_COUNT - 1] = Hazelcast.newHazelcastInstance(config); 
            } 
            for (int i = 0; i < INSTANCE_COUNT; i++) { 
                if (instances[i] != null) { 
                    Set<Object> set = new TreeSet<Object>(); 
                    IMap<Object, Object> testMap = instances[i].getMap(mapName); 
                    // all beans are matched through this predicate 
                    set.addAll(testMap.localKeySet(new SqlPredicate("index=10"))); 
                    count += set.size(); 
                    // The value with predicate
                    System.out.print(set.size()); 
                    System.out.print(":"); 
                    // local keyset without constraint (the real value, local stats show the same value) 
                    System.out.print(testMap.localKeySet().size()); 
                    System.out.print("  "); 
                } 
            } 
            System.out.println(); 
            if (count != total) { 
                System.out.println("Unexpected count " + count); 
            } 
            // asserting is not easy, temporarily the counts might be different due to ongoing migration 
            //Assert.assertEquals("localKeySet and localKeySet with Predicate must match ",total, count); 
            Thread.sleep(10); 
        } 

    } 


    @AfterClass 
    public static void tearDownAfterClass() throws Exception { 
        for (int i = 0; i < INSTANCE_COUNT; i++) { 
            if (instances[i] != null) 
                instances[i].getLifecycleService().shutdown(); 
        } 
    } 
} 
@mdogan

This comment has been minimized.

Copy link
Member

commented Dec 11, 2012

Merged into issue #359.

@mdogan mdogan closed this Dec 11, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.