You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@directmemory.apache.org by Christian Moen <ch...@gmail.com> on 2012/08/06 09:52:19 UTC

Basic DirectMemory usage question

Hello,

I'm looking into using Apache DirectMemory and I believe I'm missing something basic that I'm hoping someone can help me understand.

I'd like to use DirectMemory as an off-heap key-value store (for gigabytes of data) and I'm having a problem updating the value for a given key.

This code illustrates my problem:

       CacheService<String, Long> cache = new DirectMemory<String, Long>()
            .setNumberOfBuffers(10)
            .setSize(1000)
            .setInitialCapacity(100000)
            .setConcurrencyLevel(4)
            .newCacheService();

        System.out.println("a : " + cache.retrieve("a"));
        System.out.println("a -> 3 : " + cache.put("a", 3L));
        System.out.println("a : " + cache.retrieve("a"));
        System.out.println("a -> 5 : " + cache.put("a", 5L));
        System.out.println("a : " + cache.retrieve("a"));

Running it gives this output:

	a : null
	a -> 3 : PointerImpl[0, 0] not free
	a : 3
	a -> 5 : PointerImpl[0, 0] not free
	a : null

Hence, the 5 isn't stored in the cache with the above code.  (I'm not sure if 3 is stored properly, either.)

The documentation on http://incubator.apache.org/directmemory/simple-usage.html tells me that the object has been stored if put() returns null.  It doesn't in my case, so I'm speculating that memory needs to be provided somehow, but I'm not sure how I should do that.  I can't seem to find details on this in the example or the other documentation available, either.  I've also had a quick look through code and nothing 

My understanding was that a high-level put() and retrieve() interface was provided by whatever backed CacheService and that memory allocation would be handled by a MemoryManagerService, but I might have misunderstood things.  Guidance is most appreciated.

By the way, my POM coordinates are as follows:

	<dependency>
		<groupId>org.apache.directmemory</groupId>
		<artifactId>directmemory-cache</artifactId>
		<version>0.1-incubating</version>
	</dependency>

Notice that I'm using "org.apache.directmemory" instead of "org.apache.directmemory.server" as the documentation suggested, since the latter didn't seem to be valid.

Many thanks for any help,


Christian


Re: Basic DirectMemory usage question

Posted by Tommaso Teofili <to...@gmail.com>.
Good to know and thanks Raffaele for being quicker than me in resolving the
issue.
Have a nice day,
Tommaso

2012/8/7 Christian Moen <ch...@gmail.com>

