Skip to content

Commit

Permalink
ESQL: Simplify vector ownership (#103631)
Browse files Browse the repository at this point in the history
* Do not associate a vector with a fixed block
* Do not release blocks if their vectors are released
  • Loading branch information
alex-spies committed Dec 21, 2023
1 parent e9795cd commit 48dcb85
Show file tree
Hide file tree
Showing 31 changed files with 27 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ final class BooleanArrayVector extends AbstractVector implements BooleanVector {

private final boolean[] values;

private final BooleanBlock block;

BooleanArrayVector(boolean[] values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new BooleanVectorBlock(this);
}

@Override
public BooleanBlock asBlock() {
return block;
return new BooleanVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ public final class BooleanBigArrayVector extends AbstractVector implements Boole

private final BitArray values;

private final BooleanBlock block;

public BooleanBigArrayVector(BitArray values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new BooleanVectorBlock(this);
}

@Override
public BooleanBlock asBlock() {
return block;
return new BooleanVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ public String toString() {
return getClass().getSimpleName() + "[vector=" + vector + "]";
}

@Override
public boolean isReleased() {
return super.isReleased() || vector.isReleased();
}

@Override
public void closeInternal() {
assert (vector.isReleased() == false) : "can't release block [" + this + "] containing already released vector";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ final class BytesRefArrayVector extends AbstractVector implements BytesRefVector

private final BytesRefArray values;

private final BytesRefBlock block;

BytesRefArrayVector(BytesRefArray values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new BytesRefVectorBlock(this);
}

@Override
public BytesRefBlock asBlock() {
return block;
return new BytesRefVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ public String toString() {
return getClass().getSimpleName() + "[vector=" + vector + "]";
}

@Override
public boolean isReleased() {
return super.isReleased() || vector.isReleased();
}

@Override
public void closeInternal() {
assert (vector.isReleased() == false) : "can't release block [" + this + "] containing already released vector";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ final class ConstantBooleanVector extends AbstractVector implements BooleanVecto

private final boolean value;

private final BooleanBlock block;

ConstantBooleanVector(boolean value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new BooleanVectorBlock(this);
}

@Override
Expand All @@ -34,7 +31,7 @@ public boolean getBoolean(int position) {

@Override
public BooleanBlock asBlock() {
return block;
return new BooleanVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ final class ConstantBytesRefVector extends AbstractVector implements BytesRefVec
.shallowSizeOfInstance(BytesRef.class);
private final BytesRef value;

private final BytesRefBlock block;

ConstantBytesRefVector(BytesRef value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new BytesRefVectorBlock(this);
}

@Override
Expand All @@ -35,7 +32,7 @@ public BytesRef getBytesRef(int position, BytesRef ignore) {

@Override
public BytesRefBlock asBlock() {
return block;
return new BytesRefVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ final class ConstantDoubleVector extends AbstractVector implements DoubleVector

private final double value;

private final DoubleBlock block;

ConstantDoubleVector(double value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new DoubleVectorBlock(this);
}

@Override
Expand All @@ -34,7 +31,7 @@ public double getDouble(int position) {

@Override
public DoubleBlock asBlock() {
return block;
return new DoubleVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ final class ConstantIntVector extends AbstractVector implements IntVector {

private final int value;

private final IntBlock block;

ConstantIntVector(int value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new IntVectorBlock(this);
}

@Override
Expand All @@ -34,7 +31,7 @@ public int getInt(int position) {

@Override
public IntBlock asBlock() {
return block;
return new IntVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ final class ConstantLongVector extends AbstractVector implements LongVector {

private final long value;

private final LongBlock block;

ConstantLongVector(long value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new LongVectorBlock(this);
}

@Override
Expand All @@ -34,7 +31,7 @@ public long getLong(int position) {

@Override
public LongBlock asBlock() {
return block;
return new LongVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ final class DoubleArrayVector extends AbstractVector implements DoubleVector {

private final double[] values;

private final DoubleBlock block;

DoubleArrayVector(double[] values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new DoubleVectorBlock(this);
}

@Override
public DoubleBlock asBlock() {
return block;
return new DoubleVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ public final class DoubleBigArrayVector extends AbstractVector implements Double

private final DoubleArray values;

private final DoubleBlock block;

public DoubleBigArrayVector(DoubleArray values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new DoubleVectorBlock(this);
}

@Override
public DoubleBlock asBlock() {
return block;
return new DoubleVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ public String toString() {
return getClass().getSimpleName() + "[vector=" + vector + "]";
}

@Override
public boolean isReleased() {
return super.isReleased() || vector.isReleased();
}

@Override
public void closeInternal() {
assert (vector.isReleased() == false) : "can't release block [" + this + "] containing already released vector";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ final class IntArrayVector extends AbstractVector implements IntVector {

private final int[] values;

private final IntBlock block;

IntArrayVector(int[] values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new IntVectorBlock(this);
}

@Override
public IntBlock asBlock() {
return block;
return new IntVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ public final class IntBigArrayVector extends AbstractVector implements IntVector

private final IntArray values;

private final IntBlock block;

public IntBigArrayVector(IntArray values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new IntVectorBlock(this);
}

@Override
public IntBlock asBlock() {
return block;
return new IntVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ public String toString() {
return getClass().getSimpleName() + "[vector=" + vector + "]";
}

@Override
public boolean isReleased() {
return super.isReleased() || vector.isReleased();
}

@Override
public void closeInternal() {
assert (vector.isReleased() == false) : "can't release block [" + this + "] containing already released vector";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ final class LongArrayVector extends AbstractVector implements LongVector {

private final long[] values;

private final LongBlock block;

LongArrayVector(long[] values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new LongVectorBlock(this);
}

@Override
public LongBlock asBlock() {
return block;
return new LongVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ public final class LongBigArrayVector extends AbstractVector implements LongVect

private final LongArray values;

private final LongBlock block;

public LongBigArrayVector(LongArray values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new LongVectorBlock(this);
}

@Override
public LongBlock asBlock() {
return block;
return new LongVectorBlock(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ public String toString() {
return getClass().getSimpleName() + "[vector=" + vector + "]";
}

@Override
public boolean isReleased() {
return super.isReleased() || vector.isReleased();
}

@Override
public void closeInternal() {
assert (vector.isReleased() == false) : "can't release block [" + this + "] containing already released vector";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void add(Page page, GroupingAggregatorFunction.AddInput addInput) {
addInput.add(0, groupIds);
}
} else {
try (IntBlock groupIds = add(booleanVector).asBlock()) {
addInput.add(0, groupIds.asVector());
try (IntVector groupIds = add(booleanVector)) {
addInput.add(0, groupIds);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void allowPassingToDifferentDriver() {
}

@Override
public boolean isReleased() {
public final boolean isReleased() {
return hasReferences() == false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ public long ramBytesUsed() {
return BASE_RAM_BYTES_USED + RamUsageEstimator.sizeOf(vector);
}

@Override
public boolean isReleased() {
return super.isReleased() || vector.isReleased();
}

@Override
public void closeInternal() {
assert (vector.isReleased() == false) : "can't release block [" + this + "] containing already released vector";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public final class DocVector extends AbstractVector implements Vector {
*/
private int[] shardSegmentDocMapBackwards;

final DocBlock block;

public DocVector(IntVector shards, IntVector segments, IntVector docs, Boolean singleSegmentNonDecreasing) {
super(shards.getPositionCount(), null);
this.shards = shards;
Expand All @@ -64,7 +62,6 @@ public DocVector(IntVector shards, IntVector segments, IntVector docs, Boolean s
"invalid position count [" + shards.getPositionCount() + " != " + docs.getPositionCount() + "]"
);
}
block = new DocBlock(this);
}

public IntVector shards() {
Expand Down Expand Up @@ -171,7 +168,7 @@ protected void swap(int i, int j) {

@Override
public DocBlock asBlock() {
return block;
return new DocBlock(this);
}

@Override
Expand Down

0 comments on commit 48dcb85

Please sign in to comment.