Create a Table with Eviction Settings

Use eviction settings to keep your table within a specified limit, either by removing evicted data completely or by creating an overflow table that persists the evicted data to a disk store.

Procedure

Follow these steps to configure table eviction settings. Refer to CREATE TABLE for details about specifying eviction settings.
  1. Decide whether to evict based on:
    • Entry count (useful if table row sizes are relatively uniform).
    • Total bytes used.
    • Percentage of JVM heap used. This uses the GemFire XD resource manager. When the manager determines that eviction is required, the manager orders the eviction controller to start evicting from all tables where the eviction criterion is set to LRUHEAPPERCENT.
    • Percentage of off-heap memory used. This also uses the GemFire XD resource manager. See Configuring and Using Off-Heap Memory for information on using off-heap memory.

      You can configure a global heap and off-heap eviction percentages for all GemFire XD data stores, or configure different heap and off-heap evitction threshold percentages for one or more server groups by using system procedures or by specifying -eviction-heap-percentage or -eviction-offheap-percentage when starting up your server using gfxd. Procedures describes how to configure the heap and off-heap eviction percentage using system procedures. See server for information on using gfxd to start your servers.

      Eviction continues until the resource manager calls a halt. GemFire XD evicts the least recently used rows hosted by the member for the table.

  2. Decide what action to take when the limit is reached:
    • Locally destroy the row (partitioned tables only).
      Note: GemFire XD does not propagate the DESTROY evict action to configured callback implementations, such as DBSynchronizer. Do not configure eviction with the DESTROY action on a table that has dependent tables (for example, child rows with foreign keys). If a DELETE statement is called for a parent table row that was locally destroyed through eviction, the DELETE succeeds in GemFire XD. However, the DELETE operation can later fail in the backend database when DBSynchronizer asynchronously sends the DELETE command, if dependent rows still exist.

      If eviction with the DESTROY action is required for dependent tables, consider using a trigger or writer implementation to listen for DELETE events on the parent table. The trigger or writer should fail the DELETE operation if child rows are found to exist in the backend database.

      The DESTROY eviction action is not supported for replicated tables.

    • Overflow the row data to disk.
      Note: When you configure an overflow table, only the evicted rows are written to disk. If you restart or shut down a member that hosts the overflow table, the table data that was in memory is not restored unless you explicitly configure persistence (or you configure one or more replicas with a partitioned table). See Persisting Table Data to GemFire XD Disk Stores.
  3. If you want to overflow data to disk (or persist the entire table to disk), configure a named disk store to use for the overflow data. If you do not specify a disk store when creating an overflow table, GemFire XD stores the overflow data in the default disk store.
  4. Create the table with the required eviction configuration.

    For example, to evict using LRU entry count and overflow evicted rows to a disk store:

    CREATE TABLE Orders(OrderId INT NOT NULL,ItemId INT ) 
         EVICTION BY LRUCOUNT 2 EVICTACTION OVERFLOW 'OverflowDiskStore' ASYNCHRONOUS

    If you do not specify a disk store, GemFire XD overflows table data to the default disk store.

    To create an overflow table and persist the entire table, so that the entire table is available through peer restarts:

    gfxd> CREATE TABLE Orders(OrderId INT NOT NULL,ItemId INT ) 
    > EVICTION BY LRUCOUNT 2 EVICTACTION OVERFLOW PERSISTENT 'OverflowDiskStore' ASYNCHRONOUS;

    The table uses the same named disk store for both overflow and persistence.

    To create a table that simply removes evicted data from memory without persisting the evicted data, use the DESTROY eviction action. For example:

    gfxd> CREATE TABLE Orders(OrderId INT NOT NULL,ItemId INT ) 
    > PARTITION BY COLUMN (OrderId) EVICTION BY LRUMEMSIZE 1000 EVICTACTION DESTROY;
    Note: If you configure LRUMEMSIZE for a partitioned table, Pivotal recommends that you set both LRUMEMSIZE and MAXPARTSIZE to the same value. If you specify an LRUMEMSIZE value that is larger than a partitioned table's MAXPARTSIZE, then GemFire XD automatically sets LRUMEMSIZE equal to MAXPARTSIZE. See EVICTION BY Clause.