Skip to content

Commit

Permalink
fix author procedure deserialize problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinLeeo committed Jan 11, 2025
1 parent c933332 commit a97cb32
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
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()) {
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

0 comments on commit a97cb32

Please sign in to comment.