Class RecoverySnapshotUtils

java.lang.Object
org.apache.hadoop.hbase.master.procedure.RecoverySnapshotUtils

@Private public final class RecoverySnapshotUtils extends Object
Utility class for recovery snapshot functionality, which automatically creates snapshots before dropping tables, truncating tables, or deleting column families.
  • Field Details

    • LOG

      private static final org.slf4j.Logger LOG
  • Constructor Details

  • Method Details

    • isRecoveryEnabled

      public static boolean isRecoveryEnabled(MasterProcedureEnv env)
      Checks if recovery snapshots are enabled for destructive table actions.
      Parameters:
      env - MasterProcedureEnv
      Returns:
      true if recovery snapshot functionality is enabled, false otherwise
    • getRecoverySnapshotTtl

      public static long getRecoverySnapshotTtl(MasterProcedureEnv env, TableDescriptor tableDescriptor)
      Gets the TTL that should be used for snapshots created before destructive schema actions. Checks for table-level override first, then falls back to site configuration.
      Parameters:
      env - MasterProcedureEnv
      tableDescriptor - the table descriptor to check for table-level TTL override
      Returns:
      TTL in seconds
    • generateSnapshotName

      public static String generateSnapshotName(TableName tableName)
      Generates a recovery snapshot name.

      The naming convention is: auto_{table}_{timestamp}

      Parameters:
      tableName - the table name
      Returns:
      the generated snapshot name
    • generateSnapshotName

      public static String generateSnapshotName(TableName tableName, long timestamp)
      Generates a recovery snapshot name.

      The naming convention is: auto_{table}_{timestamp}

      Parameters:
      tableName - the table name
      timestamp - the timestamp when the snapshot was initiated
      Returns:
      the generated snapshot name
    • buildSnapshotDescription

      public static org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription buildSnapshotDescription(TableName tableName, String snapshotName)
      Creates a SnapshotDescription for the recovery snapshot for a given operation.
      Parameters:
      tableName - the table name
      snapshotName - the snapshot name
      Returns:
      SnapshotDescription for the recovery snapshot
    • buildSnapshotDescription

      public static org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription buildSnapshotDescription(TableName tableName, String snapshotName, long ttl, org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription.Type type)
      Creates a SnapshotDescription for the recovery snapshot for a given operation.
      Parameters:
      tableName - the table name
      snapshotName - the snapshot name
      ttl - the TTL for the snapshot in seconds (0 means no TTL)
      type - the type of snapshot to create
      Returns:
      SnapshotDescription for the recovery snapshot
    • createSnapshotProcedure

      public static SnapshotProcedure createSnapshotProcedure(MasterProcedureEnv env, TableName tableName, String snapshotName, TableDescriptor tableDescriptor) throws IOException
      Creates a SnapshotProcedure for soft drop functionality.

      This method should be called from procedures that need to create a snapshot before performing destructive operations. It will check for table-level TTL overrides.

      Parameters:
      env - MasterProcedureEnv
      tableName - the table name
      snapshotName - the name for the snapshot
      tableDescriptor - the table descriptor to check for table-level TTL override
      Returns:
      SnapshotProcedure that can be added as a child procedure
      Throws:
      IOException - if snapshot creation fails
    • deleteRecoverySnapshot

      public static void deleteRecoverySnapshot(MasterProcedureEnv env, String snapshotName, TableName tableName)
      Deletes a recovery snapshot during rollback scenarios.

      This method should be called during procedure rollback to clean up any snapshots that were created before the failure.

      Parameters:
      env - MasterProcedureEnv
      snapshotName - the name of the snapshot to delete
      tableName - the table name (for logging)