You can do that at the application level. Nothing wrong with that. You could use that approach of storing keys in a separate Set or something. But if you want to prevent the key set from being modified during iteration, that implies all writers have to acquire locks when writing to the map, and locks can be expensive (though maybe not so much in HA systems like Hazelcast).
Maybe it would be cool to add a `forEach(...)` like operation to asynchronous Sets and support keySet for maps. It would probably require iterating the Hazelcast key set (which requests keys in batches) in a background thread. I think the other cluster managers should be able to support this, but handling consistency issues for iteration might still have to be left to the application. I don't think we want to require expensive locking just to get a little consistency when iterating keys which should be a rare operation.
Also, you mentioned "snapshotting" maps. This is sort of how a lot of databases work - snapshot isolation. Basically, the idea would be that once a process starts iterating over the keys in a map, those keys and their values will not change, but other processes can still update keys. Updates from other processes aren't seen by the process iterating the keys since it's operating on a snapshot. That's an awesome idea but may not be practical for some cluster managers. Also, using snapshot isolation in an asynchronous framework could result in some odd behavior if, for instance, the process updates a key while iterating the snapshot. Synchronous Iterators have the benefit of context which is a bit more difficult to manage in an asynchronous environment. I think things like snapshots just have to be left to the details of specific cluster managers.
Jordan Halterman