Class TimeBasedTableDiskSizeManager

java.lang.Object
net.solarnetwork.service.support.BasicIdentifiable
net.solarnetwork.node.service.support.BaseIdentifiable
net.solarnetwork.node.dao.jdbc.TimeBasedTableDiskSizeManager
All Implemented Interfaces:
net.solarnetwork.node.job.JobService, net.solarnetwork.service.Identifiable, net.solarnetwork.settings.SettingSpecifierProvider

public class TimeBasedTableDiskSizeManager extends net.solarnetwork.node.service.support.BaseIdentifiable implements net.solarnetwork.node.job.JobService
Service that deletes rows from a database table when disk space is running low.

This service is designed so that executeJobService() can be called periodically to check if rows need to be deleted, based on the thresholds configured. The main threshold is the file system available capacity. When the file system use exceeds maxFileSystemUseThreshold then this service will attempt to delete a subset of the oldest available data from a single configured table. After deleting data, DatabaseSystemService.vacuumTable(String, String) will be called so that the database can attempt to release file system space back to the operating system.

Note that the dateColumnName time stamp column is assumed to store dates in the UTC time zone.

Since:
1.19
Version:
2.0
Author:
matt
  • Field Summary

    Fields inherited from class net.solarnetwork.node.service.support.BaseIdentifiable

    log

    Fields inherited from interface net.solarnetwork.service.Identifiable

    GROUP_UID_PROPERTY, UID_PROPERTY
  • Constructor Summary

    Constructors
    Constructor
    Description
    TimeBasedTableDiskSizeManager(org.springframework.jdbc.core.JdbcOperations jdbcOperations)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    List<net.solarnetwork.settings.SettingSpecifier>
     
     
    void
    setDateColumnName(String dateColumnName)
    Set the name of the date column to manage.
    void
    setDbSystemService(net.solarnetwork.service.OptionalService<DatabaseSystemService> dbSystemService)
    Set the database system service to use.
    void
    setMaxFileSystemUseThreshold(float maxFileSystemUseThreshold)
    Set the maximum file system use percentage allowed before trimming data is permitted.
    void
    setMinTableSizeThreshold(long minTableSizeThreshold)
    Set a minimum size, in bytes, for a table to consume before allowing the oldest data to be trimmed.
    void
    setSchemaName(String schemaName)
    Set the name of the schema of the database table to manage.
    void
    setTableName(String tableName)
    Set the name of the database table to manage.
    void
    setTrimMinutes(int trimMinutes)
    Set the number of minutes of oldest data to trim.

    Methods inherited from class net.solarnetwork.node.service.support.BaseIdentifiable

    baseIdentifiableSettings, baseIdentifiableSettings, getExpressionServices, getPlaceholderService, populateExpressionDatumProperties, resolvePlaceholders, resolvePlaceholders, setExpressionServices, setPlaceholderService

    Methods inherited from class net.solarnetwork.service.support.BasicIdentifiable

    basicIdentifiableMetadataSettings, basicIdentifiableSettings, basicIdentifiableSettings, basicIdentifiableSettings, doubleMetadataValue, getDisplayName, getGroupUid, getGroupUID, getMessageSource, getMetadata, getMetadataCount, getUid, getUID, integerMetadataValue, metadataValue, numberMetadataValue, saveMetadataValue, saveMetadataValue, setDisplayName, setGroupUid, setGroupUID, setMessageSource, setMetadata, setMetadataCount, setUid, setUID, smartMetadataValue

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.solarnetwork.service.Identifiable

    getDisplayName, getGroupUid, getUid

    Methods inherited from interface net.solarnetwork.settings.SettingSpecifierProvider

    getDisplayName, getMessageSource, templateSettingSpecifiers
  • Constructor Details

    • TimeBasedTableDiskSizeManager

      public TimeBasedTableDiskSizeManager(org.springframework.jdbc.core.JdbcOperations jdbcOperations)
      Constructor.
      Parameters:
      jdbcOperations - the JDBC operations
      Throws:
      IllegalArgumentException - if any argument is null
  • Method Details

    • getSettingUid

      public String getSettingUid()
      Specified by:
      getSettingUid in interface net.solarnetwork.settings.SettingSpecifierProvider
    • getSettingSpecifiers

      public List<net.solarnetwork.settings.SettingSpecifier> getSettingSpecifiers()
      Specified by:
      getSettingSpecifiers in interface net.solarnetwork.settings.SettingSpecifierProvider
    • executeJobService

      public void executeJobService() throws Exception
      Specified by:
      executeJobService in interface net.solarnetwork.node.job.JobService
      Throws:
      Exception
    • setDbSystemService

      public void setDbSystemService(net.solarnetwork.service.OptionalService<DatabaseSystemService> dbSystemService)
      Set the database system service to use.

      This service is assumed to be configured to manage the same database as provided by the JdbcOperations passed to the constructor.

      Parameters:
      dbSystemService - the database system service
    • setSchemaName

      public void setSchemaName(String schemaName)
      Set the name of the schema of the database table to manage.

      This defaults to SOLARNODE.

      Parameters:
      schemaName - the database schema name of the table to manage
    • setTableName

      public void setTableName(String tableName)
      Set the name of the database table to manage.

      This defaults to SN_GENERAL_NODE_DATUM.

      Parameters:
      tableName - the name of the database table to manage
    • setDateColumnName

      public void setDateColumnName(String dateColumnName)
      Set the name of the date column to manage.

      This column is referenced when executing time-based queries on the managed database table, and should contain a timestamp data type. It defaults to CREATED.

      Parameters:
      dateColumnName - the name of the date column on the database table to manage
    • setMaxFileSystemUseThreshold

      public void setMaxFileSystemUseThreshold(float maxFileSystemUseThreshold)
      Set the maximum file system use percentage allowed before trimming data is permitted.

      This value should be expressed as a percentage, for example 92.5. Defaults to 90.

      Parameters:
      maxFileSystemUseThreshold - the max file system use percentage
    • setMinTableSizeThreshold

      public void setMinTableSizeThreshold(long minTableSizeThreshold)
      Set a minimum size, in bytes, for a table to consume before allowing the oldest data to be trimmed.

      This defaults to 1048576 (1MB).

      Parameters:
      minTableSizeThreshold - the minimum table size threshold
    • setTrimMinutes

      public void setTrimMinutes(int trimMinutes)
      Set the number of minutes of oldest data to trim.

      When trimming data, the oldest available date plus this many minutes will be deleted. Defaults to 90.

      Parameters:
      trimMinutes - the number of minutes to to trim