Friday, December 14, 2012

Insert via batch_mutate using Aquiles, Delete, insert again - result is empty

Problem,

using C# Cassandra Client Aquiles to insert some data to cassandra, then delete it using the cassandra CLI. after that insert the same data back again, result is empty.

C# code,

using Apache.Cassandra;
using Aquiles.Cassandra10;
using Aquiles.Core.Cluster;
using Aquiles.Helpers;
using Aquiles.Helpers.Encoders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CassandraClient = Apache.Cassandra.Cassandra.Client;

namespace CSharpClient
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().PopulateDataWithBatchMutate();
            Console.WriteLine("Finished");

        }

        private const string CLUSTERNAME = "Test Cluster";
        private const string KEYSPACENAME = "exampleKeyspace";
        private const string COLUMNFAMILYNAME = "exampleCF";

        private void PopulateDataWithBatchMutate()
        {
            Dictionary<byte[], Dictionary<string, List<Mutation>>> mutation_map = new Dictionary<byte[], Dictionary<string, List<Mutation>>>();
            for (long i = 0; i < 1; i++)
            {
                byte[] key = ByteEncoderHelper.LongEncoder.ToByteArray(i);
                Dictionary<string, List<Mutation>> cfMutation = new Dictionary<string, List<Mutation>>();
                List<Mutation> mutationList = new List<Mutation>();
                for (long j = 0; j < 2; j++)
                {
                    string columnName = String.Format("Data-{0:0000000000}", j);
                    Mutation mutation = new Mutation()
                    {
                        Column_or_supercolumn = new ColumnOrSuperColumn()
                        {
                            Column = new Column()
                            {
                                Name = ByteEncoderHelper.UTF8Encoder.ToByteArray(columnName),
                                   Timestamp = UnixHelper.UnixTimestamp,
                                 Value = ByteEncoderHelper.LongEncoder.ToByteArray(j),
                            },
                        },
                    };
                    mutationList.Add(mutation);
                }
                cfMutation.Add(COLUMNFAMILYNAME, mutationList);
                mutation_map.Add(key, cfMutation);
            }

            ICluster cluster = AquilesHelper.RetrieveCluster(CLUSTERNAME);
            cluster.Execute(new ExecutionBlock(delegate(CassandraClient client)
            {
                client.batch_mutate(mutation_map, ConsistencyLevel.ONE);
                return null;
            }), KEYSPACENAME);
        }
    }
}

     1st insert,
        Data is there,
image

     then delete this row manually via cli, data is deleted, no problem so far.
image

then run the code again to do another insert for same data.( STILL NO DATA. that’s the problem.)
image

Why?
C# get incorrect timestamp, which is always older then the correct cassandra. so older insertion will always be ignored once there is one newer delete.

change the timestamp to the following code, will fix this issue.
image

No comments:

 
Locations of visitors to this page