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

Deadlock on adding an index to a map that is not empty #310

Closed
steffentemplin opened this issue Oct 17, 2012 · 2 comments

Comments

Projects
None yet
3 participants
@steffentemplin
Copy link

commented Oct 17, 2012

Consider two nodes that access the same hazelcast-Map. After creating the map an index should be added. Node one does this and starts adding objects to the map. Then node two starts up and tries to get the map and to create the index too, as it cannot be sure that this map was not already created initially by another node.

Adding an index to a map that is not empty ends up in a never returning call to map.addIndex();
This happens for me with Hazelcast 2.3.1.

Stacktrace:

    SCHWERWIEGEND: [172.16.208.1]:5701 [dev] error processing messages  processable=com.hazelcast.impl.MProxyImpl$MProxyReal$1@65d0d124
    java.lang.RuntimeException: Index can only be added before adding entries!
    Add indexes first and only once then put entries.
        at com.hazelcast.query.MapIndexService.addIndex(MapIndexService.java:132)
        at com.hazelcast.impl.CMap.addIndex(CMap.java:428)
        at com.hazelcast.impl.concurrentmap.AddMapIndex.process(AddMapIndex.java:52)
        at com.hazelcast.impl.BaseManager.sendProcessableToAll(BaseManager.java:1243)
        at com.hazelcast.impl.MProxyImpl$MProxyReal$1.process(MProxyImpl.java:523)
        at com.hazelcast.cluster.ClusterService.processProcessable(ClusterService.java:188)
        at com.hazelcast.cluster.ClusterService.dequeueProcessables(ClusterService.java:254)
        at com.hazelcast.cluster.ClusterService.run(ClusterService.java:199)
        at java.lang.Thread.run(Thread.java:662)
    17.10.2012 18:16:15 com.hazelcast.cluster.ClusterService
    SCHWERWIEGEND: [172.16.208.1]:5701 [dev] Index can only be added before adding entries!
    Add indexes first and only once then put entries.
    java.lang.RuntimeException: Index can only be added before adding entries!
    Add indexes first and only once then put entries.
        at com.hazelcast.query.MapIndexService.addIndex(MapIndexService.java:132)
        at com.hazelcast.impl.CMap.addIndex(CMap.java:428)
        at com.hazelcast.impl.concurrentmap.AddMapIndex.process(AddMapIndex.java:52)
        at com.hazelcast.impl.BaseManager.sendProcessableToAll(BaseManager.java:1243)
        at com.hazelcast.impl.MProxyImpl$MProxyReal$1.process(MProxyImpl.java:523)
        at com.hazelcast.cluster.ClusterService.processProcessable(ClusterService.java:188)
        at com.hazelcast.cluster.ClusterService.dequeueProcessables(ClusterService.java:254)
        at com.hazelcast.cluster.ClusterService.run(ClusterService.java:199)
        at java.lang.Thread.run(Thread.java:662)

This can be easily reproduced with a unit test:

@Test
public void testMapIndex() throws Exception {
    HazelcastInstance hazelcast = Hazelcast.getDefaultInstance();
    IMap<String, MapValue> testMap = hazelcast.getMap("testMapIndexTestMap");
    testMap.put("key1", new MapValue(1));

    testMap.addIndex("value", false);
}

private static final class MapValue implements Serializable {

    private final int value;

    public MapValue(int value) {
        super();
        this.value = value;            
    }

    public int getValue() {
        return value;
    }
}
@ngocdaothanh

This comment has been minimized.

Copy link

commented Mar 2, 2013

I've just had this problem with Hazelcast 2.5.

Is there a solution? Note that MongoDB has ensureIndex, not addIndex:
http://api.mongodb.org/java/current/com/mongodb/DBCollection.html#ensureIndex(com.mongodb.DBObject)

@mdogan

This comment has been minimized.

Copy link
Member

commented Apr 26, 2013

Feature of adding/rebuilding indexes to a (fully or partially) populated map won't be added to 2.x branch. This fix only resolves infinite wait on addIndex call.

Branch 3.0 already has this feature.

@ghost ghost assigned mdogan Apr 26, 2013

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.