You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cassandra.apache.org by Annu Agrawal <an...@gmail.com> on 2013/03/10 14:29:47 UTC

Problem in running code using thrift api and cassandra

Hi ,

The following program has a loop which reads a value from cassandra column
which is stored in the form of string. In every iteration of the loop it
reads that value converts it in unsigned long and adds 4096 in it . Then
again it inserts this value in cassandra.

The loop stops incrementing after some iterations. I have tried the same
program without inserting in cassandra and it works totally fine.

But the following program works fine till 'size' variable reaches 61440.
After this iteration i.e 61440+4096=65536 the value read from cassandra
continues to be 61440 only untill the loop ends. So this value is not
getting inserted in cassandra.

This program works absolutely fine when debugged. So I am not able to find
where is exactly the problem.
I am deadly stuck up here.. Is there any problem with jvm heap space or
should any changes be made in cassandra.yaml file. Please help..


    #include "../gen-cpp/Cassandra.h"
#include <iostream>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransportUtils.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
#include "base64.h"

using namespace std;
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
using namespace org::apache::cassandra;
using namespace boost;

static string host("127.0.0.1");
static int port= 9160;

//generate timestamp
int64_t getTS()
{
  time_t ltime;
  ltime=time(NULL);
  return (int64_t)ltime;
}

int main()
{
    shared_ptr <TTransport> socket(new TSocket(host, port));
    shared_ptr <TTransport> transport(new TFramedTransport(socket));
    shared_ptr <TProtocol> protocol(new TBinaryProtocol(transport));

    string base64,metadata;
    unsigned long size=0, *sizep;
    int ch;
    sizep=&size;

    CassandraClient client(protocol);
    ColumnPath cpath;
    ColumnParent cp;
    ColumnOrSuperColumn csc;
    Column c1;

    cp.column_family.assign("mycolfamily");
    cp.super_column.assign("");

    cpath.column_family.assign("mycolfamily");
        cpath.__set_column("data");

    transport->open();
    client.set_keyspace("mykeyspace");

    base64= base64_encode(UCCP(sizep),sizeof(*sizep));//converts
unsigned long to ASCII string

    c1.__set_name("data");
    c1.__set_value(base64);
    c1.__set_timestamp(getTS());
    client.insert("mykey", cp, c1,
org::apache::cassandra::ConsistencyLevel::ONE);

    for(ch=0;ch<30;ch++)
    {
        //reading from cassandra
            client.get(csc, "mykey", cpath,
org::apache::cassandra::ConsistencyLevel::ONE);

        metadata = base64_decode(csc.column.value); //converts string
to unsigned long
        memcpy(sizep,metadata.data(),metadata.size());
        sizep = (unsigned long *)sizep;
        cout<<"....\n Read value : "<< *sizep ;

        // incrementing size
        *sizep = *sizep + 4096;

        //writing size in cassandra
        base64= base64_encode(UCCP(sizep),sizeof(*sizep));//converts
unsigned long to ASCII string
        c1.__set_name("data");
        c1.__set_value(base64);
            c1.__set_timestamp(getTS());
        client.insert("mykey", cp, c1,
org::apache::cassandra::ConsistencyLevel::ONE);

        cout<<"\n Written value : "<< *sizep <<"\n\n";
    }
    transport->close();
    return 0;
}



-- 
Thanks,
Annu Agrawal

Re: Problem in running code using thrift api and cassandra

Posted by Annu Agrawal <an...@gmail.com>.
Yes Pushkar.. even i thought so. But if it was a problem then it would not
have been executed while debugging also if i am not wrong.. and moreover
when i exclude cassandra and keep the same logic it works..

On Sun, Mar 10, 2013 at 7:22 PM, Pushkar Prasad <
pushkar.prasad@airtightnetworks.net> wrote:

