Basic Questions on MEMBASE.
I am new to Membase.
I see that Membase is excellent with noSQL.
1) will there be an schema files that need to be defined? is there a concept of schema files?
like : SQL.
2) Everything is like hash table so I think there might not be please correct me.
I am writing the following program
3)
String s = words[i];
Object o = cache.set(s, 360000, i);
when I try to read the contents from a different program using the same key: I get NULL
Object o = cache.get(s1);
as I kept set to 360000 seconds I feel that data should be persistent, but it is not.
can you please let me know what I am missing?
If I try to put and get in the same program it works.
Thanks a lot Mike.
Here is the program:
This program is working successfully.
===
MemcachedClient cache = new MemcachedClient(new InetSocketAddress(server, port));
cache.flush(); // clean start
String[] words = { "sample1","sample2","sample3","sample4","sample5","sample6"};
for (int i = 0; i < MAX; i++)
{
String s = words[i];
Object o = cache.set(s, 360000, i);
System.out.println("cache put : " + s + " : " + i + ", result " + o);
}
===
This program alwaays gives output as null
MemcachedClient cache = new MemcachedClient(new InetSocketAddress(server, port));
cache.flush(); // clean start
String[] words = { "sample1","sample2","sample3","sample4","sample5","sample6"};
for (int i = 0; i < MAX; i++)
{
String s = words[i];
Object o = cache.get(s);
System.out.println("Cache get : " + s + " : " + o);
}
==
The issue here is that you are using the flush function in you get program. When you run the set program you call flush before you set any keys in Membase. This is good practice for testing because you are making sure that your cluster has a fresh start. This issue though is that when you run the get program, before you get any values you call the flush function again and flush all of the data out of your server. Then when you call get on the keys that you set in the set program you can't find any of them because you just deleted everything. Removing the flush call in your get program will make everything work correctly.
Also, when you are running in production I would never have the flush function called anywhere in my application. That way in case something you don't have to worry about all of your data being deleted.
Let me know if you have any other issues.
Thanks Mike.
I still have issues after removing the flush.
I am not able to retrieve all the data from the database.
some values are missing.
Inserting
========
2011-06-02 14:43:58.233 INFO net.spy.memcached.MemcachedConnection: Added {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, inter
2011-06-02 14:43:58.233 INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@5afd29
cache put : sample1 : 0, result net.spy.memcached.internal.OperationFuture@94948a
cache put : sample2 : 1, result net.spy.memcached.internal.OperationFuture@16f8cd0
cache put : sample3 : 2, result net.spy.memcached.internal.OperationFuture@85af80
cache put : sample4 : 3, result net.spy.memcached.internal.OperationFuture@c51355
cache put : sample5 : 4, result net.spy.memcached.internal.OperationFuture@787171
Time for 5 puts is 16 ms
2011-06-02 14:43:58.249 INFO net.spy.memcached.MemcachedClient: Shut down memcached client
Retrival
========
2011-06-02 14:44:18.767 INFO net.spy.memcached.MemcachedConnection: Added {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, inter
2011-06-02 14:44:18.767 INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@5afd29
Cache get : sample1 : 0
Cache get : sample2 : 1
Cache get : sample3 : 2
Cache get : sample4 : null
Cache get : sample5 : null
Time for 5 puts is 15 ms
2011-06-02 14:44:18.782 INFO net.spy.memcached.MemcachedClient: Shut down memcached client
Can you please let me know what I am missing
Your code looks correct and I have never seen this an issue like this before. I'm going to look a little bit deeper though. In the meantime can you provide me with the version number of spymemcached that you are using? Also, what version of Membase are you using?
Looking at your code again I noticed that you don't check what is returned to you when you do sets. Instead of printing out the Object (which is an OperationFuture) call the get function and print out the boolean value to see if the set succeeded. It's possible for some reason that the set failed and as a result when you do the get Membase says it can't find the key.
This can be done by changing the line
Object o = cache.set(s, 360000, i);
to
boolean o = cache.set(s, 360000, i).get().booleanValue();
If your sets are returning true and your still having issues, here's something else you can try. The issue might be that you have created a sort of race condition by doing the operations in the order you do. Right now you do a flush and then some sets. Since all of these operations are asynchronous it is possible that even though you do your sets after the flush that one of the sets actually beats the flush to Membase and then the flush comes along and deletes everything causing one of your keys to not be found when you run you get program. Try removing the flush call from your code and flushing Membase manually before you run your set program. You can do this with telnet:
telnet 11211
then type
flush_all
I ran your program a bunch of times and only saw the results you posted once so my guess is that this is the result of something strange happening with the order in which Membase receives operations. If the above suggestions still don't seem to get things fixed let me know and provide as much information about your environment as possible so I can try to best reproduce the issue.
Thanks a lot Mike for the reply.
I am testing that now with your suggestions.
between,
I remove cache.flush(); from my program
Please see the results.
luckily I did not close my windows.
so I have all the results.
This is very intermitted some times I see all the values spme times I dont see.
I created a bucket and tried in that backet all this.
once the retrival is success all subsequent times it will be true.
After retrival1 I did not do any INSERT.
2) you suggested me to do telnet 11212.
can you please tell me the complete command in Windows?
3) How to debug things like this?
I see: C:\Program Files\Membase\Server\logs
there are some files in a different format.
Read me asks me to use: Use dump_logs.bat to dump them as text.
where can I get that tool? will that help me in debugging?
Insert:
=======
2011-06-02 19:28:49.514 INFO net.spy.memcached.MemcachedConnection: Added {QA sa=localhost/127.0.0.1:11212, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, i
2011-06-02 19:28:49.514 INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@1a2961b
cache put : sample1 : 0, result net.spy.memcached.internal.OperationFuture@a401c2
cache put : sample2 : 1, result net.spy.memcached.internal.OperationFuture@85af80
cache put : sample3 : 2, result net.spy.memcached.internal.OperationFuture@c51355
cache put : sample4 : 3, result net.spy.memcached.internal.OperationFuture@787171
cache put : sample5 : 4, result net.spy.memcached.internal.OperationFuture@15fea60
cache put : sample6 : 5, result net.spy.memcached.internal.OperationFuture@1457cb
Time for 6 puts is 16 ms
2011-06-02 19:28:49.530 INFO net.spy.memcached.MemcachedClient: Shut down memcached client
Retrive1:
========
C:\Documents and Settings\sreeramk\Desktop>java membase
2011-06-02 19:29:09.218 INFO net.spy.memcached.MemcachedConnection: Added {QA sa=localhost/127.0.0.1:11212, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, i
2011-06-02 19:29:09.218 INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@12d03f9
Cache get : sample1 : 0
Cache get : sample2 : 1
Cache get : sample3 : null
Cache get : sample4 : null
Cache get : sample5 : null
Cache get : sample6 : null
Time for 6 puts is 15 ms
2011-06-02 19:29:09.233 INFO net.spy.memcached.MemcachedClient: Shut down memcached client
==
complied with your suggestion.
boolean o = cache.set(s, 360000, i).get().booleanValue();
Retrive2:
========
2011-06-02 21:11:14.163 INFO net.spy.memcached.MemcachedConnection: Added {QA sa=localhost/127.0.0.1:11212, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, i
2011-06-02 21:11:14.163 INFO net.spy.memcached.MemcachedConnection: Connection state changed for sun.nio.ch.SelectionKeyImpl@5afd29
cache put : sample1 : 0, result true
cache put : sample2 : 1, result true
cache put : sample3 : 2, result true
cache put : sample4 : 3, result true
cache put : sample5 : 4, result true
cache put : sample6 : 5, result true
Time for 6 puts is 32 ms
2011-06-02 21:11:14.195 INFO net.spy.memcached.MemcachedClient: Shut down memcached client
1) Ok, I think what is happening is the second thing I mentioned in the previous post. I think some of your sets are beating the flush to Membase so when the flush actually gets there it deletes all the keys (including the sets that beat the flush). Try changing the line of code that does the flush from
cache.flush();
to
cache.flush().get()
This will cause the flush to block until it actually finishes. Then the sets will send and I think this will fix you problems.
2) You can download telnet and I think there are instructions online from microsoft on how to install it correctly.
http://windows.microsoft.com/en-US/windows-vista/Telnet-frequently-asked...
I type the command wrong also. Its telnet ip_address port. So if Membase is on localhost you type:
telnet localhost 11211
3) At this point I don't think this is actually a bug in Spymemcached or Membase so I don't think there would be anything interesting in the logs. I'm pretty sure we also don't log individual operations in the logs because this would cause our logs to grow to enormous sizes. Using a packet trace like Wireshark will help. That's what I did to try to figure out what was going on.
Thanks again Mike.
1) I am not using flush in my program at all.
As you said it will delete all the data in the database I am not using that.
If I use that in my GET Program , I wil not be getting any data...
2)I am able to login to telnet.
I got a ERROR prompt and I was able to execute that command.
Also, what all we use this telnet prompt ?
3)ok. what exactly are those logs at: C:\Program Files\Membase\Server\logs
How are they useful?
2) I don't quite understand your question the way it is written, but I'll try to answer. Telnet is a text is a protocol used for text oriented communications and it just so happens that memcached and Membase support an ascii protocol. As a result you can use telnet to do the same thing you are doing with Spymemcached. flush_all is the ascii command to flush all of your data out of Membase. See here for a list of other commands and how you can use them in telnet.
http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt
3) These logs contain information about what is happening in different components in Membase. If you are having server crashes or things aren't working correctly in the server (Ex. Rebalancing a node out of the cluster fails. Replication doesn't seem to be an issue) these logs can be very useful in debugging the issue.
Thanks Mike This clears my questions.
1) There is no schema definition. That's one thing that makes NoSQL so great.
With that said, one thing I like to do when I use membase is to have a naming convention for keys. For example lets say we are modeling a farm game.
user00001.sheeps, 4
user00001.cows, 3
user00001.barn.windows, 2
user00001.barn.color, red
2) Yes, you we hash all of the keys into different vbuckets and we have a vbucket map that tells the client which server to send the request to.
3) You seem to be doing everything fine and I cannot reproduce this issue so far. If you post your code here I can take a look at it and see if I can reproduce the issue with your code. Also, are the programs running at the same time or one after another?