Skip to content

Commit

Permalink
Clean unused code
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Feb 25, 2025
1 parent 3a0f7cf commit f3551bc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,9 @@ static class AllPermissionCheck implements BootstrapCheck {

@Override
public final BootstrapCheckResult check(BootstrapContext context) {
// if (isAllPermissionGranted()) {
// return BootstrapCheck.BootstrapCheckResult.failure("granting the all permission effectively disables security");
// }
if (isAllPermissionGranted()) {
return BootstrapCheck.BootstrapCheckResult.failure("granting the all permission effectively disables security");
}
return BootstrapCheckResult.success();
}

Expand Down
27 changes: 8 additions & 19 deletions server/src/main/java/org/opensearch/common/Rounding.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.opensearch.common.LocalTimeOffset.Gap;
import org.opensearch.common.LocalTimeOffset.Overlap;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.round.Roundable;
import org.opensearch.common.round.RoundableFactory;
import org.opensearch.common.time.DateUtils;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.common.io.stream.StreamInput;
Expand All @@ -60,7 +62,6 @@
import java.time.temporal.TemporalQueries;
import java.time.zone.ZoneOffsetTransition;
import java.time.zone.ZoneRules;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
Expand Down Expand Up @@ -454,7 +455,7 @@ protected Prepared maybeUseArray(long minUtcMillis, long maxUtcMillis, int max)
values = ArrayUtil.grow(values, i + 1);
values[i++] = rounded;
}
return new ArrayRounding(values, i, this);
return new ArrayRounding(RoundableFactory.create(values, i), this);
}
}

Expand All @@ -463,26 +464,17 @@ protected Prepared maybeUseArray(long minUtcMillis, long maxUtcMillis, int max)
* pre-calculated round-down points to speed up lookups.
*/
private static class ArrayRounding implements Prepared {
private final long[] values;
private final int max;
private final Roundable roundable;
private final Prepared delegate;

private ArrayRounding(long[] values, int max, Prepared delegate) {
this.values = values;
this.max = max;
public ArrayRounding(Roundable roundable, Prepared delegate) {
this.roundable = roundable;
this.delegate = delegate;
}

@Override
public long round(long utcMillis) {
assert values[0] <= utcMillis : utcMillis + " must be after " + values[0];
int idx = Arrays.binarySearch(values, 0, max, utcMillis);
assert idx != -1 : "The insertion point is before the array! This should have tripped the assertion above.";
assert -1 - idx <= values.length : "This insertion point is after the end of the array.";
if (idx < 0) {
idx = -2 - idx;
}
return values[idx];
return roundable.floor(utcMillis);
}

@Override
Expand Down Expand Up @@ -732,10 +724,7 @@ private class FixedNotToMidnightRounding extends TimeUnitPreparedRounding {

@Override
public long round(long utcMillis) {
long localTime = offset.utcToLocalTime(utcMillis);
long roundedLocalTime = unit.roundFloor(localTime);
return offset.localToUtcInThisOffset(roundedLocalTime);
// return offset.localToUtcInThisOffset(unit.roundFloor(offset.utcToLocalTime(utcMillis)));
return offset.localToUtcInThisOffset(unit.roundFloor(offset.utcToLocalTime(utcMillis)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import java.util.stream.Collectors;

import static org.opensearch.search.aggregations.MultiBucketConsumerService.MAX_BUCKET_SETTING;
import static org.opensearch.search.aggregations.bucket.filterrewrite.AggregatorBridge.segmentMatchAll;

/**
* Main aggregator that aggregates docs from multiple aggregations
Expand Down Expand Up @@ -564,18 +565,18 @@ private void processLeafFromQuery(LeafReaderContext ctx, Sort indexSortPrefix) t

// @Override
// protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws IOException {
// finishLeaf(); // May need to wrap up previous leaf if it could not be precomputed
// return filterRewriteOptimizationContext.tryOptimize(ctx, this::incrementBucketDocCount, segmentMatchAll(context, ctx));
// finishLeaf(); // May need to wrap up previous leaf if it could not be precomputed
// return filterRewriteOptimizationContext.tryOptimize(ctx, this::incrementBucketDocCount, segmentMatchAll(context, ctx));
// }

@Override
protected LeafBucketCollector getLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) throws IOException {
boolean optimized = filterRewriteOptimizationContext.tryOptimize(
ctx,
this::incrementBucketDocCount,
segmentMatchAll(context, ctx),
collectableSubAggregators,
sub
ctx,
this::incrementBucketDocCount,
segmentMatchAll(context, ctx),
collectableSubAggregators,
sub
);
if (optimized) throw new CollectionTerminatedException();

Expand Down

This file was deleted.

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

import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.search.CollectionTerminatedException;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.util.CollectionUtil;
Expand Down Expand Up @@ -196,7 +197,7 @@ protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws
return true;
}
}
return filterRewriteOptimizationContext.tryOptimize(ctx, this::incrementBucketDocCount, segmentMatchAll(context, ctx));
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@

package org.opensearch.search.aggregations.bucket.range;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.CollectionTerminatedException;
import org.apache.lucene.search.ScoreMode;
import org.opensearch.core.ParseField;
import org.opensearch.core.common.io.stream.StreamInput;
Expand Down Expand Up @@ -255,8 +254,6 @@ public boolean equals(Object obj) {

private final FilterRewriteOptimizationContext filterRewriteOptimizationContext;

private final Logger logger = LogManager.getLogger(RangeAggregator.class);

public RangeAggregator(
String name,
AggregatorFactories factories,
Expand Down Expand Up @@ -312,28 +309,20 @@ public ScoreMode scoreMode() {
return super.scoreMode();
}

@Override
protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws IOException {
if (segmentMatchAll(context, ctx)) {
return filterRewriteOptimizationContext.tryOptimize(ctx, this::incrementBucketDocCount, false);
}
return false;
}
// @Override
// protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws IOException {
// if (segmentMatchAll(context, ctx)) {
// return filterRewriteOptimizationContext.tryOptimize(ctx, this::incrementBucketDocCount, false);
// }
// return false;
// }

@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {

if (segmentMatchAll(context, ctx)
&& filterRewriteOptimizationContext.tryOptimize(
ctx,
this::incrementBucketDocCount,
false,
collectableSubAggregators,
sub
)) {
throw new CollectionTerminatedException();
}

if (segmentMatchAll(context, ctx)
&& filterRewriteOptimizationContext.tryOptimize(ctx, this::incrementBucketDocCount, false, collectableSubAggregators, sub)) {
throw new CollectionTerminatedException();
}

final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
return new LeafBucketCollectorBase(sub, values) {
Expand Down

0 comments on commit f3551bc

Please sign in to comment.