> Sounds like you are hitting a 16 bit limit someplace.
>
> -----Original Message-----
> From: Annu Agrawal [mailto:annu.agrawal29@gmail.com]
> Sent: 10 March 2013 19:00
> To: dev@cassandra.apache.org
> Subject: Problem in running code using thrift api and cassandra
>
> Hi ,
>
> The following program has a loop which reads a value from cassandra column
> which is stored in the form of string. In every iteration of the loop it
> reads that value converts it in unsigned long and adds 4096 in it . Then
> again it inserts this value in cassandra.
>
> The loop stops incrementing after some iterations. I have tried the same
> program without inserting in cassandra and it works totally fine.
>
> But the following program works fine till 'size' variable reaches 61440.
> After this iteration i.e 61440+4096=65536 the value read from cassandra
> continues to be 61440 only untill the loop ends. So this value is not
> getting inserted in cassandra.
>
> This program works absolutely fine when debugged. So I am not able to find
> where is exactly the problem.
> I am deadly stuck up here.. Is there any problem with jvm heap space or
> should any changes be made in cassandra.yaml file. Please help..
>
>
>     #include "../gen-cpp/Cassandra.h"
> #include <iostream>
> #include <thrift/protocol/TBinaryProtocol.h>
> #include <thrift/transport/TSocket.h>
> #include <thrift/transport/TTransportUtils.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <sys/time.h>
> #include <stdlib.h>
> #include "base64.h"
>
> using namespace std;
> using namespace apache::thrift;
> using namespace apache::thrift::protocol;
> using namespace apache::thrift::transport;
> using namespace org::apache::cassandra;
> using namespace boost;
>
> static string host("127.0.0.1");
> static int port= 9160;
>
> //generate timestamp
> int64_t getTS()
> {
>   time_t ltime;
>   ltime=time(NULL);
>   return (int64_t)ltime;
> }
>
> int main()
> {
>     shared_ptr <TTransport> socket(new TSocket(host, port));
>     shared_ptr <TTransport> transport(new TFramedTransport(socket));
>     shared_ptr <TProtocol> protocol(new TBinaryProtocol(transport));
>
>     string base64,metadata;
>     unsigned long size=0, *sizep;
>     int ch;
>     sizep=&size;
>
>     CassandraClient client(protocol);
>     ColumnPath cpath;
>     ColumnParent cp;
>     ColumnOrSuperColumn csc;
>     Column c1;
>
>     cp.column_family.assign("mycolfamily");
>     cp.super_column.assign("");
>
>     cpath.column_family.assign("mycolfamily");
>         cpath.__set_column("data");
>
>     transport->open();
>     client.set_keyspace("mykeyspace");
>
>     base64= base64_encode(UCCP(sizep),sizeof(*sizep));//converts
> unsigned long to ASCII string
>
>     c1.__set_name("data");
>     c1.__set_value(base64);
>     c1.__set_timestamp(getTS());
>     client.insert("mykey", cp, c1,
> org::apache::cassandra::ConsistencyLevel::ONE);
>
>     for(ch=0;ch<30;ch++)
>     {
>         //reading from cassandra
>             client.get(csc, "mykey", cpath,
> org::apache::cassandra::ConsistencyLevel::ONE);
>
>         metadata = base64_decode(csc.column.value); //converts string
> to unsigned long
>         memcpy(sizep,metadata.data(),metadata.size());
>         sizep = (unsigned long *)sizep;
>         cout<<"....\n Read value : "<< *sizep ;
>
>         // incrementing size
>         *sizep = *sizep + 4096;
>
>         //writing size in cassandra
>         base64= base64_encode(UCCP(sizep),sizeof(*sizep));//converts
> unsigned long to ASCII string
>         c1.__set_name("data");
>         c1.__set_value(base64);
>             c1.__set_timestamp(getTS());
>         client.insert("mykey", cp, c1,
> org::apache::cassandra::ConsistencyLevel::ONE);
>
>         cout<<"\n Written value : "<< *sizep <<"\n\n";
>     }
>     transport->close();
>     return 0;
> }
>
>
>
> --
> Thanks,
> Annu Agrawal
>
>
>


-- 
Thanks,
Annu Agrawal

RE: Problem in running code using thrift api and cassandra

Posted by Pushkar Prasad <pu...@airtightnetworks.net>.
Sounds like you are hitting a 16 bit limit someplace.

-----Original Message-----
From: Annu Agrawal [mailto:annu.agrawal29@gmail.com] 
Sent: 10 March 2013 19:00
To: dev@cassandra.apache.org
Subject: Problem in running code using thrift api and cassandra

Hi ,

The following program has a loop which reads a value from cassandra column
which is stored in the form of string. In every iteration of the loop it
reads that value converts it in unsigned long and adds 4096 in it . Then
again it inserts this value in cassandra.

The loop stops incrementing after some iterations. I have tried the same
program without inserting in cassandra and it works totally fine.

But the following program works fine till 'size' variable reaches 61440.
After this iteration i.e 61440+4096=65536 the value read from cassandra
continues to be 61440 only untill the loop ends. So this value is not
getting inserted in cassandra.

This program works absolutely fine when debugged. So I am not able to find
where is exactly the problem.
I am deadly stuck up here.. Is there any problem with jvm heap space or
should any changes be made in cassandra.yaml file. Please help..


    #include "../gen-cpp/Cassandra.h"
#include <iostream>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransportUtils.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
#include "base64.h"

using namespace std;
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
using namespace org::apache::cassandra;
using namespace boost;

static string host("127.0.0.1");
static int port= 9160;

//generate timestamp
int64_t getTS()
{
  time_t ltime;
  ltime=time(NULL);
  return (int64_t)ltime;
}

int main()
{
    shared_ptr <TTransport> socket(new TSocket(host, port));
    shared_ptr <TTransport> transport(new TFramedTransport(socket));
    shared_ptr <TProtocol> protocol(new TBinaryProtocol(transport));

    string base64,metadata;
    unsigned long size=0, *sizep;
    int ch;
    sizep=&size;

    CassandraClient client(protocol);
    ColumnPath cpath;
    ColumnParent cp;
    ColumnOrSuperColumn csc;
    Column c1;

    cp.column_family.assign("mycolfamily");
    cp.super_column.assign("");

    cpath.column_family.assign("mycolfamily");
        cpath.__set_column("data");

    transport->open();
    client.set_keyspace("mykeyspace");

    base64= base64_encode(UCCP(sizep),sizeof(*sizep));//converts
unsigned long to ASCII string

    c1.__set_name("data");
    c1.__set_value(base64);
    c1.__set_timestamp(getTS());
    client.insert("mykey", cp, c1,
org::apache::cassandra::ConsistencyLevel::ONE);

    for(ch=0;ch<30;ch++)
    {
        //reading from cassandra
            client.get(csc, "mykey", cpath,
org::apache::cassandra::ConsistencyLevel::ONE);

        metadata = base64_decode(csc.column.value); //converts string
to unsigned long
        memcpy(sizep,metadata.data(),metadata.size());
        sizep = (unsigned long *)sizep;
        cout<<"....\n Read value : "<< *sizep ;

        // incrementing size
        *sizep = *sizep + 4096;

        //writing size in cassandra
        base64= base64_encode(UCCP(sizep),sizeof(*sizep));//converts
unsigned long to ASCII string
        c1.__set_name("data");
        c1.__set_value(base64);
            c1.__set_timestamp(getTS());
        client.insert("mykey", cp, c1,
org::apache::cassandra::ConsistencyLevel::ONE);

        cout<<"\n Written value : "<< *sizep <<"\n\n";
    }
    transport->close();
    return 0;
}



-- 
Thanks,
Annu Agrawal