Проблема при асинхронном импорте
akudelka opened this issue · 10 comments
script:
var libs = process.cwd() + '/libs/';
var fs = require('fs');
var readline = require('linebyline');
var TarantoolConnection = require('tarantool-driver');
var conn = new TarantoolConnection({port: 3301, log: false});
var inserted = 0;
conn.connect()
.then(function() {
var rl = readline('./libs/model/segment/dictionary.csv');
rl.on('line', function(line, lineCount) {
if (lineCount === 1) return;
if (lineCount % 1000 === 0){
console.log('readed :', lineCount);
}
var tags = line.split(';');
conn.insert('tags',
[parseInt(tags[0]), tags[1], parseInt(tags[2]), tags[5], parseInt(tags[6]), parseFloat(tags[3]), parseInt(tags[4]), 7, 5, 1]
).then(function(){
inserted++;
if (inserted % 1000 === 0){
console.log('inserted to db :', inserted);
}
}).catch(function (e) {
console.log(e);
})
});
rl.on("end", function(){
});
}).catch(function (e) {
console.log(e);
});
console output:
readed : 1000
readed : 2000
inserted to db : 1000
inserted to db : 2000
readed : 3000
readed : 4000
inserted to db : 3000
inserted to db : 4000
readed : 5000
readed : 6000
inserted to db : 5000
inserted to db : 6000
readed : 7000
readed : 8000
inserted to db : 7000
inserted to db : 8000
readed : 9000
readed : 10000
inserted to db : 9000
inserted to db : 10000
readed : 11000
readed : 12000
inserted to db : 11000
inserted to db : 12000
readed : 13000
inserted to db : 13000
readed : 14000
readed : 15000
inserted to db : 14000
inserted to db : 15000
readed : 16000
readed : 17000
inserted to db : 16000
Error
at TarantoolConnection._processResponse (/home/akudelka/home/tam.by/ad.tam.by/server/node_modules/tarantool-driver/lib/connection.js:680:18)
at TarantoolConnection.onData (/home/akudelka/home/tam.by/ad.tam.by/server/node_modules/tarantool-driver/lib/connection.js:406:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:191:7)
at readableAddChunk (_stream_readable.js:178:18)
at Socket.Readable.push (_stream_readable.js:136:10)
at TCP.onread (net.js:561:20)
readed : 18000
readed : 19000
readed : 20000
readed : 21000
readed : 22000
В файле более 5 млн записей
Короче проблема в том что видимо закрывается соединение и на этом все. Есть ли способ решить данную проблему? Заранее спасибо.
"name": "tarantool-driver",
...
"repository": {
"type": "git",
"url": "git+https://github.com/KlonD90/node-tarantool-driver.git"
},
...
"version": "2.0.5"
tarantool 1.7.
Может есть какая нить конфигурация для того чтобы коннект не закрывался? Еще пробовал конкретно эту запись пропускать, но все равно на след затык.
box.cfg {
listen = 3311,
log = 'tarantool.log',
checkpoint_interval = 3600,
checkpoint_count = 5,
log_level = 3,
memtx_memory = 2056 * 1024 *1024
}
if not s then
s = box.schema.space.create('tags')
-- Первичный индекс
s:create_index('primary', {type = 'TREE', parts = {1, 'INT'}})
s:create_index('tag', {type = 'TREE', unique = false, parts = {2, 'STR'}})
s:create_index('tag_id', {type = 'TREE', unique = false, parts = {3, 'INT'}})
s:create_index('segment', {type = 'TREE', unique = false, parts = {4, 'STR'}})
s:create_index('segment_id', {type = 'TREE', unique = false, parts = {5, 'INT'}})
s:create_index('tag_segment_level', {type = 'TREE', unique = true, parts = {3, 'INT', 5, 'INT', 7, 'INT'}})
end
При чем, как ни странно но записи в продолжают добавляться. Т.е. когда в тарантул консоли считаю количество - записи растут, но в консоли скрипта уже ничего не выводится.
PS посмотрел файл tarantool-driver/lib/connection.js, там при ошибке и еще каких то условиях вызывается socket.destroy().
npm install --save tarantool-driver
NodeAPI@1.0.0 ...
└── tarantool-driver@2.0.5
Попробуйте версию 1.1.1 или 1.1.0
И можете содержимое dictionary скинуть мы у себя воспроизведем.
или 1.1.2
Заработало на версии 1.1.2. Спасибо большое! Надеюсь в версии 2+ удастся воспроизвести и пофиксить.