> Hello Raffaele and Tommaso,
>
> Thanks a lot for the quick resolve.  I've confirmed that my own tests work
> as expected now.
>
> Best,
> Christian
>
> On Aug 7, 2012, at 6:59 AM, "Raffaele P. Guidi" <
> raffaele.p.guidi@gmail.com> wrote:
>
> opened and fixed https://issues.apache.org/jira/browse/DIRECTMEMORY-99
>
> Thanks for reporting this.
>
> Ciao,
>     R
>
> On Mon, Aug 6, 2012 at 6:39 PM, Raffaele P. Guidi <
> raffaele.p.guidi@gmail.com> wrote:
>
>> I've added a test case to block the build until the problem is resolved
>> (cache/BasicTest.java). Still didn't have the time to find the bug, though
>> - but the team is moving ;)
>>
>> Cheers,
>>      R
>>
>>
>> On Mon, Aug 6, 2012 at 5:24 PM, Tommaso Teofili <
>> tommaso.teofili@gmail.com> wrote:
>>
>>>
>>>
>>> 2012/8/6 Raffaele P. Guidi <ra...@gmail.com>
>>>
>>> I believe that "the object has been stored if put() returns null" is a
>>>> typo that should be read "the object has been stored if put()  retuns
>>>> a Pointer instance"
>>>
>>>
>>> yes , that looks like a typo.
>>>
>>>
>>>> and that the latest "null" could be a bug (it should return 5l or the
>>>> line above should return an error). I gotta take a look at it.
>>>
>>>
>>> I've reproduced that, the reason last line is returning null is that the
>>> Pointer instance is marked as free (which shouldn't be in my opinion) thus
>>> I think that's a bug (in the put method which actually creates the pointer).
>>> I'll work more on that later today or tomorrow.
>>> Regards,
>>> Tommaso
>>>
>>>
>>>>
>>>> Cheers,
>>>>     R
>>>>
>>>>
>>>> On Mon, Aug 6, 2012 at 9:52 AM, Christian Moen <
>>>> christian.moen@gmail.com> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I'm looking into using Apache DirectMemory and I believe I'm missing
>>>>> something basic that I'm hoping someone can help me understand.
>>>>>
>>>>> I'd like to use DirectMemory as an off-heap key-value store (for
>>>>> gigabytes of data) and I'm having a problem updating the value for a given
>>>>> key.
>>>>>
>>>>> This code illustrates my problem:
>>>>>
>>>>>        CacheService<String, Long> cache = new DirectMemory<String,
>>>>> Long>()
>>>>>             .setNumberOfBuffers(10)
>>>>>             .setSize(1000)
>>>>>             .setInitialCapacity(100000)
>>>>>             .setConcurrencyLevel(4)
>>>>>             .newCacheService();
>>>>>
>>>>>         System.out.println("a : " + cache.retrieve("a"));
>>>>>         System.out.println("a -> 3 : " + cache.put("a", 3L));
>>>>>         System.out.println("a : " + cache.retrieve("a"));
>>>>>         System.out.println("a -> 5 : " + cache.put("a", 5L));
>>>>>         System.out.println("a : " + cache.retrieve("a"));
>>>>>
>>>>> Running it gives this output:
>>>>>
>>>>> a : null
>>>>> a -> 3 : PointerImpl[0, 0] not free
>>>>>  a : 3
>>>>> a -> 5 : PointerImpl[0, 0] not free
>>>>> a : null
>>>>>
>>>>> Hence, the 5 isn't stored in the cache with the above code.  (I'm not
>>>>> sure if 3 is stored properly, either.)
>>>>>
>>>>> The documentation on
>>>>> http://incubator.apache.org/directmemory/simple-usage.html tells me
>>>>> that the object has been stored if put() returns null.  It doesn't in my
>>>>> case, so I'm speculating that memory needs to be provided somehow, but I'm
>>>>> not sure how I should do that.  I can't seem to find details on this in the
>>>>> example or the other documentation available, either.  I've also had a
>>>>> quick look through code and nothing
>>>>>
>>>>> My understanding was that a high-level put() and retrieve() interface
>>>>> was provided by whatever backed CacheService and that memory allocation
>>>>> would be handled by a MemoryManagerService, but I might have misunderstood
>>>>> things.  Guidance is most appreciated.
>>>>>
>>>>> By the way, my POM coordinates are as follows:
>>>>>
>>>>> <dependency>
>>>>> <groupId>org.apache.directmemory</groupId>
>>>>>  <artifactId>directmemory-cache</artifactId>
>>>>> <version>0.1-incubating</version>
>>>>>  </dependency>
>>>>>
>>>>> Notice that I'm using "org.apache.directmemory" instead of
>>>>> "org.apache.directmemory.server" as the documentation suggested, since the
>>>>> latter didn't seem to be valid.
>>>>>
>>>>> Many thanks for any help,
>>>>>
>>>>>
>>>>> Christian
>>>>>
>>>>>
>>>>
>>>
>>
>
>

Re: Basic DirectMemory usage question

Posted by Christian Moen <ch...@gmail.com>.
Hello Raffaele and Tommaso,

Thanks a lot for the quick resolve.  I've confirmed that my own tests work as expected now.

Best,
Christian

On Aug 7, 2012, at 6:59 AM, "Raffaele P. Guidi" <ra...@gmail.com> wrote:

> opened and fixed https://issues.apache.org/jira/browse/DIRECTMEMORY-99
> 
> Thanks for reporting this.
> 
> Ciao,
>     R
> 
> On Mon, Aug 6, 2012 at 6:39 PM, Raffaele P. Guidi <ra...@gmail.com> wrote:
> I've added a test case to block the build until the problem is resolved (cache/BasicTest.java). Still didn't have the time to find the bug, though - but the team is moving ;)
> 
> Cheers,
>      R
> 
> 
> On Mon, Aug 6, 2012 at 5:24 PM, Tommaso Teofili <to...@gmail.com> wrote:
> 
> 
> 2012/8/6 Raffaele P. Guidi <ra...@gmail.com>
> 
> I believe that "the object has been stored if put() returns null" is a typo that should be read "the object has been stored if put()  retuns a Pointer instance"
> 
> yes , that looks like a typo.
>  
> and that the latest "null" could be a bug (it should return 5l or the line above should return an error). I gotta take a look at it.
> 
> I've reproduced that, the reason last line is returning null is that the Pointer instance is marked as free (which shouldn't be in my opinion) thus I think that's a bug (in the put method which actually creates the pointer).
> I'll work more on that later today or tomorrow.
> Regards,
> Tommaso
>  
> 
> Cheers,
>     R
> 
> 
> On Mon, Aug 6, 2012 at 9:52 AM, Christian Moen <ch...@gmail.com> wrote:
> Hello,
> 
> I'm looking into using Apache DirectMemory and I believe I'm missing something basic that I'm hoping someone can help me understand.
> 
> I'd like to use DirectMemory as an off-heap key-value store (for gigabytes of data) and I'm having a problem updating the value for a given key.
> 
> This code illustrates my problem:
> 
>        CacheService<String, Long> cache = new DirectMemory<String, Long>()
>             .setNumberOfBuffers(10)
>             .setSize(1000)
>             .setInitialCapacity(100000)
>             .setConcurrencyLevel(4)
>             .newCacheService();
> 
>         System.out.println("a : " + cache.retrieve("a"));
>         System.out.println("a -> 3 : " + cache.put("a", 3L));
>         System.out.println("a : " + cache.retrieve("a"));
>         System.out.println("a -> 5 : " + cache.put("a", 5L));
>         System.out.println("a : " + cache.retrieve("a"));
> 
> Running it gives this output:
> 
> 	a : null
> 	a -> 3 : PointerImpl[0, 0] not free
> 	a : 3
> 	a -> 5 : PointerImpl[0, 0] not free
> 	a : null
> 
> Hence, the 5 isn't stored in the cache with the above code.  (I'm not sure if 3 is stored properly, either.)
> 
> The documentation on http://incubator.apache.org/directmemory/simple-usage.html tells me that the object has been stored if put() returns null.  It doesn't in my case, so I'm speculating that memory needs to be provided somehow, but I'm not sure how I should do that.  I can't seem to find details on this in the example or the other documentation available, either.  I've also had a quick look through code and nothing 
> 
> My understanding was that a high-level put() and retrieve() interface was provided by whatever backed CacheService and that memory allocation would be handled by a MemoryManagerService, but I might have misunderstood things.  Guidance is most appreciated.
> 
> By the way, my POM coordinates are as follows:
> 
> 	<dependency>
> 		<groupId>org.apache.directmemory</groupId>
> 		<artifactId>directmemory-cache</artifactId>
> 		<version>0.1-incubating</version>
> 	</dependency>
> 
> Notice that I'm using "org.apache.directmemory" instead of "org.apache.directmemory.server" as the documentation suggested, since the latter didn't seem to be valid.
> 
> Many thanks for any help,
> 
> 
> Christian
> 
> 
> 
> 
> 


Re: Basic DirectMemory usage question

Posted by "Raffaele P. Guidi" <ra...@gmail.com>.
opened and fixed https://issues.apache.org/jira/browse/DIRECTMEMORY-99

Thanks for reporting this.

Ciao,
    R

On Mon, Aug 6, 2012 at 6:39 PM, Raffaele P. Guidi <
raffaele.p.guidi@gmail.com> wrote:

> I've added a test case to block the build until the problem is resolved
> (cache/BasicTest.java). Still didn't have the time to find the bug, though
> - but the team is moving ;)
>
> Cheers,
>      R
>
>
> On Mon, Aug 6, 2012 at 5:24 PM, Tommaso Teofili <tommaso.teofili@gmail.com
> > wrote:
>
>>
>>
>> 2012/8/6 Raffaele P. Guidi <ra...@gmail.com>
>>
>> I believe that "the object has been stored if put() returns null" is a
>>> typo that should be read "the object has been stored if put()  retuns a
>>> Pointer instance"
>>
>>
>> yes , that looks like a typo.
>>
>>
>>> and that the latest "null" could be a bug (it should return 5l or the
>>> line above should return an error). I gotta take a look at it.
>>
>>
>> I've reproduced that, the reason last line is returning null is that the
>> Pointer instance is marked as free (which shouldn't be in my opinion) thus
>> I think that's a bug (in the put method which actually creates the pointer).
>> I'll work more on that later today or tomorrow.
>> Regards,
>> Tommaso
>>
>>
>>>
>>> Cheers,
>>>     R
>>>
>>>
>>> On Mon, Aug 6, 2012 at 9:52 AM, Christian Moen <christian.moen@gmail.com
>>> > wrote:
>>>
>>>> Hello,
>>>>
>>>> I'm looking into using Apache DirectMemory and I believe I'm missing
>>>> something basic that I'm hoping someone can help me understand.
>>>>
>>>> I'd like to use DirectMemory as an off-heap key-value store (for
>>>> gigabytes of data) and I'm having a problem updating the value for a given
>>>> key.
>>>>
>>>> This code illustrates my problem:
>>>>
>>>>        CacheService<String, Long> cache = new DirectMemory<String,
>>>> Long>()
>>>>             .setNumberOfBuffers(10)
>>>>             .setSize(1000)
>>>>             .setInitialCapacity(100000)
>>>>             .setConcurrencyLevel(4)
>>>>             .newCacheService();
>>>>
>>>>         System.out.println("a : " + cache.retrieve("a"));
>>>>         System.out.println("a -> 3 : " + cache.put("a", 3L));
>>>>         System.out.println("a : " + cache.retrieve("a"));
>>>>         System.out.println("a -> 5 : " + cache.put("a", 5L));
>>>>         System.out.println("a : " + cache.retrieve("a"));
>>>>
>>>> Running it gives this output:
>>>>
>>>> a : null
>>>> a -> 3 : PointerImpl[0, 0] not free
>>>>  a : 3
>>>> a -> 5 : PointerImpl[0, 0] not free
>>>> a : null
>>>>
>>>> Hence, the 5 isn't stored in the cache with the above code.  (I'm not
>>>> sure if 3 is stored properly, either.)
>>>>
>>>> The documentation on
>>>> http://incubator.apache.org/directmemory/simple-usage.html tells me
>>>> that the object has been stored if put() returns null.  It doesn't in my
>>>> case, so I'm speculating that memory needs to be provided somehow, but I'm
>>>> not sure how I should do that.  I can't seem to find details on this in the
>>>> example or the other documentation available, either.  I've also had a
>>>> quick look through code and nothing
>>>>
>>>> My understanding was that a high-level put() and retrieve() interface
>>>> was provided by whatever backed CacheService and that memory allocation
>>>> would be handled by a MemoryManagerService, but I might have misunderstood
>>>> things.  Guidance is most appreciated.
>>>>
>>>> By the way, my POM coordinates are as follows:
>>>>
>>>> <dependency>
>>>> <groupId>org.apache.directmemory</groupId>
>>>>  <artifactId>directmemory-cache</artifactId>
>>>> <version>0.1-incubating</version>
>>>>  </dependency>
>>>>
>>>> Notice that I'm using "org.apache.directmemory" instead of
>>>> "org.apache.directmemory.server" as the documentation suggested, since the
>>>> latter didn't seem to be valid.
>>>>
>>>> Many thanks for any help,
>>>>
>>>>
>>>> Christian
>>>>
>>>>
>>>
>>
>

Re: Basic DirectMemory usage question

Posted by "Raffaele P. Guidi" <ra...@gmail.com>.
I've added a test case to block the build until the problem is resolved
(cache/BasicTest.java). Still didn't have the time to find the bug, though
- but the team is moving ;)

Cheers,
     R

On Mon, Aug 6, 2012 at 5:24 PM, Tommaso Teofili
<to...@gmail.com>wrote:

>
>
> 2012/8/6 Raffaele P. Guidi <ra...@gmail.com>
>
> I believe that "the object has been stored if put() returns null" is a
>> typo that should be read "the object has been stored if put()  retuns a
>> Pointer instance"
>
>
> yes , that looks like a typo.
>
>
>> and that the latest "null" could be a bug (it should return 5l or the
>> line above should return an error). I gotta take a look at it.
>
>
> I've reproduced that, the reason last line is returning null is that the
> Pointer instance is marked as free (which shouldn't be in my opinion) thus
> I think that's a bug (in the put method which actually creates the pointer).
> I'll work more on that later today or tomorrow.
> Regards,
> Tommaso
>
>
>>
>> Cheers,
>>     R
>>
>>
>> On Mon, Aug 6, 2012 at 9:52 AM, Christian Moen <ch...@gmail.com>wrote:
>>
>>> Hello,
>>>
>>> I'm looking into using Apache DirectMemory and I believe I'm missing
>>> something basic that I'm hoping someone can help me understand.
>>>
>>> I'd like to use DirectMemory as an off-heap key-value store (for
>>> gigabytes of data) and I'm having a problem updating the value for a given
>>> key.
>>>
>>> This code illustrates my problem:
>>>
>>>        CacheService<String, Long> cache = new DirectMemory<String,
>>> Long>()
>>>             .setNumberOfBuffers(10)
>>>             .setSize(1000)
>>>             .setInitialCapacity(100000)
>>>             .setConcurrencyLevel(4)
>>>             .newCacheService();
>>>
>>>         System.out.println("a : " + cache.retrieve("a"));
>>>         System.out.println("a -> 3 : " + cache.put("a", 3L));
>>>         System.out.println("a : " + cache.retrieve("a"));
>>>         System.out.println("a -> 5 : " + cache.put("a", 5L));
>>>         System.out.println("a : " + cache.retrieve("a"));
>>>
>>> Running it gives this output:
>>>
>>> a : null
>>> a -> 3 : PointerImpl[0, 0] not free
>>>  a : 3
>>> a -> 5 : PointerImpl[0, 0] not free
>>> a : null
>>>
>>> Hence, the 5 isn't stored in the cache with the above code.  (I'm not
>>> sure if 3 is stored properly, either.)
>>>
>>> The documentation on
>>> http://incubator.apache.org/directmemory/simple-usage.html tells me
>>> that the object has been stored if put() returns null.  It doesn't in my
>>> case, so I'm speculating that memory needs to be provided somehow, but I'm
>>> not sure how I should do that.  I can't seem to find details on this in the
>>> example or the other documentation available, either.  I've also had a
>>> quick look through code and nothing
>>>
>>> My understanding was that a high-level put() and retrieve() interface
>>> was provided by whatever backed CacheService and that memory allocation
>>> would be handled by a MemoryManagerService, but I might have misunderstood
>>> things.  Guidance is most appreciated.
>>>
>>> By the way, my POM coordinates are as follows:
>>>
>>> <dependency>
>>> <groupId>org.apache.directmemory</groupId>
>>>  <artifactId>directmemory-cache</artifactId>
>>> <version>0.1-incubating</version>
>>>  </dependency>
>>>
>>> Notice that I'm using "org.apache.directmemory" instead of
>>> "org.apache.directmemory.server" as the documentation suggested, since the
>>> latter didn't seem to be valid.
>>>
>>> Many thanks for any help,
>>>
>>>
>>> Christian
>>>
>>>
>>
>

Re: Basic DirectMemory usage question

Posted by Tommaso Teofili <to...@gmail.com>.
2012/8/6 Raffaele P. Guidi <ra...@gmail.com>

> I believe that "the object has been stored if put() returns null" is a
> typo that should be read "the object has been stored if put()  retuns a
> Pointer instance"


yes , that looks like a typo.


> and that the latest "null" could be a bug (it should return 5l or the line
> above should return an error). I gotta take a look at it.


