5

I am working with AWS keyspaces and trying to insert data from C# but getting this error."Consistency level LOCAL_ONE is not supported for this operation. Supported consistency levels are: LOCAL_QUORUM". can anyone please help out here.

AWS keyspace

CREATE KEYSPACE IF NOT EXISTS "DevOps"
   WITH REPLICATION={'class': 'SingleRegionStrategy'} ;

Table

CREATE TABLE IF NOT EXISTS "DevOps"."projectdetails" (
"id" UUID PRIMARY KEY,
"name" text,
"lastupdatedtime" timestamp,
"baname" text,
"customerid" UUID)

C# code

 public async Task AddRecord(List<projectdetails> projectDetails)
        {

            try
            {
                if (projectDetails.Count > 0)
                {
                    foreach (var item in projectDetails)
                    {
                        projectdetails projectData = new projectdetails();
                        projectData.id = item.id;
                        projectData.name = item.name;
                        projectData.baname = "Vishal";
                        projectData.lastupdatedtime = item.lastupdatedtime;
                        projectData.customerid = 1;
                        await mapper.InsertAsync<projectdetails>(projectData);
                    }
                }
            }

            catch (Exception e) 
            { 

            }
        }
Alex Ott
  • 80,552
  • 8
  • 87
  • 132
virendra parade
  • 141
  • 2
  • 12

1 Answers1

5

The error clearly says that you need to use correct consistency level LOCAL_QUORUM instead of the LOCAL_ONE that is used by default. AWS documentation says that for write operations, it's only the consistency level supported. You can set consistency level by using the version of InsertAsync that accepts the CqlQueryOptions, like this (maybe create instance of the query options only once, during initialization of the application):

mapper.InsertAsync<projectdetails>(projectData, 
  new CqlQueryOptions().SetConsistencyLevel(ConsistencyLevel.LocalQuorum))
Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • 9
    I am amazed at how many nuances there are to using AWS Managed Cassandra. In fact, they should just call it "AWS Nuanced Cassandra." LOL – Aaron Jun 08 '20 at 17:10
  • 2
    frankly speaking, DataStax Astra also has such requirement - you can't use LOCAL_ONE for writing... But if I remember correctly, driver should automatically adjust it when detecting that it's using secure bundle – Alex Ott Jun 08 '20 at 17:19