Ticket T237342
Visible to All Users

XpoWorkflowInstance filling up database

created 10 years ago (modified 10 years ago)

Hi,
We are using workflows in our application and have noticed that the XpoWorkflowInstance table is filling up in the database . It now consumes > 3.5 GB. All rows have the GCRecord flag set.

My expectation is that these records are only kept as long as the workflow is being executed. Is there a way to modify the workflow server service behaviour in order to achieve this? Are there alternative ways of cleaning this up, e.g. by scheduled task?

Thanks,

Sebastian

Answers approved by DevExpress Support

created 10 years ago (modified 10 years ago)

By default, workflow instances are deleted on completion. Since the DevExpress.Workflow.Xpo.XpoWorkflowInstance persistent class has deferred deletion enabled, the records are not physically deleted from the database. These soft-deleted records can fully be removed by using a separate tool that will call the DevExpress.Xpo.Session.PurgeDeletedObjects() method. This administrative tool can be concerned with not only about removal of workflow data, but also about other persistent classes with deferred deletion. You can run it on a schedule, if you wish. The XpoTrackingRecord table can also be concerned with this for the same reason.

There are also alternative options:

  1. Implementing a DevExpress.Workflow.Xpo.XpoWorkflowInstance descendant mapped to the parent table and decorated with the DeferredDeletion(false) attribute.
  2. Implement custom code directly in the workflow service application that will remove unwanted data from required tables, e.g.:
Code
public class WorkflowServerStarter : MarshalByRefObject { ... private void Start_(string connectionString, string applicationName) { ... server.CustomizeHost += delegate(object sender, CustomizeHostEventArgs e) { e.WorkflowInstanceStoreBehavior.WorkflowInstanceStore.RunnableInstancesDetectionPeriod = TimeSpan.FromSeconds(2); e.WorkflowInstanceStoreBehavior.WorkflowInstanceStore.InstanceComplete += new EventHandler<DevExpress.Workflow.Store.InstanceEventArgs>(WorkflowInstanceStore_InstanceComplete); }; ... } void WorkflowInstanceStore_InstanceComplete(object sender, DevExpress.Workflow.Store.InstanceEventArgs e) { if (e.Status == System.Activities.ActivityInstanceState.Closed) { var fi = typeof(DevExpress.Workflow.Store.WorkflowInstanceStore).GetField("objectSpaceProvider", System.Reflection.BindingFlags.Instance| System.Reflection.BindingFlags.NonPublic); IObjectSpaceProvider provider = (IObjectSpaceProvider)fi.GetValue(sender); using (var os = provider.CreateObjectSpace()) { var list = os.GetObjects<DevExpress.Workflow.Xpo.XpoTrackingRecord>(new BinaryOperator("InstanceId", e.Id)); os.Delete(list); os.CommitChanges(); ((XPObjectSpace)os).Session.PurgeDeletedObjects(); } } } ... }

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.