[improvement](replica) set replica drop write editlog (#30345)

* set replica drop write editlog

* update test
This commit is contained in:
yujun
2024-01-25 15:32:56 +08:00
committed by yiguolei
parent e8a20d8899
commit 4681958cf7
4 changed files with 34 additions and 28 deletions

View File

@ -5543,18 +5543,17 @@ public class Env {
long tabletId = stmt.getTabletId();
long backendId = stmt.getBackendId();
ReplicaStatus status = stmt.getStatus();
setReplicaStatusInternal(tabletId, backendId, status, false);
}
public void setReplicaStatus(long tabletId, long backendId, ReplicaStatus status) throws MetaNotFoundException {
setReplicaStatusInternal(tabletId, backendId, status, false);
long userDropTime = status == ReplicaStatus.DROP ? System.currentTimeMillis() : -1L;
setReplicaStatusInternal(tabletId, backendId, status, userDropTime, false);
}
public void replaySetReplicaStatus(SetReplicaStatusOperationLog log) throws MetaNotFoundException {
setReplicaStatusInternal(log.getTabletId(), log.getBackendId(), log.getReplicaStatus(), true);
setReplicaStatusInternal(log.getTabletId(), log.getBackendId(), log.getReplicaStatus(),
log.getUserDropTime(), true);
}
private void setReplicaStatusInternal(long tabletId, long backendId, ReplicaStatus status, boolean isReplay)
private void setReplicaStatusInternal(long tabletId, long backendId, ReplicaStatus status, long userDropTime,
boolean isReplay)
throws MetaNotFoundException {
try {
TabletMeta meta = tabletInvertedIndex.getTabletMeta(tabletId);
@ -5569,22 +5568,25 @@ public class Env {
if (replica == null) {
throw new MetaNotFoundException("replica does not exist on backend, beId=" + backendId);
}
boolean updated = false;
if (status == ReplicaStatus.BAD || status == ReplicaStatus.OK) {
replica.setUserDrop(false);
replica.setUserDropTime(-1L);
if (replica.setBad(status == ReplicaStatus.BAD)) {
if (!isReplay) {
SetReplicaStatusOperationLog log = new SetReplicaStatusOperationLog(backendId, tabletId,
status);
getEditLog().logSetReplicaStatus(log);
}
updated = true;
LOG.info("set replica {} of tablet {} on backend {} as {}. is replay: {}", replica.getId(),
tabletId, backendId, status, isReplay);
}
} else if (status == ReplicaStatus.DROP) {
replica.setUserDrop(true);
replica.setUserDropTime(userDropTime);
updated = true;
LOG.info("set replica {} of tablet {} on backend {} as {}.", replica.getId(),
tabletId, backendId, status);
}
if (updated && !isReplay) {
SetReplicaStatusOperationLog log = new SetReplicaStatusOperationLog(backendId, tabletId,
status, userDropTime);
getEditLog().logSetReplicaStatus(log);
}
} finally {
table.writeUnlock();
}

View File

@ -763,18 +763,8 @@ public class Replica implements Writable {
return postWatermarkTxnId;
}
public void setUserDrop(boolean isDrop) {
if (isDrop) {
userDropTime = System.currentTimeMillis();
} else {
userDropTime = -1;
}
}
public boolean isAlive() {
return getState() != ReplicaState.CLONE
&& getState() != ReplicaState.DECOMMISSION
&& !isBad();
public void setUserDropTime(long userDropTime) {
this.userDropTime = userDropTime;
}
public boolean isUserDrop() {
@ -788,6 +778,12 @@ public class Replica implements Writable {
return false;
}
public boolean isAlive() {
return getState() != ReplicaState.CLONE
&& getState() != ReplicaState.DECOMMISSION
&& !isBad();
}
public boolean isScheduleAvailable() {
return Env.getCurrentSystemInfo().checkBackendScheduleAvailable(backendId)
&& !isUserDrop();

View File

@ -36,11 +36,14 @@ public class SetReplicaStatusOperationLog implements Writable {
private long tabletId;
@SerializedName(value = "replicaStatus")
private ReplicaStatus replicaStatus;
@SerializedName(value = "userDropTime")
private long userDropTime;
public SetReplicaStatusOperationLog(long backendId, long tabletId, ReplicaStatus replicaStatus) {
public SetReplicaStatusOperationLog(long backendId, long tabletId, ReplicaStatus replicaStatus, long userDropTime) {
this.backendId = backendId;
this.tabletId = tabletId;
this.replicaStatus = replicaStatus;
this.userDropTime = userDropTime;
}
public long getTabletId() {
@ -55,6 +58,10 @@ public class SetReplicaStatusOperationLog implements Writable {
return replicaStatus;
}
public long getUserDropTime() {
return userDropTime;
}
public static SetReplicaStatusOperationLog read(DataInput in) throws IOException {
String json = Text.readString(in);
return GsonUtils.GSON.fromJson(json, SetReplicaStatusOperationLog.class);