Skip to content

Commit

Permalink
Workaround to avoid NameId conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed Sep 6, 2023
1 parent 3389bbf commit f24ea56
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.xpack.esql.io.stream.PlanStreamOutput;
import org.elasticsearch.xpack.esql.plan.physical.PhysicalPlan;
import org.elasticsearch.xpack.esql.session.EsqlConfiguration;
import org.elasticsearch.xpack.ql.expression.NameId;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -59,6 +60,8 @@ final class DataNodeRequest extends TransportRequest implements IndicesRequest {
this.configuration = new EsqlConfiguration(in);
this.shardIds = in.readCollectionAsList(ShardId::new);
this.aliasFilters = in.readMap(Index::new, AliasFilter::readFrom);
// TODO: remove this shared local counter
NameId.advanceGlobalId(in.readVLong());
this.plan = new PlanStreamInput(in, planNameRegistry, in.namedWriteableRegistry(), configuration).readPhysicalPlanNode();
}

Expand All @@ -69,6 +72,8 @@ public void writeTo(StreamOutput out) throws IOException {
configuration.writeTo(out);
out.writeCollection(shardIds);
out.writeMap(aliasFilters);
// TODO: remove this shared local counter
out.writeVLong(new NameId().getId());
new PlanStreamOutput(out, planNameRegistry).writePhysicalPlanNode(plan);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ public NameId(long id) {
this.id = id;
}

/**
* TODO:
* This is a workaround to prevent NameId conflicts in multi-node environments. Currently, when a NameId is serialized,
* its local ID is also serialized to the remote node. If the remote node generates a new NameId, it could potentially
* have the same ID as an existing one that was deserialized, leading to an incorrect local plan on the remote node.
* <p>
* It's important to note that while conflicts might still occur between multiple computations with this approach, there
* is no conflicts within a single computation. We only need to ensure no conflict in a single computation to ensure the correctness.
*/
public static void advanceGlobalId(long other) {
COUNTER.accumulateAndGet(other, Math::max);
}

public long getId() {
return id;
}

@Override
public int hashCode() {
return Objects.hash(id);
Expand Down

0 comments on commit f24ea56

Please sign in to comment.