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

[feat](backup) GetSnapshot returns snapshot expiration time #43731 #43863

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -978,12 +978,18 @@ public synchronized Snapshot getSnapshot() {
return null;
}

// Avoid loading expired meta.
long expiredAt = createTime + timeoutMs;
if (System.currentTimeMillis() >= expiredAt) {
return new Snapshot(label, new byte[0], new byte[0], expiredAt);
}

try {
File metaInfoFile = new File(localMetaInfoFilePath);
File jobInfoFile = new File(localJobInfoFilePath);
byte[] metaInfoBytes = Files.readAllBytes(metaInfoFile.toPath());
byte[] jobInfoBytes = Files.readAllBytes(jobInfoFile.toPath());
return new Snapshot(label, metaInfoBytes, jobInfoBytes);
return new Snapshot(label, metaInfoBytes, jobInfoBytes, expiredAt);
} catch (IOException e) {
LOG.warn("failed to load meta info and job info file, meta info file {}, job info file {}: ",
localMetaInfoFilePath, localJobInfoFilePath, e);
Expand Down
17 changes: 14 additions & 3 deletions fe/fe-core/src/main/java/org/apache/doris/backup/Snapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ public class Snapshot {
@SerializedName(value = "jobInfo")
private byte[] jobInfo = null;

@SerializedName(value = "expired_at")
private long expiredAt = 0;

public Snapshot() {
}

public Snapshot(String label, byte[] meta, byte[] jobInfo) {
public Snapshot(String label, byte[] meta, byte[] jobInfo, long expiredAt) {
this.label = label;
this.meta = meta;
this.jobInfo = jobInfo;
this.expiredAt = expiredAt;
}


public byte[] getMeta() {
return meta;
}
Expand All @@ -49,17 +52,25 @@ public byte[] getJobInfo() {
return jobInfo;
}

public long getExpiredAt() {
return expiredAt;
}

public boolean isExpired() {
return System.currentTimeMillis() > expiredAt;
}

public String toJson() {
return GsonUtils.GSON.toJson(this);
}

@Override
public String toString() {
// return toJson();
return "Snapshot{"
+ "label='" + label + '\''
+ ", meta=" + meta
+ ", jobInfo=" + jobInfo
+ ", expiredAt=" + expiredAt
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2813,12 +2813,16 @@ private TGetSnapshotResult getSnapshotImpl(TGetSnapshotRequest request, String c
if (snapshot == null) {
result.getStatus().setStatusCode(TStatusCode.SNAPSHOT_NOT_EXIST);
result.getStatus().addToErrorMsgs(String.format("snapshot %s not exist", label));
} else if (snapshot.isExpired()) {
result.getStatus().setStatusCode(TStatusCode.SNAPSHOT_EXPIRED);
result.getStatus().addToErrorMsgs(String.format("snapshot %s is expired", label));
} else {
byte[] meta = snapshot.getMeta();
byte[] jobInfo = snapshot.getJobInfo();
long expiredAt = snapshot.getExpiredAt();

LOG.info("get snapshot info, snapshot: {}, meta size: {}, job info size: {}",
label, meta.length, jobInfo.length);
LOG.info("get snapshot info, snapshot: {}, meta size: {}, job info size: {}, expired at: {}",
label, meta.length, jobInfo.length, expiredAt);
if (request.isEnableCompress()) {
meta = GZIPUtils.compress(meta);
jobInfo = GZIPUtils.compress(jobInfo);
Expand All @@ -2830,6 +2834,7 @@ private TGetSnapshotResult getSnapshotImpl(TGetSnapshotRequest request, String c
}
result.setMeta(meta);
result.setJobInfo(jobInfo);
result.setExpiredAt(expiredAt);
}

return result;
Expand Down
1 change: 1 addition & 0 deletions gensrc/thrift/FrontendService.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,7 @@ struct TGetSnapshotResult {
3: optional binary job_info
4: optional Types.TNetworkAddress master_address
5: optional bool compressed;
6: optional i64 expiredAt; // in millis
}

struct TTableRef {
Expand Down
7 changes: 7 additions & 0 deletions gensrc/thrift/Status.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ enum TStatusCode {
TABLET_MISSING = 72,

NOT_MASTER = 73,

OBTAIN_LOCK_FAILED = 74,

SNAPSHOT_EXPIRED = 75,

// Not be larger than 200, see status.h
// And all error code defined here, should also be defined in status.h
}

struct TStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ class Syncer {
logger.error("TGetSnapshotResult meta is unset.")
} else if (!result.isSetJobInfo()) {
logger.error("TGetSnapshotResult job info is unset.")
} else if (!result.isSetExpiredAt()) {
logger.error("TGetSnapshotResult expiredAt is unset.")
} else {
isCheckedOK = true
}
Expand Down
Loading