[infinispan-dev] Questions on AtomicMap and improvement proposals

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[infinispan-dev] Questions on AtomicMap and improvement proposals

Emmanuel Bernard
In exchange for answers, I will improve at least the JavaDoc and maybe create a wiki from this info.

(note that this has nothing to do with the ongoing discussion on key-levle locks for a sister of AtomicMap)

I've tried to search the wiki but found nothing on AtomicMap (only forum posts) and I've read the AtomicMap JavaDoc but I am still a bit unsure of what's going on.

When I need to create an AtomicMap, I must use 
AtomicMap<String, Object> resultset = AtomicMapLookup.getAtomicMap(cache, "my_atomic_map_key");

Questions
Here are a few questions for you

1. How can I apply advanced flags to get or create the AtomicMap?
cache.withFlag(SKIP_CACHE_STORE,FORCE_ASYNCHRONOUS).get("my_atomic_map_key");

3. Is that legal to use other cache methods like replace on an AtomicMap value, what are the consequences?

3. When I expect a map to be present in the key, can I use cache.get("my_atomic_map_key") and still benefit from my properly proxied AtomicMap? Or am I forced to use AtomicMapLookup.getAtomicMap?

4. Using AtomicMapLookup.getAtomicMap, how can I differentiate an empty key where a new map has been created from a retrieval of an empty map stored in the key?

5. Must I use AtomicMapLookup.remove method to remove an atomic map?

6. Can I clone an AtomicMap?
For using methods like replace(), it seems one would need to clone the atomicmap to compare it to the initial value. When I tried briefly Iw as unsure I could do that.

Proposed improvements

I'm asking all the questions because these can potentially make AtomicMap users life quite hard and abstracting Infinispan from OGM will make a damn ugly interface / contract

1. Would it be possible to let people get their proxied AtomicMap from cache.get() and other get methods?
It seems that either the marshaller or the get operations (probably the get ops as local cache should work as well) should be able to intercept an AtomicMap and essentually do what AtomicMapLookup is doing (and make sure it is properly wrapped).
If that's possible that would be already a big benefit for the user as it would only be limited to AtomicMap creation or cloning

2. Would it be possible to let people create standalone AtomicMaps and associate them to the cache lasily and in a transparent fashion.
AtomicMap<String, Object> resultSet = AtomicMapLookup.createAtomicMap();
cache.put(key, resultSet); //lazily set cache, deltaMapKey, batchContainer and icc for new AtomicMaps

3. Could we guarantee some equality between Map and AtomicMap?
if I do Map 

map = new HashMap(atomicMap);
atomicMap.put("key", "value");
cache.replace(key, map, atomicMap);

Am I guaranteed that it can work (if no one has pushed a change behind my back)?

Emmanuel

_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev
Reply | Threaded
Open this post in threaded view
|

Re: [infinispan-dev] Questions on AtomicMap and improvement proposals

Manik Surtani
Apologies for the late response.

On 13 Apr 2011, at 10:38, Emmanuel Bernard wrote:

In exchange for answers, I will improve at least the JavaDoc and maybe create a wiki from this info.

Sounds like a fair exchange.  :-)

I've tried to search the wiki but found nothing on AtomicMap (only forum posts) and I've read the AtomicMap JavaDoc but I am still a bit unsure of what's going on.

When I need to create an AtomicMap, I must use 
AtomicMap<String, Object> resultset = AtomicMapLookup.getAtomicMap(cache, "my_atomic_map_key");

Well, AtomicMapLookup.getAtomicMap(cache, myAtomicMapName).

Questions
Here are a few questions for you

1. How can I apply advanced flags to get or create the AtomicMap?
cache.withFlag(SKIP_CACHE_STORE,FORCE_ASYNCHRONOUS).get("my_atomic_map_key");

You can't right now; as a "dirty hack", you can just do what getAtomicMap() does internally, adding the flags you need.


The real solution: create a feature request on JIRA so that we can add flags to getAtomicMap() as well.

3. Is that legal to use other cache methods like replace on an AtomicMap value, what are the consequences?

