Skip to content

Commit

Permalink
Added IndexOutputWithBuffer. Removed print logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dooyong Kim committed Sep 11, 2024
1 parent bf9bf61 commit 143e13a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 0 additions & 2 deletions jni/include/stream_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class NativeEngineIndexOutputMediator {

void writeBytes(uint8_t* data, size_t nbytes) {
auto left = (int32_t) nbytes;
std::cout << "@@@ [KDY] write " << nbytes << std::endl;
while (left > 0) {
const auto copyBytes = std::min(left, bufferSize - offset);
std::memcpy(buffer.get() + offset, data, copyBytes);
Expand Down Expand Up @@ -165,7 +164,6 @@ class NativeEngineIndexOutputMediator {
}

void flush() {
std::cout << "@@@ [KDY] flush " << offset << std::endl;
// `writeBytes` method defined.
jmethodID writeBytesMethod = getWriteBytesMethod(env);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.knn.index.util;

import org.apache.lucene.store.IndexOutput;

import java.io.IOException;

public class IndexOutputWithBuffer {
public IndexOutputWithBuffer(IndexOutput indexOutput) {
this.indexOutput = indexOutput;
}

public byte[] getBuffer() {
return buffer;
}

public void writeBytes(int length) {
try {
indexOutput.writeBytes(buffer, 0, length);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
public String toString() {
return "{indexOutput=" + indexOutput + ", len(buffer)=" + buffer.length + "}";
}

private IndexOutput indexOutput;
private byte[] buffer = new byte[4 * 1024];
}

0 comments on commit 143e13a

Please sign in to comment.