fix(linux): fix convertation of db under linux system #152

This commit is contained in:
Alexey Kasyanchuk 2021-08-10 13:54:27 +03:00
parent ae6fabc82f
commit 7225af81d0

View File

@ -236,6 +236,7 @@ module.exports = async (callback, dataDirectory, onClose, params = {}) => {
const optimizeResolvers = {} const optimizeResolvers = {}
let needConvertation = false;
sphinx.stdout.on('data', (data) => { sphinx.stdout.on('data', (data) => {
logT('sphinx', `sphinx: ${data}`) logT('sphinx', `sphinx: ${data}`)
@ -244,7 +245,12 @@ module.exports = async (callback, dataDirectory, onClose, params = {}) => {
return return
if (data.includes('accepting connections')) { if (data.includes('accepting connections')) {
logT('sphinx', 'catched sphinx start') logT('sphinx', 'catched sphinx start');
// convertation for linux after start
if(needConvertation) {
sphinx.convertDatabase();
return;
}
if(callback) if(callback)
callback() callback()
} }
@ -256,7 +262,7 @@ module.exports = async (callback, dataDirectory, onClose, params = {}) => {
if(data.includes('indexes with meta prior to v.14 are no longer supported')) if(data.includes('indexes with meta prior to v.14 are no longer supported'))
{ {
sphinx.convertDatabase() needConvertation = true;
} }
if(windowsEncodingFix && data.includes('failed to parse config file')) if(windowsEncodingFix && data.includes('failed to parse config file'))
@ -296,7 +302,10 @@ module.exports = async (callback, dataDirectory, onClose, params = {}) => {
sphinx.replaceOnClose = true // sometime we don't want to call default callback sphinx.replaceOnClose = true // sometime we don't want to call default callback
if (!sphinx.isExternal) if (!sphinx.isExternal)
{
logT('sphinx', `stoping with sphinx stopwait`);
exec(`"${sphinxPath}" --config "${config}" --stopwait`) exec(`"${sphinxPath}" --config "${config}" --stopwait`)
}
else else
{ {
logT('sphinx', `ignoring sphinx closing because external sphinx instance`) logT('sphinx', `ignoring sphinx closing because external sphinx instance`)
@ -312,6 +321,7 @@ module.exports = async (callback, dataDirectory, onClose, params = {}) => {
}) })
sphinx.convertDatabase = async () => { sphinx.convertDatabase = async () => {
logT('sphinx', 'found old database, starting convertiong process...');
if(sphinx.isExternal) if(sphinx.isExternal)
return return
@ -319,6 +329,8 @@ module.exports = async (callback, dataDirectory, onClose, params = {}) => {
return return
sphinx.fixing = true sphinx.fixing = true
logT('sphinx', 'run database convertation...');
// close db // close db
await new Promise((resolve) => { await new Promise((resolve) => {
sphinx.stop(resolve, true) sphinx.stop(resolve, true)
@ -339,7 +351,12 @@ module.exports = async (callback, dataDirectory, onClose, params = {}) => {
await new Promise((resolve) => { await new Promise((resolve) => {
const oldSphinxPath = path.resolve(appPath('searchd.v2')) const oldSphinxPath = path.resolve(appPath('searchd.v2'))
logT('dbconverter', 'old sphinx', oldSphinxPath); logT('dbconverter', 'old sphinx', oldSphinxPath);
const oldSphinxEXE = spawn(oldSphinxPath, ['--config', config]); let options = ['--config', config];
if(!(/^win/.test(process.platform)))
{
options.push('--nodetach')
}
const oldSphinxEXE = spawn(oldSphinxPath, options);
const tables = []; const tables = [];
oldSphinxEXE.stdout.on('data', async (data) => { oldSphinxEXE.stdout.on('data', async (data) => {