Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support Cluster Snapshot Backup: SQL Interface and meta data (part 1) #54447

Merged
merged 2 commits into from
Dec 30, 2024

Conversation

srlch
Copy link
Contributor

@srlch srlch commented Dec 27, 2024

What I'm doing:

This is part 1 for support backup cluster snapshot:

Introduce SQL Interface for TURN ON and TRUN OFF the automated cluster snapshot task:

ADMIN SET AUTOMATED CLUSTER SNAPSHOT ON
[STORAGE VOLUME <storage_volume_name>]

ADMIN SET AUTOMATED CLUSTER SNAPSHOT OFF

Fixes #53867
#53867

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.4
    • 3.3
    • 3.2
    • 3.1
    • 3.0

@srlch srlch requested review from a team as code owners December 27, 2024 03:31
@wanpengfei-git wanpengfei-git requested a review from a team December 27, 2024 03:31
public void write(DataOutput out) throws IOException {
Text.writeString(out, GsonUtils.GSON.toJson(this));
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most risky bug in this code is:
Typo in the method call createAutomatedSnaphot, which should be createAutomatedSnapshot.

You can modify the code like this:

private void createSnapshotIfJobIsFinished() {
    GlobalStateMgr.getCurrentState().getClusterSnapshotMgr().createAutomatedSnapshot(this);
}

@mergify mergify bot assigned srlch Dec 27, 2024
@Override
public void gsonPostProcess() throws IOException {
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most risky bug in this code is:
In the load method, the deserialized object data is not used to update the state of the current ClusterSnapshotMgr. This means that the data read from the SRMetaBlockReader, which presumably represents a saved state, does nothing to restore or set the internal state of the object using it.

You can modify the code like this:

public void load(SRMetaBlockReader reader)
        throws SRMetaBlockEOFException, IOException, SRMetaBlockException {
    ClusterSnapshotMgr data = reader.readJson(ClusterSnapshotMgr.class);
    this.automatedSnapshotSvName = data.automatedSnapshotSvName;
    this.automatedSnapshot = data.automatedSnapshot;
    this.historyAutomatedSnapshotJobs = data.historyAutomatedSnapshotJobs;
    this.remoteStorage = data.remoteStorage;
    this.locationWithServiceId = data.locationWithServiceId;
}

String json = GsonUtils.GSON.toJson(this);
Text.writeString(out, json);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most risky bug in this code is:
The read method may fail if the input JSON does not match the expected structure or if required fields are missing or null.

You can modify the code like this:

public static ClusterSnapshotLog read(DataInput in) throws IOException {
    try {
        String json = Text.readString(in);
        ClusterSnapshotLog log = GsonUtils.GSON.fromJson(json, ClusterSnapshotLog.class);
        // Add checks to ensure required fields are present and valid
        if (log.type == null) {
            throw new IOException("ClusterSnapshotLog type cannot be null");
        }
        return log;
    } catch (Exception e) {
        throw new IOException("Failed to read ClusterSnapshotLog from input", e);
    }
}

Comment on lines 738 to 745
adminSetAutomatedSnapshotStatement
: ADMIN SET AUTOMATED CLUSTER SNAPSHOT (ON (STORAGE VOLUME svName=identifier)? | OFF)
;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
adminSetAutomatedSnapshotStatement
: ADMIN SET AUTOMATED CLUSTER SNAPSHOT (ON (STORAGE VOLUME svName=identifier)? | OFF)
;
adminSetAutomatedSnapshotOnStatement
: ADMIN SET AUTOMATED CLUSTER SNAPSHOT ON (STORAGE VOLUME svName=identifier)?
;
adminSetAutomatedSnapshotOffStatement
: ADMIN SET AUTOMATED CLUSTER SNAPSHOT OFF
;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


public ClusterSnapshotMgr() {}

public void addAutomatedSnapshotRequest(String storageVolumeName, boolean isReplay) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void addAutomatedSnapshotRequest(String storageVolumeName, boolean isReplay) {
// Turn on automated snapshot, use stmt for extension in future
public void setAutomatedSnapshotOn(AdminSetAutomatedSnapshotOnStmt stmt) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

return getAutomatedSnapshot() != null;
}

public boolean containAutomatedSnapshotRequest() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public boolean containAutomatedSnapshotRequest() {
public boolean isAutomatedSnapshotOn() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

return snapshot.getSnapshotName();
}

public void dropAutomatedSnapshotRequest(boolean isReplay) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void dropAutomatedSnapshotRequest(boolean isReplay) {
// Turn off automated snapshot, use stmt for extension in future
public void setAutomatedSnapshotOff(AdminSetAutomatedSnapshotOffStmt stmt) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 190 to 193
@Override
public void write(DataOutput out) throws IOException {
Text.writeString(out, GsonUtils.GSON.toJson(this));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@SerializedName(value = "automatedSnapshot")
private ClusterSnapshot automatedSnapshot = null;
@SerializedName(value = "historyAutomatedSnapshotJobs")
private List<ClusterSnapshotJob> historyAutomatedSnapshotJobs = Lists.newArrayList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not thread-safe ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@srlch srlch force-pushed the cluster_snapshot_part_1 branch from 38fa362 to 0f400f3 Compare December 30, 2024 06:40
Comment on lines 46 to 56
public void setAutomatedSnapshotOn(AdminSetAutomatedSnapshotStmt stmt) {
setAutomatedSnapshotOn(stmt, false);
}

protected void setAutomatedSnapshotOn(AdminSetAutomatedSnapshotStmt stmt, boolean isReplay) {
String storageVolumeName = stmt.getStorageVolumeName();
if (!isReplay) {
ClusterSnapshotLog log = new ClusterSnapshotLog();
log.setCreateSnapshotNamePrefix(AUTOMATED_NAME_PREFIX, storageVolumeName);
GlobalStateMgr.getCurrentState().getEditLog().logClusterSnapshotLog(log);
}
automatedSnapshotSvName = storageVolumeName;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void setAutomatedSnapshotOn(AdminSetAutomatedSnapshotStmt stmt) {
setAutomatedSnapshotOn(stmt, false);
}
protected void setAutomatedSnapshotOn(AdminSetAutomatedSnapshotStmt stmt, boolean isReplay) {
String storageVolumeName = stmt.getStorageVolumeName();
if (!isReplay) {
ClusterSnapshotLog log = new ClusterSnapshotLog();
log.setCreateSnapshotNamePrefix(AUTOMATED_NAME_PREFIX, storageVolumeName);
GlobalStateMgr.getCurrentState().getEditLog().logClusterSnapshotLog(log);
}
automatedSnapshotSvName = storageVolumeName;
}
public void setAutomatedSnapshotOn(AdminSetAutomatedSnapshotStmt stmt) {
setAutomatedSnapshotOn(stmt.getStorageVolumeName());
ClusterSnapshotLog log = new ClusterSnapshotLog();
log.setCreateSnapshotNamePrefix(AUTOMATED_NAME_PREFIX, storageVolumeName);
GlobalStateMgr.getCurrentState().getEditLog().logClusterSnapshotLog(log);
}
protected void setAutomatedSnapshotOn(String storageVolumeName) {
automatedSnapshotSvName = storageVolumeName;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -97,6 +97,8 @@ public int getId() {

public static final SRMetaBlockID PIPE_MGR = new SRMetaBlockID(32);

public static final SRMetaBlockID CLOULD_NATIVE_SNAPSHOT_MGR = new SRMetaBlockID(33);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLUSTER_SNAPSHOT_MGR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


import com.starrocks.sql.parser.NodePosition;

public class AdminSetAutomatedSnapshotStmt extends DdlStmt {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class AdminSetAutomatedSnapshotStmt extends DdlStmt {
public class AdminSetAutomatedSnapshotOnStmt extends DdlStmt {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


import com.starrocks.sql.parser.NodePosition;

public class AdminSetOffAutomatedSnapshotStmt extends DdlStmt {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class AdminSetOffAutomatedSnapshotStmt extends DdlStmt {
public class AdminSetAutomatedSnapshotOffStmt extends DdlStmt {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -734,6 +736,14 @@ syncStatement
: SYNC
;

adminSetAutomatedSnapshotStatement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
adminSetAutomatedSnapshotStatement
adminSetAutomatedSnapshotOnStatement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

: ADMIN SET AUTOMATED CLUSTER SNAPSHOT ON (STORAGE VOLUME svName=identifier)?
;

adminSetOffAutomatedSnapshotStatement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
adminSetOffAutomatedSnapshotStatement
adminSetAutomatedSnapshotOffStatement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 69 to 78
public void setAutomatedSnapshotOff(AdminSetOffAutomatedSnapshotStmt stmt) {
setAutomatedSnapshotOff(stmt, false);
}

protected void setAutomatedSnapshotOff(AdminSetOffAutomatedSnapshotStmt stmt, boolean isReplay) {
if (!isReplay) {
ClusterSnapshotLog log = new ClusterSnapshotLog();
log.setDropSnapshot(AUTOMATED_NAME_PREFIX);
GlobalStateMgr.getCurrentState().getEditLog().logClusterSnapshotLog(log);
}

// drop AUTOMATED snapshot
automatedSnapshotSvName = "";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@srlch srlch force-pushed the cluster_snapshot_part_1 branch from 0891fe8 to 3bea59e Compare December 30, 2024 07:51
Signed-off-by: srlch <[email protected]>
@srlch srlch force-pushed the cluster_snapshot_part_1 branch from 3bea59e to 46d5c78 Compare December 30, 2024 08:00
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

fail : 79 / 115 (68.70%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/persist/EditLog.java 0 5 00.00% [1114, 1115, 1116, 1967, 1968]
🔵 com/starrocks/sql/ast/AstVisitor.java 0 2 00.00% [430, 434]
🔵 com/starrocks/journal/JournalEntity.java 0 2 00.00% [780, 781]
🔵 com/starrocks/qe/DDLStmtExecutor.java 0 8 00.00% [1194, 1195, 1196, 1197, 1203, 1204, 1205, 1206]
🔵 com/starrocks/server/GlobalStateMgr.java 1 3 33.33% [1068, 1557]
🔵 com/starrocks/lake/snapshot/ClusterSnapshotMgr.java 29 38 76.32% [59, 99, 105, 106, 107, 108, 112, 113, 117]
🔵 com/starrocks/persist/ClusterSnapshotLog.java 17 22 77.27% [69, 70, 75, 76, 77]
🔵 com/starrocks/sql/analyzer/ClusterSnapshotAnalyzer.java 14 17 82.35% [27, 45, 46]
🔵 com/starrocks/sql/ast/AdminSetAutomatedSnapshotOffStmt.java 5 5 100.00% []
🔵 com/starrocks/sql/analyzer/Analyzer.java 4 4 100.00% []
🔵 com/starrocks/persist/metablock/SRMetaBlockID.java 1 1 100.00% []
🔵 com/starrocks/sql/ast/AdminSetAutomatedSnapshotOnStmt.java 8 8 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@andyziye andyziye merged commit be70af0 into StarRocks:main Dec 30, 2024
53 of 54 checks passed
@srlch
Copy link
Contributor Author

srlch commented Dec 30, 2024

https://github.com/Mergifyio backport branch-3.4

Copy link
Contributor

mergify bot commented Dec 30, 2024

backport branch-3.4

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Dec 30, 2024
…a (part 1) (#54447)

Signed-off-by: srlch <[email protected]>
(cherry picked from commit be70af0)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/qe/DDLStmtExecutor.java
wanpengfei-git pushed a commit that referenced this pull request Dec 31, 2024
maggie-zhu pushed a commit to maggie-zhu/starrocks that referenced this pull request Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

shared-data mode support backup restore though automated snapshot
6 participants