Class RecoverySnapshotUtils
java.lang.Object
org.apache.hadoop.hbase.master.procedure.RecoverySnapshotUtils
Utility class for recovery snapshot functionality, which automatically creates snapshots before
dropping tables, truncating tables, or deleting column families.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.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.static SnapshotProcedure
createSnapshotProcedure
(MasterProcedureEnv env, TableName tableName, String snapshotName, TableDescriptor tableDescriptor) Creates a SnapshotProcedure for soft drop functionality.static void
deleteRecoverySnapshot
(MasterProcedureEnv env, String snapshotName, TableName tableName) Deletes a recovery snapshot during rollback scenarios.static String
generateSnapshotName
(TableName tableName) Generates a recovery snapshot name.static String
generateSnapshotName
(TableName tableName, long timestamp) Generates a recovery snapshot name.static long
getRecoverySnapshotTtl
(MasterProcedureEnv env, TableDescriptor tableDescriptor) Gets the TTL that should be used for snapshots created before destructive schema actions.static boolean
Checks if recovery snapshots are enabled for destructive table actions.
-
Field Details
-
LOG
-
-
Constructor Details
-
RecoverySnapshotUtils
private RecoverySnapshotUtils()
-
-
Method Details
-
isRecoveryEnabled
Checks if recovery snapshots are enabled for destructive table actions.- Parameters:
env
- MasterProcedureEnv- Returns:
- true if recovery snapshot functionality is enabled, false otherwise
-
getRecoverySnapshotTtl
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
- MasterProcedureEnvtableDescriptor
- the table descriptor to check for table-level TTL override- Returns:
- TTL in seconds
-
generateSnapshotName
Generates a recovery snapshot name.The naming convention is: auto_{table}_{timestamp}
- Parameters:
tableName
- the table name- Returns:
- the generated snapshot name
-
generateSnapshotName
Generates a recovery snapshot name.The naming convention is: auto_{table}_{timestamp}
- Parameters:
tableName
- the table nametimestamp
- 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 namesnapshotName
- 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 namesnapshotName
- the snapshot namettl
- 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
- MasterProcedureEnvtableName
- the table namesnapshotName
- the name for the snapshottableDescriptor
- 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
- MasterProcedureEnvsnapshotName
- the name of the snapshot to deletetableName
- the table name (for logging)
-