Skip to content
Permalink
Browse files

fixed #861 crash of daemon on ALTER index with blob attributes, ie re…

…move of plain attribute at RT index with MVA; added cases to test 378
  • Loading branch information...
tomatolog committed May 21, 2019
1 parent 558c632 commit 230c321e277514b191629538eb3f02d219113d95
Showing with 83 additions and 1 deletion.
  1. +1 −0 src/attribute.cpp
  2. +13 −1 src/sphinxrt.cpp
  3. +1 −0 test/test_378/model.bin
  4. +68 −0 test/test_378/test.xml
@@ -633,6 +633,7 @@ int64_t sphCopyBlobRow ( CSphTightVector<BYTE> & dDstPool, const CSphTightVector

void sphAddAttrToBlobRow ( const CSphRowitem * pDocinfo, CSphTightVector<BYTE> & dBlobRow, const BYTE * pPool, int nBlobs )
{
dBlobRow.Resize ( 0 );
if ( nBlobs )
{
const BYTE * pOldRow = pPool + sphGetBlobRowOffset ( pDocinfo );
@@ -6582,6 +6582,17 @@ bool RtIndex_c::AddRemoveAttribute ( bool bAdd, const CSphString & sAttrName, ES
if ( !m_dDiskChunks[iDiskChunk]->AddRemoveAttribute ( bAdd, sAttrName, eAttrType, sError ) )
sphWarning ( "%s attribute to %s.%d: %s", bAdd ? "adding" : "removing", m_sPath.cstr(), dChunkNames[iDiskChunk], sError.cstr() );

bool bHadBlobs = false;
for ( int i = 0; i < m_tSchema.GetAttrsCount(); i++ )
bHadBlobs |= sphIsBlobAttr ( m_tSchema.GetAttr(i).m_eAttrType );

bool bHaveBlobs = false;
for ( int i = 0; i < tNewSchema.GetAttrsCount(); i++ )
bHaveBlobs |= sphIsBlobAttr ( tNewSchema.GetAttr(i).m_eAttrType );

bool bBlob = sphIsBlobAttr ( eAttrType );
bool bBlobsModified = bBlob && ( bAdd || bHaveBlobs==bHadBlobs );

// now modify the ramchunk
for ( RtSegment_t * pSeg : m_dRamChunks )
{
@@ -6603,7 +6614,8 @@ bool RtIndex_c::AddRemoveAttribute ( bool bAdd, const CSphString & sAttrName, ES
sphWarning ( "%s attribute to %s: %s", bAdd ? "adding" : "removing", m_sPath.cstr(), sError.cstr() );

pSeg->m_dRows.SwapData(dSPA);
pSeg->m_dBlobs.SwapData(dSPB);
if ( bBlob || bBlobsModified )
pSeg->m_dBlobs.SwapData(dSPB);
}

// fixme: we can't rollback at this point
@@ -0,0 +1 @@
a:1:{i:0;a:6:{i:0;a:2:{s:8:"sphinxql";s:81:"INSERT INTO rt VALUES (1, 'text', 11, 12, 13, (101, 102), (201, 202), (301, 302))";s:14:"total_affected";i:1;}i:1;a:3:{s:8:"sphinxql";s:16:"select * from rt";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:7:{s:2:"id";s:1:"1";s:5:"attr1";s:2:"11";s:5:"attr2";s:2:"12";s:5:"attr3";s:2:"13";s:2:"m1";s:7:"101,102";s:2:"m2";s:7:"201,202";s:2:"m3";s:7:"301,302";}}}i:2;a:2:{s:8:"sphinxql";s:32:"ALTER TABLE rt drop column attr3";s:14:"total_affected";i:0;}i:3;a:3:{s:8:"sphinxql";s:16:"select * from rt";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:6:{s:2:"id";s:1:"1";s:5:"attr1";s:2:"11";s:5:"attr2";s:2:"12";s:2:"m1";s:7:"101,102";s:2:"m2";s:7:"201,202";s:2:"m3";s:7:"301,302";}}}i:4;a:2:{s:8:"sphinxql";s:29:"ALTER TABLE rt drop column m3";s:14:"total_affected";i:0;}i:5;a:3:{s:8:"sphinxql";s:16:"select * from rt";s:10:"total_rows";i:1;s:4:"rows";a:1:{i:0;a:5:{s:2:"id";s:1:"1";s:5:"attr1";s:2:"11";s:5:"attr2";s:2:"12";s:2:"m1";s:7:"101,102";s:2:"m2";s:7:"201,202";}}}}}
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<test>

<name>ALTER at index MVA</name>

<config>
indexer
{
mem_limit = 16M
}

searchd
{
<searchd_settings/>
workers = threads

}

source src
{
type = mysql
<sql_settings/>
sql_query = SELECT id, gid, title FROM test_table
sql_attr_uint = gid
}

index test
{
source = src
path = <data_path/>/test
}

index rt
{
type = rt
path = <data_path/>/rt
rt_field = title
rt_attr_uint = attr1
rt_attr_uint = attr2
rt_attr_uint = attr3
rt_attr_multi = m1
rt_attr_multi = m2
rt_attr_multi = m3
}

</config>

<db_create>
CREATE TABLE `test_table` (
`id` int(11) NOT NULL,
`gid` int(11) NOT NULL,
`title` varchar(255) NOT NULL
);
</db_create>
<db_drop>DROP TABLE IF EXISTS `test_table`;</db_drop>
<db_insert>INSERT INTO `test_table` VALUES (1,1,'test one')</db_insert>

<sphqueries>
<!-- regression crash on add \ remove plain attribute at index with blobs -->
<sphinxql>INSERT INTO rt VALUES (1, 'text', 11, 12, 13, (101, 102), (201, 202), (301, 302))</sphinxql>
<sphinxql>select * from rt</sphinxql>
<sphinxql>ALTER TABLE rt drop column attr3</sphinxql>
<sphinxql>select * from rt</sphinxql>
<sphinxql>ALTER TABLE rt drop column m3</sphinxql>
<sphinxql>select * from rt</sphinxql>
</sphqueries>

</test>

0 comments on commit 230c321

Please sign in to comment.
You can’t perform that action at this time.