Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memcached meta-data error #16244

Closed
niden opened this issue Dec 14, 2022 Discussed in #16225 · 9 comments
Closed

Memcached meta-data error #16244

niden opened this issue Dec 14, 2022 Discussed in #16225 · 9 comments
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: unverified Unverified

Comments

@niden
Copy link
Member

niden commented Dec 14, 2022

Discussed in #16225

Originally posted by quasipickle November 24, 2022
I'm not sure if this is a bug or misconfiguration - I'll re-post as a bug if necessary.

I'm trying to set up a memcached cache for my model meta-data. When I do so, I get this notice:

PHP Notice: Cannot use a scalar value as an array in phalcon/Mvc/Model/MetaData.zep on line 630 
in [trimmed for brevity]AlbumController.php:14

And a thrown exception saying The meta-data is invalid or is corrupt from phalcon/Mvc/Model/MetaData.zep:415

My cache service is set up like this:

$Container->set("modelsMetadata", function () {
    $serializerFactory = new Phalcon\Storage\SerializerFactory();
    $adapterFactory = new Phalcon\Cache\AdapterFactory($serializerFactory);
    $options = [
        "servers" => [
            0 => [
                "host" => "127.0.0.1",
                "port" => 11211,
                "weight" => 1
            ]
        ],
        "lifetime" => 86400,
        "prefix" => "pl-2022-11-24-0"
    ];

    return new Phalcon\Mvc\Model\Metadata\Libmemcached($adapterFactory, $options);
});

The only thing I have in my models' initialize() is setting up relationships.

System:
PHP: 8.1.12
Ubuntu: 20.04 (in WSL2 in Windows 10)
Phalcon: 5.1.1

Have I misconfigured something or is this a bug?

@niden niden added bug A bug report status: unverified Unverified 5.0 The issues we want to solve in the 5.0 release labels Dec 14, 2022
@niden niden self-assigned this Dec 14, 2022
@niden
Copy link
Member Author

niden commented Dec 14, 2022

@quasipickle can you post the schema of your table including the index(es) ?

Thanks

@quasipickle
Copy link
Contributor

I have three tables - I'm not sure which may be causing the issue.

CREATE TABLE `album` (
	`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
	`name` VARCHAR(100) NOT NULL COLLATE 'utf8mb4_unicode_520_ci',
	`album_id` INT(11) UNSIGNED NULL DEFAULT NULL,
	`photo_id` INT(11) UNSIGNED NULL DEFAULT NULL COMMENT 'The ID of the featured photo',
	PRIMARY KEY (`id`) USING BTREE,
	INDEX `index_foreignkey_album_album` (`album_id`) USING BTREE,
	INDEX `album_ibfk_2` (`photo_id`) USING BTREE,
	CONSTRAINT `album_ibfk_1` FOREIGN KEY (`album_id`) REFERENCES `album` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,
	CONSTRAINT `album_ibfk_2` FOREIGN KEY (`photo_id`) REFERENCES `photo` (`id`) ON UPDATE CASCADE ON DELETE SET NULL
)
COLLATE='utf8mb4_unicode_520_ci'
ENGINE=InnoDB
AUTO_INCREMENT=932
;
CREATE TABLE `album_photo` (
	`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
	`photo_id` INT(11) UNSIGNED NULL DEFAULT NULL,
	`album_id` INT(11) UNSIGNED NULL DEFAULT NULL,
	`position` INT(10) UNSIGNED NOT NULL DEFAULT '999999999',
	PRIMARY KEY (`id`) USING BTREE,
	UNIQUE INDEX `UQ_cadf1c545153612614511f15197cae7b6dacac97` (`album_id`, `photo_id`) USING BTREE,
	INDEX `index_foreignkey_album_photo_photo` (`photo_id`) USING BTREE,
	INDEX `index_foreignkey_album_photo_album` (`album_id`) USING BTREE,
	CONSTRAINT `c_fk_album_photo_album_id` FOREIGN KEY (`album_id`) REFERENCES `album` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,
	CONSTRAINT `c_fk_album_photo_photo_id` FOREIGN KEY (`photo_id`) REFERENCES `photo` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
)
COLLATE='utf8mb4_unicode_520_ci'
ENGINE=InnoDB
AUTO_INCREMENT=19529
;
CREATE TABLE `photo` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`date_uploaded` DATETIME NOT NULL DEFAULT current_timestamp(),
	`original_filename` TEXT NOT NULL COLLATE 'utf8mb4_unicode_520_ci',
	`path` TEXT NOT NULL COLLATE 'utf8mb4_unicode_520_ci',
	`width` SMALLINT(11) UNSIGNED NOT NULL,
	`height` SMALLINT(11) UNSIGNED NOT NULL,
	`thumb_path` TEXT NOT NULL COLLATE 'utf8mb4_unicode_520_ci',
	`thumb_width` SMALLINT(5) UNSIGNED NOT NULL,
	`thumb_height` SMALLINT(5) UNSIGNED NOT NULL,
	`display_path` TEXT NOT NULL COLLATE 'utf8mb4_unicode_520_ci',
	`display_width` SMALLINT(5) UNSIGNED NOT NULL,
	`display_height` SMALLINT(5) UNSIGNED NOT NULL,
	`mime_type` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_520_ci',
	`filesize` INT(11) UNSIGNED NULL DEFAULT NULL COMMENT 'In bytes',
	`phash` BIGINT(255) UNSIGNED NOT NULL,
	`battles` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	`wins` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8mb4_unicode_520_ci'