I've reproduced that, the reason last line is returning null is that the
Pointer instance is marked as free (which shouldn't be in my opinion) thus
I think that's a bug (in the put method which actually creates the pointer).
I'll work more on that later today or tomorrow.
Regards,
Tommaso


>
> Cheers,
>     R
>
>
> On Mon, Aug 6, 2012 at 9:52 AM, Christian Moen <ch...@gmail.com>wrote:
>
>> Hello,
>>
>> I'm looking into using Apache DirectMemory and I believe I'm missing
>> something basic that I'm hoping someone can help me understand.
>>
>> I'd like to use DirectMemory as an off-heap key-value store (for
>> gigabytes of data) and I'm having a problem updating the value for a given
>> key.
>>
>> This code illustrates my problem:
>>
>>        CacheService<String, Long> cache = new DirectMemory<String, Long>()
>>             .setNumberOfBuffers(10)
>>             .setSize(1000)
>>             .setInitialCapacity(100000)
>>             .setConcurrencyLevel(4)
>>             .newCacheService();
>>
>>         System.out.println("a : " + cache.retrieve("a"));
>>         System.out.println("a -> 3 : " + cache.put("a", 3L));
>>         System.out.println("a : " + cache.retrieve("a"));
>>         System.out.println("a -> 5 : " + cache.put("a", 5L));
>>         System.out.println("a : " + cache.retrieve("a"));
>>
>> Running it gives this output:
>>
>> a : null
>> a -> 3 : PointerImpl[0, 0] not free
>>  a : 3
>> a -> 5 : PointerImpl[0, 0] not free
>> a : null
>>
>> Hence, the 5 isn't stored in the cache with the above code.  (I'm not
>> sure if 3 is stored properly, either.)
>>
>> The documentation on
>> http://incubator.apache.org/directmemory/simple-usage.html tells me that
>> the object has been stored if put() returns null.  It doesn't in my case,
>> so I'm speculating that memory needs to be provided somehow, but I'm not
>> sure how I should do that.  I can't seem to find details on this in the
>> example or the other documentation available, either.  I've also had a
>> quick look through code and nothing
>>
>> My understanding was that a high-level put() and retrieve() interface was
>> provided by whatever backed CacheService and that memory allocation would
>> be handled by a MemoryManagerService, but I might have misunderstood
>> things.  Guidance is most appreciated.
>>
>> By the way, my POM coordinates are as follows:
>>
>> <dependency>
>> <groupId>org.apache.directmemory</groupId>
>>  <artifactId>directmemory-cache</artifactId>
>> <version>0.1-incubating</version>
>>  </dependency>
>>
>> Notice that I'm using "org.apache.directmemory" instead of
>> "org.apache.directmemory.server" as the documentation suggested, since the
>> latter didn't seem to be valid.
>>
>> Many thanks for any help,
>>
>>
>> Christian
>>
>>
>

Re: Basic DirectMemory usage question

Posted by "Raffaele P. Guidi" <ra...@gmail.com>.
Also the current release is a 0.2 snapshot

On Mon, Aug 6, 2012 at 4:06 PM, Raffaele P. Guidi <
raffaele.p.guidi@gmail.com> wrote:

> I believe that "the object has been stored if put() returns null" is a
> typo that should be read "the object has been stored if put()  retuns a
> Pointer instance" and that the latest "null" could be a bug (it should
> return 5l or the line above should return an error). I gotta take a look at
> it.
>
> Cheers,
>     R
>
>
> On Mon, Aug 6, 2012 at 9:52 AM, Christian Moen <ch...@gmail.com>wrote:
>
>> Hello,
>>
>> I'm looking into using Apache DirectMemory and I believe I'm missing
>> something basic that I'm hoping someone can help me understand.
>>
>> I'd like to use DirectMemory as an off-heap key-value store (for
>> gigabytes of data) and I'm having a problem updating the value for a given
>> key.
>>
>> This code illustrates my problem:
>>
>>        CacheService<String, Long> cache = new DirectMemory<String, Long>()
>>             .setNumberOfBuffers(10)
>>             .setSize(1000)
>>             .setInitialCapacity(100000)
>>             .setConcurrencyLevel(4)
>>             .newCacheService();
>>
>>         System.out.println("a : " + cache.retrieve("a"));
>>         System.out.println("a -> 3 : " + cache.put("a", 3L));
>>         System.out.println("a : " + cache.retrieve("a"));
>>         System.out.println("a -> 5 : " + cache.put("a", 5L));
>>         System.out.println("a : " + cache.retrieve("a"));
>>
>> Running it gives this output:
>>
>> a : null
>> a -> 3 : PointerImpl[0, 0] not free
>>  a : 3
>> a -> 5 : PointerImpl[0, 0] not free
>> a : null
>>
>> Hence, the 5 isn't stored in the cache with the above code.  (I'm not
>> sure if 3 is stored properly, either.)
>>
>> The documentation on
>> http://incubator.apache.org/directmemory/simple-usage.html tells me that
>> the object has been stored if put() returns null.  It doesn't in my case,
>> so I'm speculating that memory needs to be provided somehow, but I'm not
>> sure how I should do that.  I can't seem to find details on this in the
>> example or the other documentation available, either.  I've also had a
>> quick look through code and nothing
>>
>> My understanding was that a high-level put() and retrieve() interface was
>> provided by whatever backed CacheService and that memory allocation would
>> be handled by a MemoryManagerService, but I might have misunderstood
>> things.  Guidance is most appreciated.
>>
>> By the way, my POM coordinates are as follows:
>>
>> <dependency>
>> <groupId>org.apache.directmemory</groupId>
>>  <artifactId>directmemory-cache</artifactId>
>> <version>0.1-incubating</version>
>>  </dependency>
>>
>> Notice that I'm using "org.apache.directmemory" instead of
>> "org.apache.directmemory.server" as the documentation suggested, since the
>> latter didn't seem to be valid.
>>
>> Many thanks for any help,
>>
>>
>> Christian
>>
>>
>

Re: Basic DirectMemory usage question

Posted by "Raffaele P. Guidi" <ra...@gmail.com>.
I believe that "the object has been stored if put() returns null" is a typo
that should be read "the object has been stored if put()  retuns a Pointer
instance" and that the latest "null" could be a bug (it should return 5l or
the line above should return an error). I gotta take a look at it.

Cheers,
    R

On Mon, Aug 6, 2012 at 9:52 AM, Christian Moen <ch...@gmail.com>wrote:

> Hello,
>
> I'm looking into using Apache DirectMemory and I believe I'm missing
> something basic that I'm hoping someone can help me understand.
>
> I'd like to use DirectMemory as an off-heap key-value store (for gigabytes
> of data) and I'm having a problem updating the value for a given key.
>
> This code illustrates my problem:
>
>        CacheService<String, Long> cache = new DirectMemory<String, Long>()
>             .setNumberOfBuffers(10)
>             .setSize(1000)
>             .setInitialCapacity(100000)
>             .setConcurrencyLevel(4)
>             .newCacheService();
>
>         System.out.println("a : " + cache.retrieve("a"));
>         System.out.println("a -> 3 : " + cache.put("a", 3L));
>         System.out.println("a : " + cache.retrieve("a"));
>         System.out.println("a -> 5 : " + cache.put("a", 5L));
>         System.out.println("a : " + cache.retrieve("a"));
>
> Running it gives this output:
>
> a : null
> a -> 3 : PointerImpl[0, 0] not free
> a : 3
> a -> 5 : PointerImpl[0, 0] not free
> a : null
>
> Hence, the 5 isn't stored in the cache with the above code.  (I'm not sure
> if 3 is stored properly, either.)
>
> The documentation on
> http://incubator.apache.org/directmemory/simple-usage.html tells me that
> the object has been stored if put() returns null.  It doesn't in my case,
> so I'm speculating that memory needs to be provided somehow, but I'm not
> sure how I should do that.  I can't seem to find details on this in the
> example or the other documentation available, either.  I've also had a
> quick look through code and nothing
>
> My understanding was that a high-level put() and retrieve() interface was
> provided by whatever backed CacheService and that memory allocation would
> be handled by a MemoryManagerService, but I might have misunderstood
> things.  Guidance is most appreciated.
>
> By the way, my POM coordinates are as follows:
>
> <dependency>
> <groupId>org.apache.directmemory</groupId>
> <artifactId>directmemory-cache</artifactId>
> <version>0.1-incubating</version>
> </dependency>
>
> Notice that I'm using "org.apache.directmemory" instead of
> "org.apache.directmemory.server" as the documentation suggested, since the
> latter didn't seem to be valid.
>
> Many thanks for any help,
>
>
> Christian
>
>