Skip to content

external objects retention time - #1

Open
KaterynaLove wants to merge 4 commits into
MOODLE_310_STABLEfrom
DEF-475
Open

external objects retention time#1
KaterynaLove wants to merge 4 commits into
MOODLE_310_STABLEfrom
DEF-475

Conversation

@KaterynaLove

Copy link
Copy Markdown
Owner

No description provided.

@dvdcastro dvdcastro left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for working on this Kateryna. I've left some minor comments.

The task and the function changes will need unit tests written for them before we can submit to Catalyst.

$currentpath = $this->get_external_path_from_hash($contenthash);
$this->externalclient->delete_file($currentpath);
$delay_delete_external_object = get_config('tool_objectfs', 'delaydeleteexternalobject');
if($force_delay_delete) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if($force_delay_delete) {
if ($force_delay_delete) {


$delay_objects_delete->id = $DB->insert_record('tool_objectfs_delay_delete', $delay_objects_delete, true);
} else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change

Comment thread version.php Outdated
$plugin->maturity = MATURITY_STABLE;
$plugin->supported = [310, 401];
$plugin->dependencies = array(
'local_aws' => 2022011300

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is an optional dependency, we should not include it.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This was already in the code. Should I just remove it then?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Their version file does not have it. Yes, let's remove it.
https://github.com/catalyst/moodle-tool_objectfs/blob/MOODLE_310_STABLE/version.php

Comment thread settings.php Outdated
$settings->add(new admin_setting_configcheckbox('tool_objectfs/preferexternal',
new lang_string('settings:preferexternal', 'tool_objectfs'), '', ''));

$settings->add(new admin_settings_aws_region('tool_objectfs/s3_region',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why is this setting necessary?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This also was already in the code. Not sure..

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It should not appear in the diff. I think you need to rebase your changes.

Comment thread lang/en/tool_objectfs.php Outdated
$string['settings:batchsize_help'] = 'Number of files to be transferred in one cron run';
$string['settings:maxorphanedage'] = 'Max orphaned object age';
$string['settings:maxorphanedage_help'] = 'If set to zero, this will not delete old orphaned metadata for objects. Otherwise, it will remove these records as they are no longer relevant. An orphaned object is one where the metadata exists on the {tool_objectfs_objects} table but referenced file no longer exists.';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change has not been made.

* and external file (if delete external enabled) as it is no longer useful/relevant.
*
* @package tool_objectfs
* @author Kevin Pham <kevinpham@catalyst-au.net>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
* @author Kevin Pham <kevinpham@catalyst-au.net>
* @author Katerina Martinenko <kateryna.martynenko@moodle.com>


$timeperiodforremoval = $this->config->delaydeleteexternalobject;
if (empty($timeperiodforremoval)) {
mtrace('Skipping delayed deletion of the external object of the delaydeleteexternalobject is set to an empty value.');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens if there are files in the table still? Should we purge the table then?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Right now the records are not deleting from the table, only updating. We could delete those directly from the table instead.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Would that be okay keeping always an empty table though?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We can purge the table as a last step. Let's say it purges files from the list which were removed 90 days ago. IDK what would happen if there was a file added that has the same content has and then also deleted. Would we have 2 entries in the table? If that's the case, and they don't clash, I don't see a problem with deleting these entries periodically. Deleting them straight away is also valid, you could get rid of the status field.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Ok, I'll delete them directly then and will remove the status field.

$objects = $DB->get_recordset_sql($sql, $params);
$count = 0;
foreach ($objects as $object) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change

$deletedexternalobject->id = $object->id;
$deletedexternalobject->status = 1;
$DB->update_record('tool_objectfs_delay_delete', $deletedexternalobject);
$count++;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should short circuit this for loop in case there are many files delayed to be deleted. Having a long list may harm the task execution for the entire site.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Hmm good point! I can add a limit to that, for example, to delete 10 files at a time..?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think 1000 at a time is a good value.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

All right, will put a limit as 1000 :)

Comment on lines +630 to +642
$delay_delete_external_object = get_config('tool_objectfs', 'delaydeleteexternalobject');
if($force_delay_delete) {
$this->externalclient->delete_file($currentpath);
} else if ($delay_delete_external_object > 0) {
$delay_objects_delete = new \stdClass();
$delay_objects_delete->contenthash = $contenthash;
$delay_objects_delete->timecreated = time();

$delay_objects_delete->id = $DB->insert_record('tool_objectfs_delay_delete', $delay_objects_delete, true);
} else {

$this->externalclient->delete_file($currentpath);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor suggestion.

Suggested change
$delay_delete_external_object = get_config('tool_objectfs', 'delaydeleteexternalobject');
if($force_delay_delete) {
$this->externalclient->delete_file($currentpath);
} else if ($delay_delete_external_object > 0) {
$delay_objects_delete = new \stdClass();
$delay_objects_delete->contenthash = $contenthash;
$delay_objects_delete->timecreated = time();
$delay_objects_delete->id = $DB->insert_record('tool_objectfs_delay_delete', $delay_objects_delete, true);
} else {
$this->externalclient->delete_file($currentpath);
}
$delaydeleteexternalobject = get_config('tool_objectfs', 'delaydeleteexternalobject');
if($forcedelaydelete || $delaydeleteexternalobject <= 0) {
$this->externalclient->delete_file($currentpath);
} else if ($delaydeleteexternalobject > 0) {
$delay_objects_delete = new \stdClass();
$delay_objects_delete->contenthash = $contenthash;
$delay_objects_delete->timecreated = time();
$delay_objects_delete->id = $DB->insert_record('tool_objectfs_delay_delete', $delay_objects_delete, true);
}

Comment thread classes/local/manager.php Outdated
}

// If location change is 'orphaned' we update timeorphaned.
//Set time orphaned clock is ticking now for delay deletion comparison...

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
//Set time orphaned clock is ticking now for delay deletion comparison...
// Set time orphaned clock is ticking now for delay deletion comparison...

* Deletes external file depending on deleteexternal settings.
*
* @param string $contenthash file to be moved
* @param boolean $forcedelete will force to delete the file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
* @param boolean $forcedelete will force to delete the file

Comment on lines +628 to +629
global $DB;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
global $DB;

Comment thread db/tasks.php Outdated
Comment on lines +113 to +114
'minute' => '*',
'hour' => '*',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we can run this in the same manner as the tool_objectfs\task\orphan_objects and the tool_objectfs\task\delete_orphaned_object_metadata tasks. This is optional, just an opinion.

Suggested change
'minute' => '*',
'hour' => '*',
'minute' => 'R',
'hour' => 'R',

Comment thread lang/en/tool_objectfs.php Outdated
$string['settings:batchsize_help'] = 'Number of files to be transferred in one cron run';
$string['settings:maxorphanedage'] = 'Max orphaned object age';
$string['settings:maxorphanedage_help'] = 'If set to zero, this will not delete old orphaned metadata for objects. Otherwise, it will remove these records as they are no longer relevant. An orphaned object is one where the metadata exists on the {tool_objectfs_objects} table but referenced file no longer exists.';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change has not been made.

Comment thread tests/delay_file_delete.php Outdated
$this->assertTrue($this->is_externally_readable_by_hash($filehash));
}

public function presigned_url_should_redirect_provider() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this can be removed.

Comment thread tests/delay_file_delete.php Outdated
*
* @return array
*/
public function get_expiration_time_method_if_supported_provider() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this can be removed.

Comment thread tests/delay_file_delete.php Outdated
*
* @return array
*/
public function get_valid_http_ranges_provider() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this can be removed.

Comment thread tests/delay_file_delete.php Outdated
*
* @return array
*/
public function curl_range_request_to_presigned_url_provider() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this can be removed.

Comment thread tests/task/delay_file_delete_test.php Outdated
/**
* Execute task
*/
public function execute() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't understand this test. How is it validating that elements are being deleted from the external system? I think we should create mocks for the method $filesystem->delete_external_file_from_hash(...), and check that when the task is run, the method is called under the correct circumstances.

@dvdcastro dvdcastro left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for working on this Kateryna. Please review the comments I had left in prior reviews where I suggested removing empty lines or whitespaces, they still have not been addressed.

Comment thread tests/object_file_system_test.php Outdated

manager::update_object($objectrecord, OBJECT_LOCATION_ORPHANED);

$this->assertTrue($this->is_externally_readable_by_hash($filehash));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I suggest we also validate that the objectfs row has the timeorphaned value set.

$objectrecord = $DB->get_record('tool_objectfs_objects', ['contenthash' => $filehash]);
$this->assertGreaterThan($objectrecord->timeorphaned, 0, 'Time orphaned should be greater than 0.');

Comment thread tests/object_file_system_test.php Outdated
$this->assertTrue($this->is_externally_readable_by_hash($filehash));
}

public function test_if_external_orphaned_object_is_deleted_after_delaydeleteexternalobject_setting() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This method is not currently testing something. I suggest we delete it. If you want to test the task execution, I suggest you first create orphaned files with an expired orphanedtime and then run the execute function from the task.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

But I think we can get a pass on running tests for the task. They are currently not testing their tasks.

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.

4 participants