ENGINE=InnoDB
AUTO_INCREMENT=16978
;

@Drummi42
Copy link

Drummi42 commented Mar 6, 2023

Hello! Using Redis, I ran into the same error Cannot use a scalar value as an array in phalcon/Mvc/Model/MetaData.zep on line 630. It's floating problem. And additionally there is an error (also floating) one of (occurs on random samples, sometimes repeated sometimes not). One of many:
Column 'valueInt' doesn't belong to any of the selected models (1), when preparing:

SELECT IFNULL(SUM(valueInt), 0) AS [valueInt] 
FROM [Models\Summary] 
WHERE ((summaryTypeId = :summaryTypeId:) 
AND (checkId IN({checkIds:array}))) 
AND (Models\Summary.entityId = 12)

PHP: 8.1.16
System: almalinux (in docker)
Phalcon: 5.1.4

@kvityasya
Copy link

kvityasya commented Mar 20, 2023

@niden I have a similar problem

Cannot use a scalar value as an array in phalcon/Mvc/Model/MetaData.zep on line 630

ErrorException

#0 [internal function]: Lib\ErrorHandler->errorHandler()
#1 [internal function]: Phalcon\Mvc\Model\MetaData->readMetaDataIndex()
#2 [internal function]: Phalcon\Mvc\Model\MetaData->getAttributes()
#3 [internal function]: Phalcon\Mvc\Model\Query->executeSelect()
....
#10 /app/Service.php(78): Lib\QueryBuilder->getQuery()

php 8.1
phalcon 5.1.4
cache in redis

@yesworld
Copy link

@niden Faced the same problem. :(

php 8.2
phalcon 5.2.1
cache in memcache

Notice: Cannot use a scalar value as an array in phalcon/Mvc/Model/MetaData.zep on line 630 in /var/www/html/src/Models/Session.php on line 41
string(38) "The meta-data is invalid or is corrupt"
#0 [internal function]: Phalcon\Mvc\Model\MetaData->getPrimaryKeyAttributes(Object(Press\Models\Session))
#1 [internal function]: Phalcon\Mvc\Model\Query\Builder->getPhql()
#2 [internal function]: Phalcon\Mvc\Model\Query\Builder->getQuery()
#3 [internal function]: Phalcon\Mvc\Model::getPreparedQuery(Array, 1)
#4 /var/www/html/src/Models/Session.php(41): Phalcon\Mvc\Model::findFirst(61)
#5 /var/www/html/src/Board/Services/AuthorizationService.php(88): Press\Models\Session::check('61', 'd0dcbea7ab24518...', 'cf50f79de7ab94c...')
#6 /var/www/html/src/Board/Controllers/ControllerBase.php(26): Press\Board\Services\AuthorizationService->checkAuth()
#7 [internal function]: Press\Board\Controllers\ControllerBase->beforeExecuteRoute(Object(Phalcon\Mvc\Dispatcher))
#8 [internal function]: Phalcon\Dispatcher\AbstractDispatcher->dispatch()
#9 /var/www/html/public/index.php(24): Phalcon\Mvc\Application->handle('/')
#10 /var/www/html/public/index.php(36): Application->initialize()
#11 {main}

@davidbayra
Copy link

any news?

@Drummi42
Copy link

All I found is that at some point the model classes cache data and cannot access it. As an assumption, these are the moments when the cache is rotten at the time of the model's work (model works with meta always) gets null, falls, and then updates the cache in the database with the next iteration. But there are no 100% confirmations, just guesses.

@niden niden mentioned this issue Jul 3, 2023
5 tasks
@niden niden added wontfix The issue will not be fixed or implemented status: unverified Unverified and removed status: unverified Unverified wontfix The issue will not be fixed or implemented labels Jul 3, 2023
@niden
Copy link
Member Author

niden commented Jul 3, 2023

Sadly I have not been able to reproduce this.

I have added the models that @quasipickle provided and wrote the relevant test for both Redis and Memcached. The test passes just fine and no issues reported on screen.

Perhaps @Drummi42 is on to something but even when playing with the cache timeout I was unable to reproduce it.

I am going to mark this as unverified and close it after the PR is merged. At least we gained two more tests.

@niden
Copy link
Member Author

niden commented Jul 3, 2023

#16369 - Closing

@niden niden closed this as completed Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: unverified Unverified
Projects
Status: Released
Development

No branches or pull requests

6 participants