cache.putIfAbsent() is used internally by getAtomicMap().  replace() is harder, since it may mean that a thread may be storing stuff in an AtomicMap that has been replaced, so those changes get lost.  Why would you need to replace() an atomic map?

3. When I expect a map to be present in the key, can I use cache.get("my_atomic_map_key") and still benefit from my properly proxied AtomicMap? Or am I forced to use AtomicMapLookup.getAtomicMap?

You need to use AML.getAtomicMap() to make sure your proxy is properly created/wrapped.  See:


4. Using AtomicMapLookup.getAtomicMap, how can I differentiate an empty key where a new map has been created from a retrieval of an empty map stored in the key?

You could use getAtomicMap(cache, mapName, createIfAbsent) so you get a null if createIfAbsent == false and no such atomic map exists.  Does this help?

5. Must I use AtomicMapLookup.remove method to remove an atomic map?

You can just use cache.remove(), but for the sake of clean generics, it is better to go via AML.remove().

6. Can I clone an AtomicMap?

No, it's not cloneable, since a clone that is not stored in the cache (in a threadsafe manner) is meaningless, and Java's clone() API doesn't allow you to pass in a new name for the clone.

However, we could provide a AtomicMap.clone(nameOfClone) method, which could take care of this (internally call AML.getAtomicMap(nameOfClone) and copy contents across).

For using methods like replace(), it seems one would need to clone the atomicmap to compare it to the initial value. When I tried briefly Iw as unsure I could do that.

Yep.

Proposed improvements

I'm asking all the questions because these can potentially make AtomicMap users life quite hard and abstracting Infinispan from OGM will make a damn ugly interface / contract

1. Would it be possible to let people get their proxied AtomicMap from cache.get() and other get methods?
It seems that either the marshaller or the get operations (probably the get ops as local cache should work as well) should be able to intercept an AtomicMap and essentually do what AtomicMapLookup is doing (and make sure it is properly wrapped).
If that's possible that would be already a big benefit for the user as it would only be limited to AtomicMap creation or cloning

Fair point, certain AML code could be moved into the CacheDelegate.  But I fear a lot of instanceof checking which may be unnecessary if using the cache to store anything other than AtomicMaps.

2. Would it be possible to let people create standalone AtomicMaps and associate them to the cache lasily and in a transparent fashion.
AtomicMap<String, Object> resultSet = AtomicMapLookup.createAtomicMap();
cache.put(key, resultSet); //lazily set cache, deltaMapKey, batchContainer and icc for new AtomicMaps

The problem there is that the put() won't be atomic.  You'd need to mandate a putIfAbsent, but that means any initialization of the AtomicMap (setting values) could potentially be wasted.  This is why the AML registers the AtomicMap in the cache before allowing user code to store values.

3. Could we guarantee some equality between Map and AtomicMap?
if I do Map 

map = new HashMap(atomicMap);
atomicMap.put("key", "value");
cache.replace(key, map, atomicMap);

Am I guaranteed that it can work (if no one has pushed a change behind my back)?

Not at the moment, but this is something we could possibly do.

Hope this helps
Manik
--
Manik Surtani

Lead, Infinispan




_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev
Reply | Threaded
Open this post in threaded view
|

Re: [infinispan-dev] Questions on AtomicMap and improvement proposals

Mircea Markus

On 14 Apr 2011, at 15:30, Manik Surtani wrote:

Apologies for the late response.

On 13 Apr 2011, at 10:38, Emmanuel Bernard wrote:

In exchange for answers, I will improve at least the JavaDoc and maybe create a wiki from this info.

Sounds like a fair exchange.  :-)

I've tried to search the wiki but found nothing on AtomicMap (only forum posts) and I've read the AtomicMap JavaDoc but I am still a bit unsure of what's going on.

When I need to create an AtomicMap, I must use 
AtomicMap<String, Object> resultset = AtomicMapLookup.getAtomicMap(cache, "my_atomic_map_key");

Well, AtomicMapLookup.getAtomicMap(cache, myAtomicMapName).

