[BugFix] Align enable_merge_commit setting for FE/BE (backport #62310) (#62322)

Signed-off-by: shuming.li <ming.moriarty@gmail.com>
Co-authored-by: shuming.li <ming.moriarty@gmail.com>
This commit is contained in:
mergify[bot] 2025-08-26 15:18:54 +08:00 committed by GitHub
parent ee253d78df
commit b69e6bd00f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 85 additions and 6 deletions

View File

@ -531,5 +531,18 @@ public class Util {
return objectsUnResolved;
}
/**
* To align with BE's string_to_bool function, the following string values are considered as true.
*/
public static boolean stringToBool(String str) {
if (str == null) {
return false;
}
str = str.trim().toLowerCase();
if ("true".equals(str) || "1".equals(str) || "true".equals(str.stripTrailing())) {
return true;
} else {
return false;
}
}
}

View File

@ -161,8 +161,7 @@ public class LoadAction extends RestBaseAction {
// affect subsequent requests processing.
response.setForceCloseConnection(true);
boolean enableBatchWrite = "true".equalsIgnoreCase(
request.getRequest().headers().get(StreamLoadHttpHeader.HTTP_ENABLE_BATCH_WRITE));
boolean enableBatchWrite = StreamLoadHttpHeader.isEnabledBatchWrite(request);
if (enableBatchWrite && redirectToLeader(request, response)) {
return;
}

View File

@ -79,8 +79,7 @@ public class StreamLoadMetaAction extends RestBaseAction {
@Override
public void executeWithoutPassword(BaseRequest request, BaseResponse response) throws DdlException,
AccessDeniedException {
boolean enableBatchWrite = "true".equalsIgnoreCase(
request.getRequest().headers().get(StreamLoadHttpHeader.HTTP_ENABLE_BATCH_WRITE));
boolean enableBatchWrite = StreamLoadHttpHeader.isEnabledBatchWrite(request);
if (enableBatchWrite && redirectToLeader(request, response)) {
return;
}

View File

@ -13,6 +13,9 @@
package com.starrocks.load.streamload;
import com.starrocks.common.util.Util;
import com.starrocks.http.BaseRequest;
import java.util.Arrays;
import java.util.List;
@ -74,4 +77,12 @@ public class StreamLoadHttpHeader {
HTTP_LOG_REJECTED_RECORD_NUM, HTTP_COMPRESSION, HTTP_WAREHOUSE, HTTP_ENABLE_BATCH_WRITE,
HTTP_BATCH_WRITE_ASYNC, HTTP_BATCH_WRITE_INTERVAL_MS, HTTP_BATCH_WRITE_PARALLEL
);
public static boolean isEnabledBatchWrite(BaseRequest request) {
if (request == null) {
return false;
}
String val = request.getRequest().headers().get(StreamLoadHttpHeader.HTTP_ENABLE_BATCH_WRITE);
return Util.stringToBool(val);
}
}

View File

@ -14,6 +14,7 @@
package com.starrocks.load.streamload;
import com.starrocks.common.util.Util;
import com.starrocks.thrift.TFileFormatType;
import com.starrocks.thrift.TFileType;
import com.starrocks.thrift.TPartialUpdateMode;
@ -317,7 +318,7 @@ public class StreamLoadKvParams implements StreamLoadParams {
if (value == null) {
return Optional.empty();
}
return Optional.of(Boolean.parseBoolean(value));
return Optional.of(Util.stringToBool(value));
}
private Optional<Integer> getIntParam(String paramName) {

View File

@ -17,6 +17,9 @@ package com.starrocks.common.util;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class UtilTest {
@Test
@ -24,4 +27,57 @@ public class UtilTest {
Assertions.assertThrows(Exception.class,
() -> Util.getResultForUrl("http://127.0.0.1:23/invalid", null, 1000, 1000));
}
@Test
public void returnsFalseWhenInputIsNull() {
assertFalse(Util.stringToBool(null));
}
@Test
public void returnsFalseWhenInputIsEmpty() {
assertFalse(Util.stringToBool(""));
}
@Test
public void returnsFalseWhenInputIsWhitespace() {
assertFalse(Util.stringToBool(" "));
}
@Test
public void returnsTrueWhenInputIsTrueIgnoringCase() {
assertTrue(Util.stringToBool("TRUE"));
assertTrue(Util.stringToBool("true"));
assertTrue(Util.stringToBool("TrUe"));
}
@Test
public void returnsTrueWhenInputIsOne() {
assertTrue(Util.stringToBool("1"));
}
@Test
public void returnsFalseWhenInputIsZero() {
assertFalse(Util.stringToBool("0"));
}
@Test
public void returnsFalseWhenInputIsFalseIgnoringCase() {
assertFalse(Util.stringToBool("FALSE"));
assertFalse(Util.stringToBool("false"));
assertFalse(Util.stringToBool("FaLsE"));
}
@Test
public void returnsTrueWhenInputHasTrailingWhitespace() {
assertTrue(Util.stringToBool("true "));
assertTrue(Util.stringToBool("1 "));
}
@Test
public void returnsFalseWhenInputIsInvalid() {
assertFalse(Util.stringToBool("invalid"));
assertFalse(Util.stringToBool("yes"));
assertFalse(Util.stringToBool("no"));
}
}