Opened 14 years ago

Closed 14 years ago

Last modified 10 years ago

#620 closed (fixed)

Empty trashcan as job

Reported by: Fredrik Levander Owned by: olle
Milestone: Proteios SE 2.10 Keywords:
Cc:

Description (last modified by Fredrik Levander)

Emptying of the trash can take a long time, and put a lot of pressure on tomcat and mysql. To avoid problems, it should be executed as a job instead. The current EmptyTrash? action works fine and can be used as a basis, but to minimise dependency problems, the following order should be applied:

Jobs
Spectrum Searches
Files
Directories
Projects

The job should delete as much as possible, and report back deletion failures. The progress reporter should be used, since execution time could be long for this plug-in.

A bonus would be if the empty trash action first checks if there are any spectrum searches in the trash, and if there are, or the total number of trash items is larger that ~10, generate empty trash job. Otherwise trash as now (but with above order).

Change History (19)

comment:1 Changed 14 years ago by Fredrik Levander

Milestone: Proteios SE Future ReleaseProteios SE 2.10

comment:2 Changed 14 years ago by Fredrik Levander

Owner: changed from Gregory Vincic to olle
type: defectenhancement

comment:3 Changed 14 years ago by Fredrik Levander

component: servletplugin
Description: modified (diff)
priority: minormajor

comment:4 Changed 14 years ago by olle

Status: newassigned

Ticket accepted.

comment:5 Changed 14 years ago by olle

Traceability note.

  • Latest ticket related to trash can functionality was Ticket #523 (Trashcan updated with separate item class views and links in menus).

comment:6 Changed 14 years ago by Fredrik Levander

Description: modified (diff)

comment:7 Changed 14 years ago by olle

Note on ticket description and current trash can functionality:

  • Of the database items discussed as deletion candidates in the ticket description, current trash can view and emptying functionality only support Jobs, Spectrum Searches, Files, and Directories. while Projects are not supported.

comment:8 Changed 14 years ago by olle

Design discussion, initial:

  • In order to facilitate future addition of trash can support for more item classes, the EmptyTrash class should be refactored to use a generic method for deleting items of a specific class. The ListTrash and MainMenu classes were already updated in changeset [3130] in Ticket #523 (Trashcan updated with separate item class views and links in menus) to make it simple to added trash can support for more item classes.

comment:9 Changed 14 years ago by olle

(In [3449]) Refs #620. Refs #523. Class/file action/write/EmptyTrash.java in client/servlet/ refactored to to facilitate future addition of trash can support for more item classes:

  1. New private instance variable String errorMessage with

public accessor methods added. This replaces the previous local variable with the same name in protected method void runMe().

  1. Protected method void runMe() updated to call new private

method int deleteItemsOfSpecificClass(Class itemClass) to try to delete items of a specific class.

  1. New private method int deleteItemsOfSpecificClass(Class itemClass)

added. It tries to delete items of a specific class, and returns the number of deleted items. If some item cannot be deleted, the error message is updated.

comment:10 Changed 14 years ago by olle

(In [3450]) Refs #620. Refs #523. Class/file action/write/EmptyTrash.java in client/servlet/ updated to facilitate future optional creation of job to empty trash can:

  1. Protected method void runMe() updated by moving commands

for deleting items to new private method void emptyTrashCan().

  1. New private method void emptyTrashCan() added.

It calls method int deleteItemsOfSpecificClass(Class itemClass) to try to delete items of a specific class. Order in which items are deleted changed to Jobs, Spectrum Searches, Files, and Directories.

  1. Unused imports and code removed.

comment:11 Changed 14 years ago by olle

Design description:

  • The empty trash can action currently shows a message reporting the number of deleted items plus an optional error message. It should be updated to prefix the error message part with "ERROR: ", in order to clearly indicate that an error has occurred.
  • The empty trash can action should check the number and type of items marked for removal, and create a job if any SpectrumSearch item or more than 10 other items should be removed, otherwise the trash can should be emptied directly.
  • The plug-in for emptying the trash can should be based on current code for the empty trash can action. However, method deleteItemsOfSpecificClass(...) should update the progress reporter to indicate the percent of items processed.
  • The plug-in for emptying the trash can should set a job response message equal to the message reported by the empty trash can action.
  • The estimated execution time for the job should be set to next fastest, SHORT.

comment:12 Changed 14 years ago by olle

(In [3451]) Refs #620. Refs #523. Action to empty trash can now creates a job if any SpectrumSearch item or or more than 10 other items should be removed:

  1. Class/file action/write/EmptyTrash.java in client/servlet/

updated:

  1. Protected method void runMe() updated to call new private

method <D extends BasicItem> int getNumberOfTrashItems(DbControl dc, Class<D> itemClass) to obtain the number of items to remove of a specific class. If any SpectrumSearch item or or more than 10 other items should be removed, new private method void createEmptyTrashCanJob() is called to create a job, otherwise private method void emptyTrashCan() is called.

  1. New private method void createEmptyTrashCanJob() added.

It creates a job using new plug-in class EmptyTrashPlugin.

  1. Private method void emptyTrashCan() updated to prefix any

error part of the delete message with "ERROR: ".

  1. New private method int getTotalNumberOfTrashItems(DbControl dc)

added. It obtains the total number of items in the trash can by calling new private method <D extends BasicItem> int getNumberOfTrashItems(DbControl dc, Class<D> itemClass).

  1. New private method