Questions
Here are a few questions for you

1. How can I apply advanced flags to get or create the AtomicMap?
cache.withFlag(SKIP_CACHE_STORE,FORCE_ASYNCHRONOUS).get("my_atomic_map_key");

You can't right now; as a "dirty hack", you can just do what getAtomicMap() does internally, adding the flags you need.


The real solution: create a feature request on JIRA so that we can add flags to getAtomicMap() as well.

3. Is that legal to use other cache methods like replace on an AtomicMap value, what are the consequences?

cache.putIfAbsent() is used internally by getAtomicMap().  replace() is harder, since it may mean that a thread may be storing stuff in an AtomicMap that has been replaced, so those changes get lost.  Why would you need to replace() an atomic map?
if we don't allow replace shouldn't we at least throw an exception so that user would notice that?

3. When I expect a map to be present in the key, can I use cache.get("my_atomic_map_key") and still benefit from my properly proxied AtomicMap? Or am I forced to use AtomicMapLookup.getAtomicMap?

You need to use AML.getAtomicMap() to make sure your proxy is properly created/wrapped.  See:

This is somehow error prone the users - good that Emmanuel reads the docs :-)
I would expect cache.get("my_atomic_map_key") to return a proxified form. This is quite easy achievable if we move the proxification in GetKeyValueCommand

4. Using AtomicMapLookup.getAtomicMap, how can I differentiate an empty key where a new map has been created from a retrieval of an empty map stored in the key?

You could use getAtomicMap(cache, mapName, createIfAbsent) so you get a null if createIfAbsent == false and no such atomic map exists.  Does this help?

5. Must I use AtomicMapLookup.remove method to remove an atomic map?

You can just use cache.remove(), but for the sake of clean generics, it is better to go via AML.remove().

6. Can I clone an AtomicMap?

No, it's not cloneable, since a clone that is not stored in the cache (in a threadsafe manner) is meaningless, and Java's clone() API doesn't allow you to pass in a new name for the clone.

However, we could provide a AtomicMap.clone(nameOfClone) method, which could take care of this (internally call AML.getAtomicMap(nameOfClone) and copy contents across).

For using methods like replace(), it seems one would need to clone the atomicmap to compare it to the initial value. When I tried briefly Iw as unsure I could do that.

Yep.

Proposed improvements

I'm asking all the questions because these can potentially make AtomicMap users life quite hard and abstracting Infinispan from OGM will make a damn ugly interface / contract

1. Would it be possible to let people get their proxied AtomicMap from cache.get() and other get methods?
It seems that either the marshaller or the get operations (probably the get ops as local cache should work as well) should be able to intercept an AtomicMap and essentually do what AtomicMapLookup is doing (and make sure it is properly wrapped).
If that's possible that would be already a big benefit for the user as it would only be limited to AtomicMap creation or cloning

Fair point, certain AML code could be moved into the CacheDelegate.  But I fear a lot of instanceof checking which may be unnecessary if using the cache to store anything other than AtomicMaps.

2. Would it be possible to let people create standalone AtomicMaps and associate them to the cache lasily and in a transparent fashion.
AtomicMap<String, Object> resultSet = AtomicMapLookup.createAtomicMap();
cache.put(key, resultSet); //lazily set cache, deltaMapKey, batchContainer and icc for new AtomicMaps

The problem there is that the put() won't be atomic.  You'd need to mandate a putIfAbsent, but that means any initialization of the AtomicMap (setting values) could potentially be wasted.  This is why the AML registers the AtomicMap in the cache before allowing user code to store values.

3. Could we guarantee some equality between Map and AtomicMap?
if I do Map 

map = new HashMap(atomicMap);
atomicMap.put("key", "value");
cache.replace(key, map, atomicMap);

Am I guaranteed that it can work (if no one has pushed a change behind my back)?

Not at the moment, but this is something we could possibly do.

Hope this helps
Manik
--
Manik Surtani

Lead, Infinispan



_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev


_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev
Reply | Threaded
Open this post in threaded view
|

