Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INLONG-10463][SDK] Optimization of ultra-long field processing in InlongSDK (Temp) #11213

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ public class ConfigConstants {

public static String HTTP = "http://";
public static String HTTPS = "https://";
public static int MAX_MESSAGE_LENGTH = 500 * 1024;

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import static org.apache.inlong.sdk.dataproxy.utils.DataBodyUtil.getDataSize;

public class DefaultMessageSender implements MessageSender {

private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMessageSender.class);
Expand Down Expand Up @@ -218,6 +220,9 @@ public SendResult sendMessage(byte[] body, String groupId, String streamId, long
*/
public SendResult sendMessage(byte[] body, String groupId, String streamId, long dt, String msgUUID,
long timeout, TimeUnit timeUnit, boolean isProxySend) {
if (getDataSize(body) > ConfigConstants.MAX_MESSAGE_LENGTH) {
return SendResult.BODY_EXCEED_MAX_LEN;
}
dt = ProxyUtils.covertZeroDt(dt);
if (!ProxyUtils.isBodyValid(body) || !ProxyUtils.isDtValid(dt)) {
return SendResult.INVALID_ATTRIBUTES;
Expand Down Expand Up @@ -275,7 +280,9 @@ public SendResult sendMessage(byte[] body, String groupId, String streamId, long
*/
public SendResult sendMessage(byte[] body, String groupId, String streamId, long dt, String msgUUID,
long timeout, TimeUnit timeUnit, Map<String, String> extraAttrMap, boolean isProxySend) {

if (getDataSize(body) > ConfigConstants.MAX_MESSAGE_LENGTH) {
return SendResult.BODY_EXCEED_MAX_LEN;
}
dt = ProxyUtils.covertZeroDt(dt);
if (!ProxyUtils.isBodyValid(body) || !ProxyUtils.isDtValid(dt) || !ProxyUtils.isAttrKeysValid(extraAttrMap)) {
return SendResult.INVALID_ATTRIBUTES;
Expand Down Expand Up @@ -332,6 +339,9 @@ public SendResult sendMessage(List<byte[]> bodyList, String groupId, String stre
*/
public SendResult sendMessage(List<byte[]> bodyList, String groupId, String streamId, long dt, String msgUUID,
long timeout, TimeUnit timeUnit, boolean isProxySend) {
if (getDataSize(bodyList) > ConfigConstants.MAX_MESSAGE_LENGTH) {
return SendResult.BODY_EXCEED_MAX_LEN;
}
dt = ProxyUtils.covertZeroDt(dt);
if (!ProxyUtils.isBodyValid(bodyList) || !ProxyUtils.isDtValid(dt)) {
return SendResult.INVALID_ATTRIBUTES;
Expand Down Expand Up @@ -388,6 +398,9 @@ public SendResult sendMessage(List<byte[]> bodyList, String groupId, String stre
*/
public SendResult sendMessage(List<byte[]> bodyList, String groupId, String streamId, long dt,
String msgUUID, long timeout, TimeUnit timeUnit, Map<String, String> extraAttrMap, boolean isProxySend) {
if (getDataSize(bodyList) > ConfigConstants.MAX_MESSAGE_LENGTH) {
return SendResult.BODY_EXCEED_MAX_LEN;
}
dt = ProxyUtils.covertZeroDt(dt);
if (!ProxyUtils.isBodyValid(bodyList) || !ProxyUtils.isDtValid(dt) || !ProxyUtils.isAttrKeysValid(
extraAttrMap)) {
Expand Down Expand Up @@ -450,6 +463,9 @@ public void asyncSendMessage(SendMessageCallback callback, byte[] body, String g
*/
public void asyncSendMessage(SendMessageCallback callback, byte[] body, String groupId, String streamId, long dt,
String msgUUID, long timeout, TimeUnit timeUnit, boolean isProxySend) throws ProxysdkException {
if (getDataSize(body) > ConfigConstants.MAX_MESSAGE_LENGTH) {
callback.onMessageAck(SendResult.BODY_EXCEED_MAX_LEN);
}
dt = ProxyUtils.covertZeroDt(dt);
if (!ProxyUtils.isBodyValid(body) || !ProxyUtils.isDtValid(dt)) {
throw new ProxysdkException(SendResult.INVALID_ATTRIBUTES.toString());
Expand Down Expand Up @@ -512,6 +528,9 @@ public void asyncSendMessage(SendMessageCallback callback, byte[] body, String g
public void asyncSendMessage(SendMessageCallback callback, byte[] body, String groupId, String streamId, long dt,
String msgUUID, long timeout, TimeUnit timeUnit, Map<String, String> extraAttrMap, boolean isProxySend)
throws ProxysdkException {
if (getDataSize(body) > ConfigConstants.MAX_MESSAGE_LENGTH) {
callback.onMessageAck(SendResult.BODY_EXCEED_MAX_LEN);
}
dt = ProxyUtils.covertZeroDt(dt);
if (!ProxyUtils.isBodyValid(body) || !ProxyUtils.isDtValid(dt) || !ProxyUtils.isAttrKeysValid(extraAttrMap)) {
throw new ProxysdkException(SendResult.INVALID_ATTRIBUTES.toString());
Expand Down Expand Up @@ -566,6 +585,9 @@ public void asyncSendMessage(SendMessageCallback callback, List<byte[]> bodyList
public void asyncSendMessage(SendMessageCallback callback, List<byte[]> bodyList,
String groupId, String streamId, long dt, String msgUUID,
long timeout, TimeUnit timeUnit, boolean isProxySend) throws ProxysdkException {
if (getDataSize(bodyList) > ConfigConstants.MAX_MESSAGE_LENGTH) {
callback.onMessageAck(SendResult.BODY_EXCEED_MAX_LEN);
}
dt = ProxyUtils.covertZeroDt(dt);
if (!ProxyUtils.isBodyValid(bodyList) || !ProxyUtils.isDtValid(dt)) {
throw new ProxysdkException(SendResult.INVALID_ATTRIBUTES.toString());
Expand Down Expand Up @@ -628,6 +650,9 @@ public void asyncSendMessage(SendMessageCallback callback,
List<byte[]> bodyList, String groupId, String streamId, long dt, String msgUUID,
long timeout, TimeUnit timeUnit,
Map<String, String> extraAttrMap, boolean isProxySend) throws ProxysdkException {
if (getDataSize(bodyList) > ConfigConstants.MAX_MESSAGE_LENGTH) {
callback.onMessageAck(SendResult.BODY_EXCEED_MAX_LEN);
}
dt = ProxyUtils.covertZeroDt(dt);
if (!ProxyUtils.isBodyValid(bodyList) || !ProxyUtils.isDtValid(dt) || !ProxyUtils.isAttrKeysValid(
extraAttrMap)) {
Expand Down Expand Up @@ -852,4 +877,4 @@ public void close() {
sender.close();
shutdownInternalThreads();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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
*
* http://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.
*/

package org.apache.inlong.sdk.dataproxy.utils;

import java.util.List;

public class DataBodyUtil {

/**
* get the data size of a single body
* @param body body
* @return size
*/
public static int getDataSize(byte[] body) {
return body.length;
}

/**
* calculate the total data size of body list
* @param bodyList body list
* @return size
*/
public static int getDataSize(List<byte[]> bodyList) {
int size = 0;
for (byte[] body : bodyList) {
size += body.length;
}
return size;
}
}
Loading