Skip to content
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 @@ -144,9 +144,6 @@ private void constructBlackList(final ConfigNodeProcedureEnv env) {

private void invalidateCache(final ConfigNodeProcedureEnv env) {
try {
// Cannot roll back after cache invalidation
// Because we do not know whether there are time series successfully created
alreadyRollback = true;
executeInvalidateCache(env);
setNextState(UnsetTemplateState.CHECK_DATANODE_TEMPLATE_ACTIVATION);
} catch (final ProcedureException e) {
Expand Down Expand Up @@ -217,21 +214,26 @@ protected void rollbackState(
}
alreadyRollback = true;
ProcedureException rollbackException;
final TSStatus status =
env.getConfigManager()
.getClusterSchemaManager()
.rollbackPreUnsetSchemaTemplate(template.getId(), path);
if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
return;
} else {
LOGGER.error(
"Failed to rollback pre unset template operation of template {} set on {}",
template.getName(),
path);
rollbackException =
new ProcedureException(
new MetadataException(
"Rollback template pre unset failed because of" + status.getMessage()));
try {
executeRollbackInvalidateCache(env);
final TSStatus status =
env.getConfigManager()
.getClusterSchemaManager()
.rollbackPreUnsetSchemaTemplate(template.getId(), path);
if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
return;
} else {
LOGGER.error(
"Failed to rollback pre unset template operation of template {} set on {}",
template.getName(),
path);
rollbackException =
new ProcedureException(
new MetadataException(
"Rollback template pre unset failed because of" + status.getMessage()));
}
} catch (final ProcedureException e) {
rollbackException = e;
}
try {
executeInvalidateCache(env);
Expand All @@ -244,6 +246,42 @@ protected void rollbackState(
}
}

private void executeRollbackInvalidateCache(ConfigNodeProcedureEnv env)
throws ProcedureException {
Map<Integer, TDataNodeLocation> dataNodeLocationMap =
env.getConfigManager().getNodeManager().getRegisteredDataNodeLocations();
TUpdateTemplateReq rollbackTemplateSetInfoReq = new TUpdateTemplateReq();
rollbackTemplateSetInfoReq.setType(
TemplateInternalRPCUpdateType.ROLLBACK_INVALIDATE_TEMPLATE_SET_INFO.toByte());
rollbackTemplateSetInfoReq.setTemplateInfo(getAddTemplateSetInfo());
DataNodeAsyncRequestContext<TUpdateTemplateReq, TSStatus> clientHandler =
new DataNodeAsyncRequestContext<>(
CnToDnAsyncRequestType.UPDATE_TEMPLATE,
rollbackTemplateSetInfoReq,
dataNodeLocationMap);
CnToDnInternalServiceAsyncRequestManager.getInstance().sendAsyncRequestWithRetry(clientHandler);
Map<Integer, TSStatus> statusMap = clientHandler.getResponseMap();
for (TSStatus status : statusMap.values()) {
// all dataNodes must clear the related template cache
if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
LOGGER.error(
"Failed to rollback template cache of template {} set on {}", template.getName(), path);
throw new ProcedureException(new MetadataException("Rollback template cache failed"));
}
}
}

private ByteBuffer getAddTemplateSetInfo() {
if (this.addTemplateSetInfo == null) {
this.addTemplateSetInfo =
ByteBuffer.wrap(
TemplateInternalRPCUtil.generateAddTemplateSetInfoBytes(
template, path.getFullPath()));
}

return addTemplateSetInfo;
}

@Override
protected boolean isRollbackSupported(final UnsetTemplateState unsetTemplateState) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,6 @@ public TSStatus setTTL(TSetTTLReq req) throws TException {
@Override
public TSStatus updateTemplate(final TUpdateTemplateReq req) {
switch (TemplateInternalRPCUpdateType.getType(req.type)) {
// Reserved for rolling upgrade
case ROLLBACK_INVALIDATE_TEMPLATE_SET_INFO:
ClusterTemplateManager.getInstance().addTemplateSetInfo(req.getTemplateInfo());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.nio.ByteBuffer;

public enum TemplateInternalRPCUpdateType {
// Deprecated
ROLLBACK_INVALIDATE_TEMPLATE_SET_INFO((byte) 0),
INVALIDATE_TEMPLATE_SET_INFO((byte) 1),
ADD_TEMPLATE_PRE_SET_INFO((byte) 2),
Expand Down
Loading