Re: [infinispan-dev] Questions on AtomicMap and improvement proposals

Emmanuel Bernard
In reply to this post by Manik Surtani
Another behavior I'm seeing that is surprising me is:

tx.begin();
Map<?,?> map = AtomicMapLookup.getAtomicMap(cache, key);
assert map.size() == 3;
AtomicMapLookup.removeAtomicMap(cache, key);
assert map.size() == 0;
tx.commit();

I can sort understand in a twisted way that removeAtomicMap clears the underlying map but that's for sure surprising and can lead to weird bugs for ATM users. Is that necessary?

Emmanuel

On 14 avr. 2011, at 10:30, Manik Surtani wrote:

Apologies for the late response.

On 13 Apr 2011, at 10:38, Emmanuel Bernard wrote:

In exchange for answers, I will improve at least the JavaDoc and maybe create a wiki from this info.

Sounds like a fair exchange.  :-)

I've tried to search the wiki but found nothing on AtomicMap (only forum posts) and I've read the AtomicMap JavaDoc but I am still a bit unsure of what's going on.

When I need to create an AtomicMap, I must use 
AtomicMap<String, Object> resultset = AtomicMapLookup.getAtomicMap(cache, "my_atomic_map_key");

Well, AtomicMapLookup.getAtomicMap(cache, myAtomicMapName).

Questions
Here are a few questions for you

1. How can I apply advanced flags to get or create the AtomicMap?
cache.withFlag(SKIP_CACHE_STORE,FORCE_ASYNCHRONOUS).get("my_atomic_map_key");

You can't right now; as a "dirty hack", you can just do what getAtomicMap() does internally, adding the flags you need.


The real solution: create a feature request on JIRA so that we can add flags to getAtomicMap() as well.

3. Is that legal to use other cache methods like replace on an AtomicMap value, what are the consequences?

cache.putIfAbsent() is used internally by getAtomicMap().  replace() is harder, since it may mean that a thread may be storing stuff in an AtomicMap that has been replaced, so those changes get lost.  Why would you need to replace() an atomic map?

3. When I expect a map to be present in the key, can I use cache.get("my_atomic_map_key") and still benefit from my properly proxied AtomicMap? Or am I forced to use AtomicMapLookup.getAtomicMap?

You need to use AML.getAtomicMap() to make sure your proxy is properly created/wrapped.  See:


4. Using AtomicMapLookup.getAtomicMap, how can I differentiate an empty key where a new map has been created from a retrieval of an empty map stored in the key?

You could use getAtomicMap(cache, mapName, createIfAbsent) so you get a null if createIfAbsent == false and no such atomic map exists.  Does this help?

5. Must I use AtomicMapLookup.remove method to remove an atomic map?

You can just use cache.remove(), but for the sake of clean generics, it is better to go via AML.remove().

6. Can I clone an AtomicMap?

No, it's not cloneable, since a clone that is not stored in the cache (in a threadsafe manner) is meaningless, and Java's clone() API doesn't allow you to pass in a new name for the clone.

However, we could provide a AtomicMap.clone(nameOfClone) method, which could take care of this (internally call AML.getAtomicMap(nameOfClone) and copy contents across).

For using methods like replace(), it seems one would need to clone the atomicmap to compare it to the initial value. When I tried briefly Iw as unsure I could do that.

Yep.

Proposed improvements

I'm asking all the questions because these can potentially make AtomicMap users life quite hard and abstracting Infinispan from OGM will make a damn ugly interface / contract

1. Would it be possible to let people get their proxied AtomicMap from cache.get() and other get methods?
It seems that either the marshaller or the get operations (probably the get ops as local cache should work as well) should be able to intercept an AtomicMap and essentually do what AtomicMapLookup is doing (and make sure it is properly wrapped).
If that's possible that would be already a big benefit for the user as it would only be limited to AtomicMap creation or cloning

Fair point, certain AML code could be moved into the CacheDelegate.  But I fear a lot of instanceof checking which may be unnecessary if using the cache to store anything other than AtomicMaps.

