Mongo - > PHP indexes

96 views
Skip to first unread message

Marcin Oleszkiewicz

unread,
Jul 2, 2012, 4:25:03 AM7/2/12
to mongodb-user
I'm indexing some data using multikey in a commandline running script,
when I do ensureIndex(Array) the CLI stops working with:

Problem signature:
Problem Event Name: APPCRASH
Application Name: php.exe
Application Version: 5.3.12.0
Application Timestamp: 4fa94ed7
Fault Module Name: php5ts.dll
Fault Module Version: 5.3.12.0
Fault Module Timestamp: 4fa94f4e
Exception Code: c0000005
Exception Offset: 0000c894
OS Version: 6.1.7601.2.1.0.272.7
Locale ID: 1045
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

I'm using (following RockMongo data):
Web server Apache/2.2.22
PHP version PHP 5.3.13
PHP extension mongo/1.2.10

What is strange is that I have this problem only when I'm using one
data source, when I'm using other ones the indexing works fine. In
other sources the array looks same and it's not a big number of
documents in collection (I'm iterating over a MSSql data source,
entering 1000 records to mongo and it breaks on the very first
iteration).

Jeremy Mikola

unread,
Jul 2, 2012, 2:21:52 PM7/2/12
to mongod...@googlegroups.com
Could you provide a backtrace of the PHP process? Either of these links should help:
Does the CLI script (which is crashing) simply call ensureIndex(), or is it doing that before/after you do a batch insert of results from an MSSQL query? A code snippet that reproduces the crash would certainly help explain, if you can share that.

Lastly, what other PHP extensions are at play here? Are you using PDO or the mssql_* functions to access MSSQL?

Marcin Oleszkiewicz

unread,
Jul 3, 2012, 4:06:01 AM7/3/12
to mongod...@googlegroups.com
sometimes I'm also getting the zend_mm_cheap occured using this script...

code snippet: http://wklej.org/id/783438/

the ensureIndex that is giving troubles is the one on line 73

it's a part of data warehouse app that is downloading data from MSSql (pdo sqlserv) entering it to mongo warehouse and than creating data marts from mongo warehouse and once again entering them to mongo, the code I've shown is the code that is doing the last part of this process so creating a data mart

I've run the code using https://bugs.php.net/bugs-generating-backtrace-win32.php without compiler and got a report, the mht file is attached. I will provide more info if needed
CrashHang_Report__Date_07_03_2012__Time_09_42_30AM__154.mht

Marcin Oleszkiewicz

unread,
Jul 3, 2012, 4:10:19 AM7/3/12
to mongod...@googlegroups.com
of course I'm using Windows Server envirorment, the 5.3 PHP is the one delivered with 32 bit Wamp Package

Derick Rethans

unread,
Jul 3, 2012, 5:55:42 AM7/3/12
to mongod...@googlegroups.com
On Tue, 3 Jul 2012, Marcin Oleszkiewicz wrote:

> sometimes I'm also getting the zend_mm_cheap occured using this script...
>
> code snippet: http://wklej.org/id/783438/
>
> the ensureIndex that is giving troubles is the one on line 73

Could you try dumping the result of the getIndexes() ? If it doesn't
return a proper array, that might cause the crashes.

cheers,
Derick

--
http://mongodb.org | http://derickrethans.nl
twitter: @derickr and @mongodb

Marcin Oleszkiewicz

unread,
Jul 3, 2012, 6:24:01 AM7/3/12
to mongod...@googlegroups.com
as I said in other sources the same process works fine and also in this one the getIndexes its already used on line 27... but of course I've dumped it and the print_r of the getIndexes array shows:

Array
(
    [0] => CPV
    [1] => IDzleceniodawcy
    [2] => PL
    [3] => wojewodztwo
)


what is more, before I realized that multikey gives different result, on this source I tried to do something like:

 
$a=$mart->getIndexes();
foreach($a as $b){
       
      $coll->ensureIndex($a);}

and it didn't caused problems

Jeremy Mikola

unread,
Jul 3, 2012, 9:27:50 AM7/3/12
to mongod...@googlegroups.com
On Tuesday, July 3, 2012 6:24:01 AM UTC-4, Marcin Oleszkiewicz wrote:
as I said in other sources the same process works fine and also in this one the getIndexes its already used on line 27... but of course I've dumped it and the print_r of the getIndexes array shows:

Array
(
    [0] => CPV
    [1] => IDzleceniodawcy
    [2] => PL
    [3] => wojewodztwo
)

If getIndexes() returns an array of strings, it's not the appropriate parameter to pass to ensureIndex() on line 75. The indexes should be specified as an associative array, where values are 1 and -1 for ascending or descending, respectively. See the documentation for more info. I'm not sure why that would cause a crash, though. If I had to guess, the driver would instruct MongoDB to index fields named zero through four in ascending order (if those strings were evaluated as "1" or not "-1")

On an unrelated note, it's probably cleaner to replace:

foreach( $mart->getIndexes() as $index ) {
    $index = (array)$index;
    $indexParam = array_combine($index, array_fill(0, count($index), 1));
    $result = $coll->ensureIndex($indexParam);
}

With this:

foreach( $mart->getIndexes() as $index ) {
    $result = $coll->ensureIndex(array($index => 1));
}
 

Marcin Oleszkiewicz

unread,
Jul 5, 2012, 4:21:51 AM7/5/12
to mongod...@googlegroups.com
how sad is that... yeah it was causing problems, but I'm not sure why only in this case and in other that are the same it wasn't... thanks for that!
Reply all
Reply to author
Forward
0 new messages