Skip to content

Issue #752: Migrate all the location status to bits - #753

Open
petersistrom wants to merge 3 commits into
MOODLE_404_STABLE-bits-and-bobsfrom
issue-752
Open

Issue #752: Migrate all the location status to bits#753
petersistrom wants to merge 3 commits into
MOODLE_404_STABLE-bits-and-bobsfrom
issue-752

Conversation

@petersistrom

@petersistrom petersistrom commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Resolves #752

Schema: boolean columns instead of a bitmask column

Moodle has no cross-database support for bitwise indexes, so a single combined location integer column cannot be indexed efficiently. Replacing it with three boolean columns (in_filedir, in_mdl_files, in_remote) allows a standard composite index to work on all supported databases.

PHP/DB boundary

PHP code keeps the existing bitmask constants. location_helper translates at the boundary: splitting a bitmask into the three boolean values on write and reconstructing it from a DB row on read.

Candidate classes

Candidate queries previously filtered on exact location equality, which breaks when new bit flags are added. They now express two masks - bits an object must have, and bits it must not have. So they survive the addition of new flags without modification.

@petersistrom
petersistrom force-pushed the issue-752 branch 5 times, most recently from 5479819 to 5dc1815 Compare July 10, 2026 01:37
Comment thread lib.php Outdated
Comment thread db/install.xml Outdated
Comment thread classes/log/aggregate_logger.php Outdated
Comment thread classes/log/aggregate_logger.php Outdated
Comment thread classes/local/store/object_file_system.php Outdated
Comment thread classes/local/report/object_status_history_table.php Outdated
// Object is not anywhere - we toggle an error state in the DB.
manager::update_object_by_hash($contenthash, OBJECT_LOCATION_ERROR);
return OBJECT_LOCATION_ERROR;
// The mdl_files bit is always set because this function is only called

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the condition this comment asserts actually enforced?

E.g., If the function were ever called for a contenthash not present in mdl_files it would return LOCAL (3) instead of ORPHANED (1) right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes correct, if it were called for a file not in mdl_files it would return LOCAL. The precondition isn't enforced, it's just a calling convention. However, orphan detection is handled via scheduled tasks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recoverer task looks for objects which are in the objectfs table but not in mdl_files and then tries to recover them. I'd prefer it if this had an param which if set did proper checks to see if its in the mdl_files as well.

Or perhaps better, it would pass in a bit map of the places we know it is present and then we don't have to re-check those places. So most places start with knowing mdl_files is present, the recoverer on the other hand only knows that it is present in objectfs tables.

get_object_location_from_hash($contenthash, $knownlocations = OBJECT_LOCATION_IN_MDL_FILES) {

recoverer:
get_object_location_from_hash($contenthash, 0) {

@petersistrom petersistrom Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree passing in a bit map of known locations is a better approach. Happy to implement that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to pass in known locations

@petersistrom
petersistrom force-pushed the issue-752 branch 2 times, most recently from 244f613 to 8c45c93 Compare July 15, 2026 06:40
@petersistrom
petersistrom changed the base branch from MOODLE_404_STABLE to MOODLE_404_STABLE-bits-and-bobs July 16, 2026 22:49
@petersistrom
petersistrom force-pushed the issue-752 branch 3 times, most recently from 19b043d to 16aeb3b Compare August 4, 2026 23:41
public function get_object_location_from_hash($contenthash) {
$localreadable = $this->is_file_readable_locally_by_hash($contenthash);
$externalreadable = $this->is_file_readable_externally_by_hash($contenthash);
public function get_object_location_from_hash($contenthash, $knownlocations = OBJECT_LOCATION_IN_MDL_FILES) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default for $knownlocations should be 0 and callers of this method should pass OBJECT_LOCATION_IN_MDL_FILES (add this to the doc block of this method to make it known to callers).

We want to do this because if a caller calls this on a hash in the db table objectfs_objects but the associated file reference of the hash no longer exists in mdl_files then the bitmask returned will incorrectly include IN_MDL_FILES which causes the checker to class the object as EXTERNAL or DUPLICATED instead of MISSING or the like.

@alexdamsted

Copy link
Copy Markdown
Contributor

@petersistrom Can the deleter, puller, pusher, and recoverer candidates classes now just be deleted? They aren't reachable via the factory anymore from your changes.

@brendanheywood mentioned about the need of candidates now after your changes. To me looking at the code raw it looks like a layer of abstraction that just complicates things more. You could move the sql from these into a single candidates static class to simplify the abstraction perhaps.

What problem was the candidates abstraction solving before your changes? To me the candidates had different sql logic and has some useful unique methods, e.g., relating to logging, but now with your changes its not as much the case and the unique methods aren't a lot of code.

@petersistrom

Copy link
Copy Markdown
Contributor Author

@alexdamsted Yes they can be deleted now, they were providing different SQL queries for each task but that has now collapsed into one query with the bitmask changes. And I think Brendan's suggestion now makes sense to nuke the concept of candidate classes completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate all the location status to bits

3 participants