2. Would it be possible to let people create standalone AtomicMaps and associate them to the cache lasily and in a transparent fashion.
AtomicMap<String, Object> resultSet = AtomicMapLookup.createAtomicMap();
cache.put(key, resultSet); //lazily set cache, deltaMapKey, batchContainer and icc for new AtomicMaps

The problem there is that the put() won't be atomic.  You'd need to mandate a putIfAbsent, but that means any initialization of the AtomicMap (setting values) could potentially be wasted.  This is why the AML registers the AtomicMap in the cache before allowing user code to store values.

3. Could we guarantee some equality between Map and AtomicMap?
if I do Map 

map = new HashMap(atomicMap);
atomicMap.put("key", "value");
cache.replace(key, map, atomicMap);

Am I guaranteed that it can work (if no one has pushed a change behind my back)?

Not at the moment, but this is something we could possibly do.

Hope this helps
Manik
--
Manik Surtani

Lead, Infinispan



_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev


_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev
Reply | Threaded
Open this post in threaded view
|

Re: [infinispan-dev] Questions on AtomicMap and improvement proposals

Galder Zamarreno
Well, there's a fundamental difference to how atomic map works to normal cache operations and that's the fact that the creation of atomic maps is hidden behind AtomicMapLookup.getAtomicMap. It's not like std cache usage where the client creates the map that goes into the cache.

So, I don't see why AtomicMapLookup.removeAtomicMap should let that map escape its boundaries. IOW, the underlying map is owned by the AML class, not the the user code.

On Apr 30, 2011, at 9:14 PM, Emmanuel Bernard wrote:

