This is an automated email from the ASF dual-hosted git repository.

ctubbsii pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/main by this push:
     new 98d78fee9f Avoid unnecessary copies of Thrift binary types (#6459)
98d78fee9f is described below

commit 98d78fee9fcd48d746d563e25c7b5d6d77103a5c
Author: Christopher Tubbs <[email protected]>
AuthorDate: Tue Jul 7 20:33:23 2026 -0400

    Avoid unnecessary copies of Thrift binary types (#6459)
    
    Avoid unnecessary copies of Thrift binary types while working
    around bug in thrift generated code 
(https://issues.apache.org/jira/browse/THRIFT-6080)
    
    Avoid making copies using the public API setter when truncating the
    underlying stream to get the array by assigning the result of the
    optional resize operation directly to the variable, and avoiding the
    setter that performs the unneeded copy.
    
    Also simplify some adjacent TextUtil code
    
    Add preventative script to avoid new uses of bufferFor methods
---
 .github/workflows/maven.yaml                       |  2 +
 .../java/org/apache/accumulo/core/data/Column.java |  4 +-
 .../java/org/apache/accumulo/core/data/Key.java    |  9 ++--
 .../org/apache/accumulo/core/data/Mutation.java    |  4 +-
 .../org/apache/accumulo/core/summary/Gatherer.java |  9 ++--
 .../org/apache/accumulo/core/util/TextUtil.java    | 18 +++-----
 core/src/main/scripts/generate-thrift.sh           | 10 +++--
 .../core/clientImpl/thrift/ClientService.java      |  4 +-
 .../accumulo/core/dataImpl/thrift/TColumn.java     |  6 +--
 .../accumulo/core/dataImpl/thrift/TCondition.java  | 10 ++---
 .../apache/accumulo/core/dataImpl/thrift/TKey.java |  8 ++--
 .../accumulo/core/dataImpl/thrift/TKeyExtent.java  |  6 +--
 .../accumulo/core/dataImpl/thrift/TKeyValue.java   |  2 +-
 .../accumulo/core/dataImpl/thrift/TMutation.java   |  4 +-
 .../accumulo/core/dataImpl/thrift/TRowRange.java   |  4 +-
 .../core/manager/thrift/ManagerClientService.java  |  4 +-
 .../securityImpl/thrift/TAuthenticationKey.java    |  2 +-
 .../core/securityImpl/thrift/TCredentials.java     |  2 +-
 .../core/securityImpl/thrift/TDelegationToken.java |  2 +-
 .../thrift/TabletServerClientService.java          |  4 +-
 src/build/ci/find-unapproved-thrift-bytebuffer.sh  | 51 ++++++++++++++++++++++
 21 files changed, 106 insertions(+), 59 deletions(-)

diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml
index a42e83d764..5f0e41cd0a 100644
--- a/.github/workflows/maven.yaml
+++ b/.github/workflows/maven.yaml
@@ -54,6 +54,8 @@ jobs:
       run: src/build/ci/find-unapproved-abstract-ITs.sh
     - name: Check for unapproved package naming conventions
       run: src/build/ci/check-module-package-conventions.sh
+    - name: Check for unapproved bufferFor methods
+      run: src/build/ci/find-unapproved-thrift-bytebuffer.sh
     - name: Build with Maven (Fast Build)
       timeout-minutes: 20
       run: mvn -B -V -e -ntp "-Dstyle.color=always" clean package 
dependency:resolve -DskipTests -DskipFormat -DverifyFormat
diff --git a/core/src/main/java/org/apache/accumulo/core/data/Column.java 
b/core/src/main/java/org/apache/accumulo/core/data/Column.java
index 7f6698e39c..1817b999c3 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/Column.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/Column.java
@@ -19,7 +19,6 @@
 package org.apache.accumulo.core.data;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.accumulo.core.util.ByteBufferUtil.toBytes;
 
 import java.io.DataInput;
 import java.io.DataOutput;
@@ -139,8 +138,7 @@ public class Column implements WritableComparable<Column> {
    * @param tcol Thrift column
    */
   public Column(TColumn tcol) {
-    this(toBytes(tcol.bufferForColumnFamily()), 
toBytes(tcol.bufferForColumnQualifier()),
-        toBytes(tcol.bufferForColumnVisibility()));
+    this(tcol.getColumnFamily(), tcol.getColumnQualifier(), 
tcol.getColumnVisibility());
   }
 
   @Override
diff --git a/core/src/main/java/org/apache/accumulo/core/data/Key.java 
b/core/src/main/java/org/apache/accumulo/core/data/Key.java
index f0b5e79566..fab52b3794 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/Key.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/Key.java
@@ -29,7 +29,6 @@ import org.apache.accumulo.core.Constants;
 import org.apache.accumulo.core.dataImpl.thrift.TKey;
 import org.apache.accumulo.core.dataImpl.thrift.TKeyValue;
 import org.apache.accumulo.core.security.ColumnVisibility;
-import org.apache.accumulo.core.util.ByteBufferUtil;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.WritableComparable;
 import org.apache.hadoop.io.WritableComparator;
@@ -685,10 +684,10 @@ public class Key implements WritableComparable<Key>, 
Cloneable {
    * @param tkey Thrift key
    */
   public Key(TKey tkey) {
-    this.row = ByteBufferUtil.toBytes(tkey.bufferForRow());
-    this.colFamily = ByteBufferUtil.toBytes(tkey.bufferForColFamily());
-    this.colQualifier = ByteBufferUtil.toBytes(tkey.bufferForColQualifier());
-    this.colVisibility = ByteBufferUtil.toBytes(tkey.bufferForColVisibility());
+    this.row = tkey.getRow();
+    this.colFamily = tkey.getColFamily();
+    this.colQualifier = tkey.getColQualifier();
+    this.colVisibility = tkey.getColVisibility();
     this.timestamp = tkey.getTimestamp();
     this.deleted = false;
 
diff --git a/core/src/main/java/org/apache/accumulo/core/data/Mutation.java 
b/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
index 1b7ddb7694..ef78bb7dc8 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
@@ -236,8 +236,8 @@ public class Mutation implements Writable {
    * @param tmutation Thrift mutation
    */
   public Mutation(TMutation tmutation) {
-    this.row = ByteBufferUtil.toBytes(tmutation.bufferForRow());
-    this.data = ByteBufferUtil.toBytes(tmutation.bufferForData());
+    this.row = tmutation.getRow();
+    this.data = tmutation.getData();
     this.entries = tmutation.getEntries();
     this.values = ByteBufferUtil.toBytesList(tmutation.getValues());
 
diff --git a/core/src/main/java/org/apache/accumulo/core/summary/Gatherer.java 
b/core/src/main/java/org/apache/accumulo/core/summary/Gatherer.java
index 1d1e5aef0b..0eb4e23b51 100644
--- a/core/src/main/java/org/apache/accumulo/core/summary/Gatherer.java
+++ b/core/src/main/java/org/apache/accumulo/core/summary/Gatherer.java
@@ -71,7 +71,6 @@ import org.apache.accumulo.core.spi.cache.BlockCache;
 import org.apache.accumulo.core.spi.crypto.CryptoService;
 import 
org.apache.accumulo.core.tabletserver.thrift.TabletServerClientService.Client;
 import org.apache.accumulo.core.trace.TraceUtil;
-import org.apache.accumulo.core.util.ByteBufferUtil;
 import org.apache.accumulo.core.util.CancelFlagFuture;
 import org.apache.accumulo.core.util.CompletableFutureUtil;
 import org.apache.accumulo.core.util.TextUtil;
@@ -127,8 +126,8 @@ public class Gatherer {
       CryptoService cryptoService) {
     this.ctx = context;
     this.tableId = TableId.of(request.getTableId());
-    this.startRow = 
ByteBufferUtil.toText(request.getBounds().bufferForStartRow());
-    this.endRow = ByteBufferUtil.toText(request.getBounds().bufferForEndRow());
+    this.startRow = 
TextUtil.fromNullableBytes(request.getBounds().getStartRow());
+    this.endRow = TextUtil.fromNullableBytes(request.getBounds().getEndRow());
     this.clipRange = new Range(startRow, false, endRow, true);
     this.summaries = 
request.getSummarizers().stream().map(SummarizerConfigurationUtil::fromThrift)
         .collect(Collectors.toSet());
@@ -436,8 +435,8 @@ public class Gatherer {
       Map<String,List<TRowRange>> files, BlockCache summaryCache, BlockCache 
indexCache,
       Cache<String,Long> fileLenCache, ExecutorService srp) {
     Function<TRowRange,RowRange> fromThrift = tRowRange -> {
-      Text lowerBound = ByteBufferUtil.toText(tRowRange.bufferForStartRow());
-      Text upperBound = ByteBufferUtil.toText(tRowRange.bufferForEndRow());
+      Text lowerBound = TextUtil.fromNullableBytes(tRowRange.getStartRow());
+      Text upperBound = TextUtil.fromNullableBytes(tRowRange.getEndRow());
       return RowRange.range(lowerBound, false, upperBound, true);
     };
     List<CompletableFuture<SummaryCollection>> futures = new 
ArrayList<>(files.size());
diff --git a/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java 
b/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java
index cbdcd0321a..463f747511 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java
@@ -26,21 +26,18 @@ import org.apache.accumulo.core.Constants;
 import org.apache.hadoop.io.Text;
 
 public final class TextUtil {
+
+  public static Text fromNullableBytes(byte[] bytes) {
+    return bytes == null ? null : new Text(bytes);
+  }
+
   public static byte[] getBytes(Text text) {
     byte[] bytes = text.getBytes();
-    if (bytes.length != text.getLength()) {
-      bytes = new byte[text.getLength()];
-      System.arraycopy(text.getBytes(), 0, bytes, 0, bytes.length);
-    }
-    return bytes;
+    return bytes.length == text.getLength() ? bytes : text.copyBytes();
   }
 
   public static ByteBuffer getByteBuffer(Text text) {
-    if (text == null) {
-      return null;
-    }
-    byte[] bytes = text.getBytes();
-    return ByteBuffer.wrap(bytes, 0, text.getLength());
+    return text == null ? null : ByteBuffer.wrap(text.getBytes(), 0, 
text.getLength());
   }
 
   public static Text truncate(Text text, int maxLen) {
@@ -51,7 +48,6 @@ public final class TextUtil {
       newText.append(suffix.getBytes(UTF_8), 0, suffix.length());
       return newText;
     }
-
     return text;
   }
 
diff --git a/core/src/main/scripts/generate-thrift.sh 
b/core/src/main/scripts/generate-thrift.sh
index f47b30ff95..1e03442f16 100755
--- a/core/src/main/scripts/generate-thrift.sh
+++ b/core/src/main/scripts/generate-thrift.sh
@@ -67,7 +67,7 @@ THRIFT_ARGS=("${THRIFT_ARGS[@]}" -o "$BUILD_DIR")
 mkdir -p "$BUILD_DIR"
 rm -rf "$BUILD_DIR"/gen-java
 for f in src/main/thrift/*.thrift; do
-  thrift "${THRIFT_ARGS[@]}" --gen 
java:generated_annotations=suppress,private-members "$f" || fail unable to 
generate java thrift classes
+  thrift "${THRIFT_ARGS[@]}" --gen 
java:generated_annotations=suppress,private_members "$f" || fail unable to 
generate java thrift classes
   thrift "${THRIFT_ARGS[@]}" --gen py "$f" || fail unable to generate python 
thrift classes
   thrift "${THRIFT_ARGS[@]}" --gen rb "$f" || fail unable to generate ruby 
thrift classes
   thrift "${THRIFT_ARGS[@]}" --gen cpp "$f" || fail unable to generate cpp 
thrift classes
@@ -76,10 +76,12 @@ done
 # For all generated thrift code, get rid of all warnings and add the LICENSE 
header
 
 # add dummy method to suppress "unnecessary suppress warnings" for classes 
which don't have any unused variables
-# this only affects classes, enums aren't affected
+# this only affects classes, enums aren't affected; also avoid thrift bug that 
makes a redundant copy when resizing the array
 #shellcheck disable=SC1004
-find "$BUILD_DIR/gen-java" -name '*.java' -exec grep -Zl '^public class ' {} + 
| xargs -0 sed -i -e 's/^[}]$/  private static void unusedMethod() {}\
-}/'
+find "$BUILD_DIR/gen-java" -name '*.java' -exec grep -Zl '^public class ' {} + 
| xargs -0 sed -i \
+  -e 's/^[}]$/  private static void unusedMethod() {}\
+}/' \
+  -e 
's/^\([[:space:]]*\)set[A-Z][A-Za-z]*(org[.]apache[.]thrift[.]TBaseHelper[.]rightSize(\([^)]*\)));$/\1this.\2
 = org.apache.thrift.TBaseHelper.rightSize(\2);/g'
 
 for lang in "${LANGUAGES_TO_GENERATE[@]}"; do
   case $lang in
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/clientImpl/thrift/ClientService.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/clientImpl/thrift/ClientService.java
index 83ede22466..acaf3649ea 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/clientImpl/thrift/ClientService.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/clientImpl/thrift/ClientService.java
@@ -9604,7 +9604,7 @@ public class ClientService {
     }
 
     public byte[] getPassword() {
-      setPassword(org.apache.thrift.TBaseHelper.rightSize(password));
+      this.password = org.apache.thrift.TBaseHelper.rightSize(password);
       return password == null ? null : password.array();
     }
 
@@ -11720,7 +11720,7 @@ public class ClientService {
     }
 
     public byte[] getPassword() {
-      setPassword(org.apache.thrift.TBaseHelper.rightSize(password));
+      this.password = org.apache.thrift.TBaseHelper.rightSize(password);
       return password == null ? null : password.array();
     }
 
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TColumn.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TColumn.java
index 6b6ca9de83..1fe6383ff7 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TColumn.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TColumn.java
@@ -163,7 +163,7 @@ public class TColumn implements 
org.apache.thrift.TBase<TColumn, TColumn._Fields
   }
 
   public byte[] getColumnFamily() {
-    setColumnFamily(org.apache.thrift.TBaseHelper.rightSize(columnFamily));
+    this.columnFamily = org.apache.thrift.TBaseHelper.rightSize(columnFamily);
     return columnFamily == null ? null : columnFamily.array();
   }
 
@@ -197,7 +197,7 @@ public class TColumn implements 
org.apache.thrift.TBase<TColumn, TColumn._Fields
   }
 
   public byte[] getColumnQualifier() {
-    
setColumnQualifier(org.apache.thrift.TBaseHelper.rightSize(columnQualifier));
+    this.columnQualifier = 
org.apache.thrift.TBaseHelper.rightSize(columnQualifier);
     return columnQualifier == null ? null : columnQualifier.array();
   }
 
@@ -231,7 +231,7 @@ public class TColumn implements 
org.apache.thrift.TBase<TColumn, TColumn._Fields
   }
 
   public byte[] getColumnVisibility() {
-    
setColumnVisibility(org.apache.thrift.TBaseHelper.rightSize(columnVisibility));
+    this.columnVisibility = 
org.apache.thrift.TBaseHelper.rightSize(columnVisibility);
     return columnVisibility == null ? null : columnVisibility.array();
   }
 
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TCondition.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TCondition.java
index afad65f935..adc312765b 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TCondition.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TCondition.java
@@ -219,7 +219,7 @@ public class TCondition implements 
org.apache.thrift.TBase<TCondition, TConditio
   }
 
   public byte[] getCf() {
-    setCf(org.apache.thrift.TBaseHelper.rightSize(cf));
+    this.cf = org.apache.thrift.TBaseHelper.rightSize(cf);
     return cf == null ? null : cf.array();
   }
 
@@ -253,7 +253,7 @@ public class TCondition implements 
org.apache.thrift.TBase<TCondition, TConditio
   }
 
   public byte[] getCq() {
-    setCq(org.apache.thrift.TBaseHelper.rightSize(cq));
+    this.cq = org.apache.thrift.TBaseHelper.rightSize(cq);
     return cq == null ? null : cq.array();
   }
 
@@ -287,7 +287,7 @@ public class TCondition implements 
org.apache.thrift.TBase<TCondition, TConditio
   }
 
   public byte[] getCv() {
-    setCv(org.apache.thrift.TBaseHelper.rightSize(cv));
+    this.cv = org.apache.thrift.TBaseHelper.rightSize(cv);
     return cv == null ? null : cv.array();
   }
 
@@ -367,7 +367,7 @@ public class TCondition implements 
org.apache.thrift.TBase<TCondition, TConditio
   }
 
   public byte[] getVal() {
-    setVal(org.apache.thrift.TBaseHelper.rightSize(val));
+    this.val = org.apache.thrift.TBaseHelper.rightSize(val);
     return val == null ? null : val.array();
   }
 
@@ -401,7 +401,7 @@ public class TCondition implements 
org.apache.thrift.TBase<TCondition, TConditio
   }
 
   public byte[] getIterators() {
-    setIterators(org.apache.thrift.TBaseHelper.rightSize(iterators));
+    this.iterators = org.apache.thrift.TBaseHelper.rightSize(iterators);
     return iterators == null ? null : iterators.array();
   }
 
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TKey.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TKey.java
index c274da3ab4..c561664120 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TKey.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TKey.java
@@ -192,7 +192,7 @@ public class TKey implements org.apache.thrift.TBase<TKey, 
TKey._Fields>, java.i
   }
 
   public byte[] getRow() {
-    setRow(org.apache.thrift.TBaseHelper.rightSize(row));
+    this.row = org.apache.thrift.TBaseHelper.rightSize(row);
     return row == null ? null : row.array();
   }
 
@@ -226,7 +226,7 @@ public class TKey implements org.apache.thrift.TBase<TKey, 
TKey._Fields>, java.i
   }
 
   public byte[] getColFamily() {
-    setColFamily(org.apache.thrift.TBaseHelper.rightSize(colFamily));
+    this.colFamily = org.apache.thrift.TBaseHelper.rightSize(colFamily);
     return colFamily == null ? null : colFamily.array();
   }
 
@@ -260,7 +260,7 @@ public class TKey implements org.apache.thrift.TBase<TKey, 
TKey._Fields>, java.i
   }
 
   public byte[] getColQualifier() {
-    setColQualifier(org.apache.thrift.TBaseHelper.rightSize(colQualifier));
+    this.colQualifier = org.apache.thrift.TBaseHelper.rightSize(colQualifier);
     return colQualifier == null ? null : colQualifier.array();
   }
 
@@ -294,7 +294,7 @@ public class TKey implements org.apache.thrift.TBase<TKey, 
TKey._Fields>, java.i
   }
 
   public byte[] getColVisibility() {
-    setColVisibility(org.apache.thrift.TBaseHelper.rightSize(colVisibility));
+    this.colVisibility = 
org.apache.thrift.TBaseHelper.rightSize(colVisibility);
     return colVisibility == null ? null : colVisibility.array();
   }
 
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TKeyExtent.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TKeyExtent.java
index 808443868f..0fe958f559 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TKeyExtent.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TKeyExtent.java
@@ -163,7 +163,7 @@ public class TKeyExtent implements 
org.apache.thrift.TBase<TKeyExtent, TKeyExten
   }
 
   public byte[] getTable() {
-    setTable(org.apache.thrift.TBaseHelper.rightSize(table));
+    this.table = org.apache.thrift.TBaseHelper.rightSize(table);
     return table == null ? null : table.array();
   }
 
@@ -197,7 +197,7 @@ public class TKeyExtent implements 
org.apache.thrift.TBase<TKeyExtent, TKeyExten
   }
 
   public byte[] getEndRow() {
-    setEndRow(org.apache.thrift.TBaseHelper.rightSize(endRow));
+    this.endRow = org.apache.thrift.TBaseHelper.rightSize(endRow);
     return endRow == null ? null : endRow.array();
   }
 
@@ -231,7 +231,7 @@ public class TKeyExtent implements 
org.apache.thrift.TBase<TKeyExtent, TKeyExten
   }
 
   public byte[] getPrevEndRow() {
-    setPrevEndRow(org.apache.thrift.TBaseHelper.rightSize(prevEndRow));
+    this.prevEndRow = org.apache.thrift.TBaseHelper.rightSize(prevEndRow);
     return prevEndRow == null ? null : prevEndRow.array();
   }
 
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TKeyValue.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TKeyValue.java
index 83978596a8..b91f7fbc38 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TKeyValue.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TKeyValue.java
@@ -175,7 +175,7 @@ public class TKeyValue implements 
org.apache.thrift.TBase<TKeyValue, TKeyValue._
   }
 
   public byte[] getValue() {
-    setValue(org.apache.thrift.TBaseHelper.rightSize(value));
+    this.value = org.apache.thrift.TBaseHelper.rightSize(value);
     return value == null ? null : value.array();
   }
 
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TMutation.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TMutation.java
index cbaaed190b..ce95f1c388 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TMutation.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TMutation.java
@@ -195,7 +195,7 @@ public class TMutation implements 
org.apache.thrift.TBase<TMutation, TMutation._
   }
 
   public byte[] getRow() {
-    setRow(org.apache.thrift.TBaseHelper.rightSize(row));
+    this.row = org.apache.thrift.TBaseHelper.rightSize(row);
     return row == null ? null : row.array();
   }
 
@@ -229,7 +229,7 @@ public class TMutation implements 
org.apache.thrift.TBase<TMutation, TMutation._
   }
 
   public byte[] getData() {
-    setData(org.apache.thrift.TBaseHelper.rightSize(data));
+    this.data = org.apache.thrift.TBaseHelper.rightSize(data);
     return data == null ? null : data.array();
   }
 
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TRowRange.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TRowRange.java
index 39979f393c..2867a4e81c 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TRowRange.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/dataImpl/thrift/TRowRange.java
@@ -150,7 +150,7 @@ public class TRowRange implements 
org.apache.thrift.TBase<TRowRange, TRowRange._
   }
 
   public byte[] getStartRow() {
-    setStartRow(org.apache.thrift.TBaseHelper.rightSize(startRow));
+    this.startRow = org.apache.thrift.TBaseHelper.rightSize(startRow);
     return startRow == null ? null : startRow.array();
   }
 
@@ -184,7 +184,7 @@ public class TRowRange implements 
org.apache.thrift.TBase<TRowRange, TRowRange._
   }
 
   public byte[] getEndRow() {
-    setEndRow(org.apache.thrift.TBaseHelper.rightSize(endRow));
+    this.endRow = org.apache.thrift.TBaseHelper.rightSize(endRow);
     return endRow == null ? null : endRow.array();
   }
 
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/manager/thrift/ManagerClientService.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/manager/thrift/ManagerClientService.java
index ad6eb39aa1..17a4858e0f 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/manager/thrift/ManagerClientService.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/manager/thrift/ManagerClientService.java
@@ -7419,7 +7419,7 @@ public class ManagerClientService {
     }
 
     public byte[] getStartRow() {
-      setStartRow(org.apache.thrift.TBaseHelper.rightSize(startRow));
+      this.startRow = org.apache.thrift.TBaseHelper.rightSize(startRow);
       return startRow == null ? null : startRow.array();
     }
 
@@ -7453,7 +7453,7 @@ public class ManagerClientService {
     }
 
     public byte[] getEndRow() {
-      setEndRow(org.apache.thrift.TBaseHelper.rightSize(endRow));
+      this.endRow = org.apache.thrift.TBaseHelper.rightSize(endRow);
       return endRow == null ? null : endRow.array();
     }
 
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/securityImpl/thrift/TAuthenticationKey.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/securityImpl/thrift/TAuthenticationKey.java
index bc52759db0..f6011e5044 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/securityImpl/thrift/TAuthenticationKey.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/securityImpl/thrift/TAuthenticationKey.java
@@ -173,7 +173,7 @@ public class TAuthenticationKey implements 
org.apache.thrift.TBase<TAuthenticati
   }
 
   public byte[] getSecret() {
-    setSecret(org.apache.thrift.TBaseHelper.rightSize(secret));
+    this.secret = org.apache.thrift.TBaseHelper.rightSize(secret);
     return secret == null ? null : secret.array();
   }
 
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/securityImpl/thrift/TCredentials.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/securityImpl/thrift/TCredentials.java
index 0aaaa0bb19..7843c9650f 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/securityImpl/thrift/TCredentials.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/securityImpl/thrift/TCredentials.java
@@ -226,7 +226,7 @@ public class TCredentials implements 
org.apache.thrift.TBase<TCredentials, TCred
   }
 
   public byte[] getToken() {
-    setToken(org.apache.thrift.TBaseHelper.rightSize(token));
+    this.token = org.apache.thrift.TBaseHelper.rightSize(token);
     return token == null ? null : token.array();
   }
 
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/securityImpl/thrift/TDelegationToken.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/securityImpl/thrift/TDelegationToken.java
index 7202be9db7..52b0b244b9 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/securityImpl/thrift/TDelegationToken.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/securityImpl/thrift/TDelegationToken.java
@@ -150,7 +150,7 @@ public class TDelegationToken implements 
org.apache.thrift.TBase<TDelegationToke
   }
 
   public byte[] getPassword() {
-    setPassword(org.apache.thrift.TBaseHelper.rightSize(password));
+    this.password = org.apache.thrift.TBaseHelper.rightSize(password);
     return password == null ? null : password.array();
   }
 
diff --git 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/tabletserver/thrift/TabletServerClientService.java
 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/tabletserver/thrift/TabletServerClientService.java
index 8a24325504..6a9f0cda1c 100644
--- 
a/core/src/main/thrift-gen-java/org/apache/accumulo/core/tabletserver/thrift/TabletServerClientService.java
+++ 
b/core/src/main/thrift-gen-java/org/apache/accumulo/core/tabletserver/thrift/TabletServerClientService.java
@@ -3050,7 +3050,7 @@ public class TabletServerClientService {
     }
 
     public byte[] getStartRow() {
-      setStartRow(org.apache.thrift.TBaseHelper.rightSize(startRow));
+      this.startRow = org.apache.thrift.TBaseHelper.rightSize(startRow);
       return startRow == null ? null : startRow.array();
     }
 
@@ -3084,7 +3084,7 @@ public class TabletServerClientService {
     }
 
     public byte[] getEndRow() {
-      setEndRow(org.apache.thrift.TBaseHelper.rightSize(endRow));
+      this.endRow = org.apache.thrift.TBaseHelper.rightSize(endRow);
       return endRow == null ? null : endRow.array();
     }
 
diff --git a/src/build/ci/find-unapproved-thrift-bytebuffer.sh 
b/src/build/ci/find-unapproved-thrift-bytebuffer.sh
new file mode 100755
index 0000000000..bb6068070b
--- /dev/null
+++ b/src/build/ci/find-unapproved-thrift-bytebuffer.sh
@@ -0,0 +1,51 @@
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# The purpose of this ci script is to ensure that a pull request doesn't
+# unintentionally add any new calls to Thrift generated methods of the
+# form "bufferForX()" which create expensive unneeded byte array copies.
+NUM_EXPECTED=0
+ALLOWED=(
+)
+
+ALLOWED_PIPE_SEP=$({ for x in "${ALLOWED[@]}"; do echo "$x"; done; } | paste 
-sd'|')
+
+function findallbufferfor() {
+  # -P for perl matching, -R for recursive, -l for matching files
+  local opts='-PRl'
+  if [[ $1 == 'print' ]]; then
+    # -P for perl matching, -R for recursive, -l for matching files, -H for 
always showing filenames
+    opts='-PRlH'
+  fi
+  # find any new classes using something other than the jupiter API, except 
those allowed
+  grep "$opts" --include='*.java' '[.]bufferFor[^(]+[(]' | grep -Pv 
"^(${ALLOWED_PIPE_SEP//./[.]})\$"
+}
+
+function comparecounts() {
+  local count
+  count=$(findallbufferfor | wc -l)
+  if [[ $NUM_EXPECTED -ne $count ]]; then
+    echo "Expected $NUM_EXPECTED, but found $count classes using 
'bufferForX()' calls:"
+    findallbufferfor 'print'
+    return 1
+  fi
+}
+
+comparecounts && echo "Found exactly $NUM_EXPECTED unapproved 'bufferForX()' 
calls, as expected"

Reply via email to