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

fix author procedure deserialize problem. #14675

Open
wants to merge 1 commit into
base: rc/1.3.3
Choose a base branch
from
Open
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 @@ -24,6 +24,7 @@
import org.apache.iotdb.commons.conf.CommonConfig;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.exception.IoTDBException;
import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.commons.utils.ThriftCommonsSerDeUtils;
import org.apache.iotdb.confignode.client.CnToDnRequestType;
import org.apache.iotdb.confignode.client.sync.SyncDataNodeClientPool;
Expand Down Expand Up @@ -69,7 +70,7 @@ public class AuthOperationProcedure extends AbstractNodeProcedure<AuthOperationP
private static final int RETRY_THRESHOLD = 2;
private static final CommonConfig commonConfig = CommonDescriptor.getInstance().getConfig();

private final List<Pair<TDataNodeConfiguration, Long>> dataNodesToInvalid = new ArrayList<>();
private List<Pair<TDataNodeConfiguration, Long>> dataNodesToInvalid = new ArrayList<>();

private List<TDataNodeConfiguration> datanodes;

Expand All @@ -87,6 +88,11 @@ public AuthOperationProcedure(
this.timeoutMS = commonConfig.getDatanodeTokenTimeoutMS();
}

@TestOnly
public void setDataNodeToInvalid(List<Pair<TDataNodeConfiguration, Long>> nodeList) {
dataNodesToInvalid = nodeList;
}

@Override
protected Flow executeFromState(ConfigNodeProcedureEnv env, AuthOperationProcedureState state) {
try {
Expand Down Expand Up @@ -221,19 +227,19 @@ public void deserialize(ByteBuffer byteBuffer) {
}
this.timeoutMS = ReadWriteIOUtils.readLong(byteBuffer);
try {
ReadWriteIOUtils.readInt(byteBuffer);
int cap = ReadWriteIOUtils.readInt(byteBuffer);
int position = byteBuffer.position();
this.plan = (AuthorPlan) ConfigPhysicalPlan.Factory.create(byteBuffer);
byteBuffer.position(cap + position);
} catch (IOException e) {
LOGGER.error("IO error when deserialize authplan.", e);
}
if (byteBuffer.hasRemaining()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why removing this judgement? if you think this bytebuffer will always has remaining, you should add a else branch and then throw exeception

size = ReadWriteIOUtils.readInt(byteBuffer);
for (int i = 0; i < size; i++) {
TDataNodeConfiguration datanode =
ThriftCommonsSerDeUtils.deserializeTDataNodeConfiguration(byteBuffer);
Long timeStamp = ReadWriteIOUtils.readLong(byteBuffer);
this.dataNodesToInvalid.add(new Pair<>(datanode, timeStamp));
}
size = ReadWriteIOUtils.readInt(byteBuffer);
for (int i = 0; i < size; i++) {
TDataNodeConfiguration datanode =
ThriftCommonsSerDeUtils.deserializeTDataNodeConfiguration(byteBuffer);
Long timeStamp = ReadWriteIOUtils.readLong(byteBuffer);
this.dataNodesToInvalid.add(new Pair<>(datanode, timeStamp));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.iotdb.confignode.consensus.request.write.auth.AuthorPlan;
import org.apache.iotdb.confignode.procedure.store.ProcedureFactory;

import org.apache.tsfile.utils.Pair;
import org.apache.tsfile.utils.PublicBAOS;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -75,11 +76,14 @@ public void serializeDeserializeTest() throws IOException {
"role1",
"123456",
"123456",
Collections.singleton(1),
Collections.singleton(i),
false,
Collections.singletonList(new PartialPath("root.t1"))),
datanodes,
false);
List<Pair<TDataNodeConfiguration, Long>> dataNodeToInvalid = new ArrayList<>();
dataNodeToInvalid.add(new Pair<>(dataNodeConfiguration, 1L));
proc.setDataNodeToInvalid(dataNodeToInvalid);
proc.serialize(outputStream);
final ByteBuffer buffer =
ByteBuffer.wrap(byteArrayOutputStream.getBuf(), 0, byteArrayOutputStream.size());
Expand Down
Loading