> Another behavior I'm seeing that is surprising me is:
>
> tx.begin();
> Map<?,?> map = AtomicMapLookup.getAtomicMap(cache, key);
> assert map.size() == 3;
> AtomicMapLookup.removeAtomicMap(cache, key);
> assert map.size() == 0;
> tx.commit();
>
> I can sort understand in a twisted way that removeAtomicMap clears the underlying map but that's for sure surprising and can lead to weird bugs for ATM users. Is that necessary?
>
> Emmanuel
>
> On 14 avr. 2011, at 10:30, Manik Surtani wrote:
>
>> Apologies for the late response.
>>
>> On 13 Apr 2011, at 10:38, Emmanuel Bernard wrote:
>>
>>> In exchange for answers, I will improve at least the JavaDoc and maybe create a wiki from this info.
>>
>> Sounds like a fair exchange.  :-)
>>
>>> I've tried to search the wiki but found nothing on AtomicMap (only forum posts) and I've read the AtomicMap JavaDoc but I am still a bit unsure of what's going on.
>>>
>>> When I need to create an AtomicMap, I must use
>>> AtomicMap<String, Object> resultset = AtomicMapLookup.getAtomicMap(cache, "my_atomic_map_key");
>>
>> Well, AtomicMapLookup.getAtomicMap(cache, myAtomicMapName).
>>
>>> Questions
>>> Here are a few questions for you
>>>
>>> 1. How can I apply advanced flags to get or create the AtomicMap?
>>> cache.withFlag(SKIP_CACHE_STORE,FORCE_ASYNCHRONOUS).get("my_atomic_map_key");
>>
>> You can't right now; as a "dirty hack", you can just do what getAtomicMap() does internally, adding the flags you need.
>>
>> https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/atomic/AtomicMapLookup.java#L49
>>
>> The real solution: create a feature request on JIRA so that we can add flags to getAtomicMap() as well.
>>
>>> 3. Is that legal to use other cache methods like replace on an AtomicMap value, what are the consequences?
>>
>> cache.putIfAbsent() is used internally by getAtomicMap().  replace() is harder, since it may mean that a thread may be storing stuff in an AtomicMap that has been replaced, so those changes get lost.  Why would you need to replace() an atomic map?
>>
>>> 3. When I expect a map to be present in the key, can I use cache.get("my_atomic_map_key") and still benefit from my properly proxied AtomicMap? Or am I forced to use AtomicMapLookup.getAtomicMap?
>>
>> You need to use AML.getAtomicMap() to make sure your proxy is properly created/wrapped.  See:
>>
>> https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/atomic/AtomicMapLookup.java#L49
>>
>>> 4. Using AtomicMapLookup.getAtomicMap, how can I differentiate an empty key where a new map has been created from a retrieval of an empty map stored in the key?
>>
>> You could use getAtomicMap(cache, mapName, createIfAbsent) so you get a null if createIfAbsent == false and no such atomic map exists.  Does this help?
>>
>>> 5. Must I use AtomicMapLookup.remove method to remove an atomic map?
>>
>> You can just use cache.remove(), but for the sake of clean generics, it is better to go via AML.remove().
>>
>>> 6. Can I clone an AtomicMap?
>>
>> No, it's not cloneable, since a clone that is not stored in the cache (in a threadsafe manner) is meaningless, and Java's clone() API doesn't allow you to pass in a new name for the clone.
>>
>> However, we could provide a AtomicMap.clone(nameOfClone) method, which could take care of this (internally call AML.getAtomicMap(nameOfClone) and copy contents across).
>>
>>> For using methods like replace(), it seems one would need to clone the atomicmap to compare it to the initial value. When I tried briefly Iw as unsure I could do that.
>>
>> Yep.
>>
>>> Proposed improvements
>>>
>>> I'm asking all the questions because these can potentially make AtomicMap users life quite hard and abstracting Infinispan from OGM will make a damn ugly interface / contract
>>>
>>> 1. Would it be possible to let people get their proxied AtomicMap from cache.get() and other get methods?
>>> It seems that either the marshaller or the get operations (probably the get ops as local cache should work as well) should be able to intercept an AtomicMap and essentually do what AtomicMapLookup is doing (and make sure it is properly wrapped).
>>> If that's possible that would be already a big benefit for the user as it would only be limited to AtomicMap creation or cloning
>>
>> Fair point, certain AML code could be moved into the CacheDelegate.  But I fear a lot of instanceof checking which may be unnecessary if using the cache to store anything other than AtomicMaps.
>>
>>> 2. Would it be possible to let people create standalone AtomicMaps and associate them to the cache lasily and in a transparent fashion.
>>> AtomicMap<String, Object> resultSet = AtomicMapLookup.createAtomicMap();
>>> cache.put(key, resultSet); //lazily set cache, deltaMapKey, batchContainer and icc for new AtomicMaps
>>
>> The problem there is that the put() won't be atomic.  You'd need to mandate a putIfAbsent, but that means any initialization of the AtomicMap (setting values) could potentially be wasted.  This is why the AML registers the AtomicMap in the cache before allowing user code to store values.
>>
>>> 3. Could we guarantee some equality between Map and AtomicMap?
>>> if I do Map
>>>
>>> map = new HashMap(atomicMap);
>>> atomicMap.put("key", "value");
>>> cache.replace(key, map, atomicMap);
>>>
>>> Am I guaranteed that it can work (if no one has pushed a change behind my back)?
>>
>> Not at the moment, but this is something we could possibly do.
>>
>> Hope this helps
>> Manik
>> --
>> Manik Surtani
>> [hidden email]
>> twitter.com/maniksurtani
>>
>> Lead, Infinispan
>> http://www.infinispan.org
>>
>>
>>
>> _______________________________________________
>> infinispan-dev mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/infinispan-dev
>
> _______________________________________________
> infinispan-dev mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/infinispan-dev

--
Galder ZamarreƱo
Sr. Software Engineer
Infinispan, JBoss Cache


_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev
Reply | Threaded
Open this post in threaded view
|

Re: [infinispan-dev] Questions on AtomicMap and improvement proposals

Manik Surtani
In reply to this post by Emmanuel Bernard

On 30 Apr 2011, at 20:14, Emmanuel Bernard wrote:

> Another behavior I'm seeing that is surprising me is:
>
> tx.begin();
> Map<?,?> map = AtomicMapLookup.getAtomicMap(cache, key);
> assert map.size() == 3;
> AtomicMapLookup.removeAtomicMap(cache, key);
> assert map.size() == 0;
> tx.commit();
>
> I can sort understand in a twisted way that removeAtomicMap clears the underlying map but that's for sure surprising and can lead to weird bugs for ATM users. Is that necessary?

