3

I have a lambda :

'use strict';
const config = require('./redshift_config');
const pg = require('pg');
const redshift_conn = `pg://${config.user}:${config.password}@${config.host}/${config.database}`;

function move_to_disable_tables(users_ids, context) {
  const client = new pg.Client(redshift_conn);
  const query = `
  INSERT INTO disable_connections
  SELECT *
  FROM active_connections
  WHERE user_id
     IN (${users_ids});
  DELETE FROM active_connections
  WHERE user_id
     IN (${users_ids});
  INSERT INTO disable_downloads
  SELECT *
  FROM active_downloads
  WHERE user_id
     IN (${users_ids});
  DELETE FROM active_downloads
  WHERE user_id
     IN (${users_ids});
  `;

  client.connect(function(err) {
    if (err) {
      return context.fail(`Failed to connect: ${err}`);
    }
    client.query(query, function (err) {
      if (err) {
        return context.fail(`Failed to run query: ${err}`);
      }
      context.succeed(`Successfully transferred.`);
      client.end(function (err) {
        if (err) return context.fail(`Error in ending query: ${err}`);
      });
    });
  });
}

exports.handler = function(event, context) {
  move_to_disable_tables(event.users_ids, context);
};

But I get sometimes : "Failed to run query: error: 1023"

The error you are getting occurs whenever you run concurrent transactions is such a way that Redshift's serializable isolation is violated. See http://docs.aws.amazon.com/redshift/latest/dg/c_serial_isolation.html for a description of what this means.

From : https://forums.aws.amazon.com/message.jspa?messageID=443644#443644

Before the sql was warped into a block BEGIN; END; but I removed it to fix the issue but it still occurs. Any ideas?

Does this 4 queries can fail in concurrency?

The lambda doesn't run very often :

screenshot

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.