Skip to content

Commit

Permalink
Make Blocks and Vectors Releasable
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHegarty committed Sep 13, 2023
1 parent 10c8f2a commit f26b195
Show file tree
Hide file tree
Showing 42 changed files with 221 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public String toString() {
+ Arrays.toString(values)
+ ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[positions=" + getPositionCount() + ", values=" + Arrays.toString(values) + ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[vector=" + vector + "]";
}

@Override
public void close() {
vector.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ public String toString() {
+ values.size()
+ ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.RamUsageEstimator;
import org.elasticsearch.common.util.BytesRefArray;
import org.elasticsearch.core.Releasables;

/**
* Vector implementation that stores an array of BytesRef values.
Expand Down Expand Up @@ -77,4 +78,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[positions=" + getPositionCount() + ']';
}

@Override
public void close() {
Releasables.close(values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[vector=" + vector + "]";
}

@Override
public void close() {
vector.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[positions=" + getPositionCount() + ", value=" + value + ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[positions=" + getPositionCount() + ", value=" + value + ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[positions=" + getPositionCount() + ", value=" + value + ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[positions=" + getPositionCount() + ", value=" + value + ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[positions=" + getPositionCount() + ", value=" + value + ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public String toString() {
+ Arrays.toString(values)
+ ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[positions=" + getPositionCount() + ", values=" + Arrays.toString(values) + ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[vector=" + vector + "]";
}

@Override
public void close() {
vector.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ private void appendValues(StringBuilder sb) {
sb.append(']');
}
}

@Override
public void close() {
block.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ private void appendValues(StringBuilder sb) {
sb.append(getBoolean(i));
}
}

@Override
public void close() {
vector.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,9 @@ private void appendValues(StringBuilder sb) {
sb.append(']');
}
}

@Override
public void close() {
block.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,9 @@ private void appendValues(StringBuilder sb) {
sb.append(getBytesRef(i, new BytesRef()));
}
}

@Override
public void close() {
vector.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ private void appendValues(StringBuilder sb) {
sb.append(']');
}
}

@Override
public void close() {
block.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ private void appendValues(StringBuilder sb) {
sb.append(getDouble(i));
}
}

@Override
public void close() {
vector.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ private void appendValues(StringBuilder sb) {
sb.append(']');
}
}

@Override
public void close() {
block.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ private void appendValues(StringBuilder sb) {
sb.append(getInt(i));
}
}

@Override
public void close() {
vector.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ private void appendValues(StringBuilder sb) {
sb.append(']');
}
}

@Override
public void close() {
block.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ private void appendValues(StringBuilder sb) {
sb.append(getLong(i));
}
}

@Override
public void close() {
vector.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public String toString() {
+ Arrays.toString(values)
+ ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[positions=" + getPositionCount() + ", values=" + Arrays.toString(values) + ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[vector=" + vector + "]";
}

@Override
public void close() {
vector.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public String toString() {
+ Arrays.toString(values)
+ ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[positions=" + getPositionCount() + ", values=" + Arrays.toString(values) + ']';
}

@Override
public void close() {
// no-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ public int hashCode() {
public String toString() {
return getClass().getSimpleName() + "[vector=" + vector + "]";
}

@Override
public void close() {
vector.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.lucene.util.Accountable;
import org.elasticsearch.common.io.stream.NamedWriteable;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.core.Releasable;

import java.util.List;

Expand All @@ -31,7 +32,7 @@
*
* <p> Block are immutable and can be passed between threads.
*/
public interface Block extends Accountable, NamedWriteable {
public interface Block extends Accountable, NamedWriteable, Releasable {

/**
* {@return an efficient dense single-value view of this block}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public String toString() {
return "ConstantNullBlock[positions=" + getPositionCount() + "]";
}

@Override
public void close() {
// no-op
}

static class Builder implements Block.Builder {
private int positionCount;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.apache.lucene.util.RamUsageEstimator;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.core.Releasables;

import java.io.IOException;

Expand Down Expand Up @@ -56,6 +57,11 @@ public long ramBytesUsed() {
return BASE_RAM_BYTES_USED + RamUsageEstimator.sizeOf(vector);
}

@Override
public void close() {
Releasables.close(vector);
}

/**
* A builder the for {@link DocBlock}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.apache.lucene.util.IntroSorter;
import org.apache.lucene.util.RamUsageEstimator;
import org.elasticsearch.core.Releasables;

/**
* {@link Vector} where each entry references a lucene document.
Expand Down Expand Up @@ -198,4 +199,9 @@ public static long ramBytesEstimated(
public long ramBytesUsed() {
return ramBytesEstimated(shards, segments, docs, shardSegmentDocMapForwards, shardSegmentDocMapBackwards);
}

@Override
public void close() {
Releasables.close(shards, segments, docs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
package org.elasticsearch.compute.data;

import org.apache.lucene.util.Accountable;
import org.elasticsearch.core.Releasable;

/**
* A dense Vector of single values.
*/
public interface Vector extends Accountable {
public interface Vector extends Accountable, Releasable {

/**
* {@return Returns a Block view over this vector.}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,9 @@ $else$
$endif$
+ ']';
}

@Override
public void close() {
// no-op
}
}
Loading

0 comments on commit f26b195

Please sign in to comment.