This is weird, from a usage perspective, agreed.

Realistically, any operations that happen on an atomic map handle after the atomic map has been removed should result in an exception.  I can't think of any existing JDK exceptions being valid - perhaps InvalidAtomicMapException?

@Emmanuel, WDYT?

Cheers
Manik

--
Manik Surtani
[hidden email]
twitter.com/maniksurtani

Lead, Infinispan
http://www.infinispan.org




_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev
Reply | Threaded
Open this post in threaded view
|

Re: [infinispan-dev] Questions on AtomicMap and improvement proposals

Emmanuel Bernard

On 18 mai 2011, at 12:23, Manik Surtani wrote:

>
> On 30 Apr 2011, at 20:14, Emmanuel Bernard wrote:
>
>> Another behavior I'm seeing that is surprising me is:
>>
>> tx.begin();
>> Map<?,?> map = AtomicMapLookup.getAtomicMap(cache, key);
>> assert map.size() == 3;
>> AtomicMapLookup.removeAtomicMap(cache, key);
>> assert map.size() == 0;
>> tx.commit();
>>
>> I can sort understand in a twisted way that removeAtomicMap clears the underlying map but that's for sure surprising and can lead to weird bugs for ATM users. Is that necessary?
>
> This is weird, from a usage perspective, agreed.
>
> Realistically, any operations that happen on an atomic map handle after the atomic map has been removed should result in an exception.  I can't think of any existing JDK exceptions being valid - perhaps InvalidAtomicMapException?
>
> @Emmanuel, WDYT?

IllegalStateException works, I'd say

/**
 * Signals that a method has been invoked at an illegal or
 * inappropriate time.  In other words, the Java environment or
 * Java application is not in an appropriate state for the requested
 * operation.
 */


_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev
Reply | Threaded
Open this post in threaded view
|

Re: [infinispan-dev] Questions on AtomicMap and improvement proposals

Manik Surtani

On 18 May 2011, at 12:17, Emmanuel Bernard wrote:


On 18 mai 2011, at 12:23, Manik Surtani wrote:


On 30 Apr 2011, at 20:14, Emmanuel Bernard wrote:

Another behavior I'm seeing that is surprising me is:

tx.begin();
Map<?,?> map = AtomicMapLookup.getAtomicMap(cache, key);
assert map.size() == 3;
AtomicMapLookup.removeAtomicMap(cache, key);
assert map.size() == 0;
tx.commit();

I can sort understand in a twisted way that removeAtomicMap clears the underlying map but that's for sure surprising and can lead to weird bugs for ATM users. Is that necessary?

This is weird, from a usage perspective, agreed.

Realistically, any operations that happen on an atomic map handle after the atomic map has been removed should result in an exception.  I can't think of any existing JDK exceptions being valid - perhaps InvalidAtomicMapException?

@Emmanuel, WDYT?

IllegalStateException works, I'd say

Ok, ISE it is then.





_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev
Reply | Threaded
Open this post in threaded view
|

Re: [infinispan-dev] Questions on AtomicMap and improvement proposals

Manik Surtani

On 18 May 2011, at 12:24, Manik Surtani wrote:

>>>
>>> Realistically, any operations that happen on an atomic map handle after the atomic map has been removed should result in an exception.  I can't think of any existing JDK exceptions being valid - perhaps InvalidAtomicMapException?
>>>
>>> @Emmanuel, WDYT?
>>
>> IllegalStateException works, I'd say
>
> Ok, ISE it is then.
>
> https://issues.jboss.org/browse/ISPN-1121

Pull req issued.  This is going to be in CR3.

https://github.com/infinispan/infinispan/pull/321

--
Manik Surtani
[hidden email]
twitter.com/maniksurtani

Lead, Infinispan
http://www.infinispan.org




_______________________________________________
infinispan-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/infinispan-dev