Skip to content

Tarantool pg connector is freezes at many queryes #9

Description

@agent-0007

Tarantool pg connector is freezes at many query with new connect.

This code freezes tarantool:

local function psql_data(query, limit)
    log.error("Connection to pg host: "..pg_host.." database: "..pg_database);
    local conn = pg.connect({host = pg_host, user = pg_user, password = pg_password, db = pg_database})
    log.error("Execute query: "..query.."limit: "..limit)
    local tuples = conn:execute(query, limit)
    return tuples   
end

local function parse_database_response(query, result)
    log.error("query: "..query)
    local db_res = psql_data(query, 10000)
    if db_res then
        for k, record in pairs (db_res) do
            local tuple = {record['id'], record['email'], record['req_hash'], record['host'], record['log_path'], record['log_message_type'], record['srv_timestamp'], record['grepmaillog']}
            table.insert(result, tuple)
        end
    end
    return result
end

local first_letter = "a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 _"
local second_letter = "a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 _tir_ _dot_ _ _dog_"
local res = {}
for k in string.gmatch(first_letter,'%S+') do
    for j in string.gmatch(second_letter,'%S+') do
        prefix = k..j..'_'..prefix_day
        local query = "SELECT * FROM touch_logs_"..prefix.." WHERE req_hash='"..req_hash.."' ORDER BY srv_timestamp DESC"
        res = parse_database_response(query, res)
    end
end

This code works propely:

    local conn = pg.connect({host = pg_host, user = pg_user, password = pg_password, db = pg_database})
    local first_letter = "a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 _"
    local second_letter = "a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 _tir_ _dot_ _ _dog_"
    for k in string.gmatch(first_letter,'%S+') do
        local need_break = 0
        for j in string.gmatch(second_letter,'%S+') do
            prefix = k..j..'_'..prefix_day
            local query = "SELECT * FROM touch_logs_"..prefix.." WHERE req_hash='"..req_hash.."' ORDER BY srv_timestamp DESC"
            --log.error("Execute query: "..query)
            local db_res = conn:execute(query, 10000)
            if next(db_res) ~= nil then
                log.error("success query: "..query)
                for k, record in pairs (db_res) do
                    log.error('FOUND!!!!!!!')
                    log.error(prefix)
                    log.error(k)
                    log.error(j)
                    log.error(record)
                    local tuple = {record['id'], record['email'], record['req_hash'], record['host'], record['log_path'], record['log_message_type'], record['srv_timestamp'], record['grepmaillog']}
                    table.insert(res, tuple)
                end
                --db_res = {}
                --need_break = 1
                --break
            end

--          if (res and res.getn > 0) then
--              need_break = 1
--              break
--          end
        end
        if (need_break == 1) then
            break
        end
    end

Onece moment i think that my database is suck, but this code on perl works fine too (database not suck):

#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use DBD::Pg;
use Time::Local;
use Data::Dumper;

# pgsql
my $db_host     = 'XXXXXXXXXXX';
my $db_database = 'XXXXXXXXXXX';
my $db_user     = 'XXXXXXXXX';
my $db_pass     = 'XXXXXXXXXXXX';
my @last_days_array = ();

sub push_last_day {
    my ($last_day, $last_days_array) = @_;
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime($last_day);
    push @{$last_days_array}, $mday;
    return @{$last_days_array};
}

my ($sec, $min, $hour, $mday, $mon, $year) = localtime();
my $last_day_1 = timelocal(0, 0, 12, $mday, $mon, $year);
my $last_day_2 = timelocal(0, 0, 12, $mday, $mon, $year) - 1*24*60*60;
#my $last_day_3 = timelocal(0, 0, 12, $mday, $mon, $year) - 2*24*60*60;
@last_days_array = push_last_day($last_day_1, \@last_days_array);
#@last_days_array = push_last_day($last_day_2, \@last_days_array);
#@last_days_array = push_last_day($last_day_3, \@last_days_array);

my $req_hash = '4b6b4fcdba';
my $dbh = DBI->connect("dbi:Pg:dbname=$db_database;host=$db_host", $db_user, $db_pass) or die("Can't connect to database!");

foreach my $letter1 ( (('a'..'z'), (0..9), ("_")) ) {
    foreach my $letter2 ( (('a'..'z'), ("_dot_", "_tir_", "_", "_dog_"), (0..9)) ) {
        foreach my $day (@last_days_array) {
            my $name = "touch_logs_".$letter1.$letter2.'_'.$day;
            my $sth = $dbh->prepare("SELECT * FROM $name WHERE req_hash = ?")
                or die "Couldn't prepare statement: " . $dbh->errstr;
      $sth->execute($req_hash)             # Execute the query
        or die "Couldn't execute statement: " . $sth->errstr;

      # Read the matching records and print them out          
      while (my @data = $sth->fetchrow_array()) {
        my $id = $data[1];
        print "\t$id\n";
        last;
      }

      $sth->finish;
#           print "TRUNCATE $name RESTART IDENTITY\n";
        }
    }
}

# diconnect
$dbh->disconnect;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions