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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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 740
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

Signed-off-by: srlch <[email protected]>

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

Signed-off-by: srlch <[email protected]>
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

fail : 143 / 201 (71.14%)

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 54 73 73.97% [107, 108, 111, 119, 131, 132, 133, 135, 165, 166, 167, 178, 184, 185, 186, 187, 191, 192, 196]
🔵 com/starrocks/persist/ClusterSnapshotLog.java 21 27 77.78% [74, 82, 83, 88, 89, 90]
🔵 com/starrocks/lake/snapshot/ClusterSnapshotJob.java 29 37 78.38% [67, 72, 82, 83, 84, 87, 88, 91]
🔵 com/starrocks/lake/snapshot/ClusterSnapshot.java 11 14 78.57% [43, 58, 62]
🔵 com/starrocks/sql/analyzer/ClusterSnapshotAnalyzer.java 14 17 82.35% [27, 45, 46]
🔵 com/starrocks/sql/ast/AdminSetAutomatedSnapshotStmt.java 5 5 100.00% []
🔵 com/starrocks/sql/analyzer/Analyzer.java 4 4 100.00% []
🔵 com/starrocks/sql/ast/AdminSetOffAutomatedSnapshotStmt.java 3 3 100.00% []
🔵 com/starrocks/persist/metablock/SRMetaBlockID.java 1 1 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

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
3 participants