1

I got an error when I have second execute

All host(s) tried for query failed. First host tried, 127.0.0.1:9042: 
ResponseError: Not enough replicas available for query at consistency 
QUORUM (2 required but only 1 alive). See innerErrors.

and i tried many thing to fixed this but nothing help

I have tried to change replication class from simplestartegy to networktopologystrategy also change replication factor to 3 but it doesn't work too.

this is my code main.js :

const cqsql = require('./cqlfunction')
let insert_cassandra = async () => {
  try {
   let get_id = `SELECT next_id FROM ids WHERE id_name = 'person_id'`
   let last_id = await cqsql.cql_getofdb(get_id)
   let next_id = last_id[0].next_id
   let update_id = `UPDATE ids SET next_id = ${next_id + 1} WHERE id_name = 
   'person_id' IF next_id = ` + next_id
   let result = await cqsql.cql_execute(update_id)
   console.log(result);
} catch (error) {
   console.log(error);
   debugger
   process.exit()
  }
}
insert_cassandra()

cqlfunction.js :

const cassandra = require('cassandra-driver');
const client = new cassandra.Client({ contactPoints: ['127.0.0.1'], localDataCenter: 'datacenter1', keyspace: 'javafrm'});

exports.cql_getofdb = async (query) => {
    try {
        // await client.connect()
        let result1 = await client.execute(query)
         if (result1.rowLength > 0) {
            return result1.rows
        } else {
            return []
        }
    } catch (error) {
        debugger
        console.error(error);
        return error
    }
}

exports.cql_execute = async (query) => {
    try {
        // await client.connect()
        debugger
        let result1 = await client.execute(query)
        return {}
    } catch (error) {
        debugger
        console.error(error);
        return error
    }
}
Seaty Sw
  • 15
  • 5
  • see this link: https://stackoverflow.com/questions/27974911/not-enough-replica-available-for-query-at-consistency-one-1-required-but-only-0 – mohammad javad ahmadi Sep 05 '19 at 06:42
  • I see you're connecting to 127.0.0.1. Do you just have the one node? If so, you'll want to keep RF=1 and not query at anything other than ONE as well. – Aaron Sep 05 '19 at 12:16

1 Answers1

1

Instead of changing the replication, which is going to give resilience to your database, you may want to try different consistency levels.

The select and update operations consider as an atomic operation is also known as a Compare and Set operation (CAS), which you can achieve with a Lightweight transaction.

Carlos Monroy Nieblas
  • 2,225
  • 2
  • 16
  • 27