Skip to content

Commit

Permalink
Addressed code review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta committed May 4, 2023
1 parent 97c2db8 commit 8f1ae77
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,13 @@ public static int sortAndDedup(final BytesRefArray bytes, final int[] indices) {
}
return uniqueCount;
}

public static long bytesToLong(BytesRef bytes) {
int high = (bytes.bytes[bytes.offset + 0] << 24) | ((bytes.bytes[bytes.offset + 1] & 0xff) << 16) | ((bytes.bytes[bytes.offset + 2]
& 0xff) << 8) | (bytes.bytes[bytes.offset + 3] & 0xff);
int low = (bytes.bytes[bytes.offset + 4] << 24) | ((bytes.bytes[bytes.offset + 5] & 0xff) << 16) | ((bytes.bytes[bytes.offset + 6]
& 0xff) << 8) | (bytes.bytes[bytes.offset + 7] & 0xff);
return (((long) high) << 32) | (low & 0x0ffffffffL);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import org.apache.lucene.util.BytesRefArray;
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.Counter;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.test.OpenSearchTestCase;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -86,4 +88,10 @@ public void testSortByteRefArray() {
assertThat(array.get(spare, indices[i]), equalTo(iterator.next()));
}
}

public void testBytesToLong() {
final long value = randomLong();
final BytesReference buffer = BytesReference.fromByteBuffer(ByteBuffer.allocate(8).putLong(value).flip());
assertThat(BytesRefUtils.bytesToLong(buffer.toBytesRef()), equalTo(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
import org.opensearch.cluster.routing.ShardRoutingState;
import org.opensearch.cluster.routing.UnassignedInfo;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.BytesRefUtils;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.ByteSizeUnit;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.util.BytesRefUtils;
import org.opensearch.index.Index;
import org.opensearch.index.IndexService;
import org.opensearch.index.engine.Engine;
Expand Down
28 changes: 0 additions & 28 deletions server/src/main/java/org/opensearch/common/BytesRefUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import org.opensearch.cluster.routing.allocation.AllocationService;
import org.opensearch.cluster.service.ClusterManagerTaskThrottler;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.BytesRefUtils;
import org.opensearch.common.Nullable;
import org.opensearch.common.Numbers;
import org.opensearch.common.SetOnce;
Expand Down Expand Up @@ -95,6 +94,7 @@
import org.opensearch.common.util.concurrent.AbstractRunnable;
import org.opensearch.common.util.concurrent.ConcurrentCollections;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
import org.opensearch.core.util.BytesRefUtils;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.core.xcontent.XContentParser;
Expand Down

0 comments on commit 8f1ae77

Please sign in to comment.