<D extends BasicItem> int getNumberOfTrashItems(DbControl dc, Class<D> itemClass) added. It obtains the number of items of a specific class in the trash can.

  1. New class/file plugins/EmptyTrashPlugin.java in plugin/ added.
  2. Public method

void run(Request request, Response response, ProgressReporter progress) calls public method void execute(Request request, Response response, ProgressReporter progress) to empty the trash can.

  1. Public method

void execute(Request request, Response response, ProgressReporter progress) calls private method int deleteItemsOfSpecificClass(Class itemClass, ProgressReporter progress, int startCount, int totalCount) to remove items of a specific class.

  1. Private method

int deleteItemsOfSpecificClass(Class itemClass, ProgressReporter progress, int startCount, int totalCount) tries to delete items of a specific class, and returns the number of deleted items. If some item cannot be deleted, the error message is updated. The progress reporter is updated after each processed item.

  1. Private method int getTotalNumberOfTrashItems(DbControl dc)

obtains the total number of items in the trash can by calling private method <D extends BasicItem> int getNumberOfTrashItems(DbControl dc, Class<D> itemClass).

  1. Private method

<D extends BasicItem> int getNumberOfTrashItems(DbControl dc, Class<D> itemClass) obtains the number of items of a specific class in the trash can.

comment:13 Changed 14 years ago by olle

Design note:

  • A problem with the current design of the empty trash plug-in is that it will try to remove all deleted items at time of execution, which may include items that were not deleted when the job was created.

comment:14 Changed 14 years ago by Fredrik Levander

It has been possible to delete several thousand trashcan items in one go, so it is fine.

comment:15 Changed 14 years ago by Fredrik Levander

Resolution: fixed
Status: assignedclosed

comment:16 Changed 14 years ago by olle

(In [3517]) Refs #620. Refs #327. Classes related to emptying trash can updated to remove warnings due to unchecked conversion from unspecified class type:

  1. Class/file action/write/EmptyTrash.java in client/servlet/

updated:

  1. Private method

int deleteItemsOfSpecificClass(Class itemClass) updated by change of type for argument itemClass from Class to Class<? extends BasicItem>.

  1. Class/file plugins/EmptyTrashPlugin.java in plugin/ updated:
  2. Private method

int deleteItemsOfSpecificClass(Class itemClass, ProgressReporter progress, int startCount, int totalCount) updated by change of type for argument itemClass from Class to Class<? extends BasicItem>.

comment:17 Changed 13 years ago by olle

(In [3953]) Refs #704. Refs #523. Refs #620. Routines for listing, restoring or permanently removing items in the trash should be updated to support project items:

  1. Class/file gui/MainMenu.java in client/servlet/ updated to add

a menu item for projects in the trash can menu.

  1. Class/file action/read/ViewHome.java in client/servlet/ updated:
  2. New valid parameter VInteger VPROJECTCOUNT added.
  3. Public method void runMe() updated to support project items.
  4. Private method Form getTrashCanForm(...) updated with new

argument Integer projectCount and support for projects in the form.

  1. Class/file action/write/EmptyTrash.java in client/servlet/

updated to support project items.

  1. Class/file plugins/EmptyTrashPlugin.java in plugin/ updated

to support project items.

comment:18 Changed 13 years ago by olle

(In [3956]) Refs #704. Refs #523. Refs #620. Routines for permanently removing items in the trash updated to repeat attempts to empty the trash can, as long as some item is removed in each attempt, and more items to remove remain:

  1. Class/file action/write/EmptyTrash.java in client/servlet/ updated:
  2. Private method void emptyTrashCan() updated with new argument

int totalItemCount and calling new private method int emptyTrashCanAttempt() as long as some item is removed in each attempt, and more items to remove remain.

  1. New private method int emptyTrashCanAttempt() added.

It attempts to permanently remove items, using code previously in private method void emptyTrashCan().

  1. Class/file plugins/EmptyTrashPlugin.java in plugin/ updated:
  2. Public method void execute(Request request, Response response, ProgressReporter progress)

updated to call new private method int emptyTrashCanAttempt(Request request, Response response, ProgressReporter progress, int accDeletedCount, int totalItemCount) as long as some item is removed in each attempt, and more items to remove remain.

  1. New private method

int emptyTrashCanAttempt(Request request, Response response, ProgressReporter progress, int accDeletedCount, int totalItemCount) added. It attempts to permanently remove items, using code previously in public method void execute(Request request, Response response, ProgressReporter progress).

comment:19 Changed 10 years ago by olle

(In [4412]) Refs #798. Refs #620. Refs #46. Classes/files action/write/EmptyTrash.java in client/servlet/ and plugins/EmptyTrashPlugin.java in plugin/ have been updated to hopefully avoid errors due to a proxy being associated with two open sessions. The updated routine has the following main steps:

  • DbControl object dc is used to create an ItemResultList<?> itemResultList from a database query. This is in turn used to create a List<BasicItem<?>> itemList of the items of interest.
  • DbControl object dc is closed, and List<BasicItem<?>> itemList is used to loop over the items.
  • For each item, DbControl object dc2 is created and used to get a new instance of the item from its database id. DbControl object dc2 is then used to delete the latter item, the change is committed, and DbControl object dc2 is closed.
  • DbControl object dc is created again, and used to generate a list of items still in the database, that is checked against the List<BasicItem<?>> itemList of items to delete.

Note: See TracTickets for help on using tickets.