You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/10/31 07:59:08 UTC

[GitHub] [inlong] EMsnap commented on a diff in pull request #6323: [INLONG-6322][Sort] Fix write data incorrect for doris connector with sink multiple scenario

EMsnap commented on code in PR #6323:
URL: https://github.com/apache/inlong/pull/6323#discussion_r1009121570


##########
inlong-sort/sort-connectors/doris/src/main/java/org/apache/inlong/sort/doris/table/DorisDynamicSchemaOutputFormat.java:
##########
@@ -258,35 +263,68 @@ public synchronized void close() throws IOException {
 
     @SuppressWarnings({"rawtypes"})
     public synchronized void flush() {
-        if (batchMap.isEmpty()) {
+        flushing = true;
+        if (!hasRecords()) {
+            flushing = false;
             return;
         }
+        List<String> errorTables = new ArrayList<>();
         for (Entry<String, List> kvs : batchMap.entrySet()) {
-            if (checkFlushException(kvs.getKey())) {
+            if (checkFlushException(kvs.getKey()) || kvs.getValue().isEmpty()) {
                 continue;
             }
+            String loadValue = null;
             try {
-                load(kvs.getKey(), OBJECT_MAPPER.writeValueAsString(kvs.getValue()));
+                loadValue = OBJECT_MAPPER.writeValueAsString(kvs.getValue());
+                load(kvs.getKey(), loadValue);
+                LOG.info("load {} records to tableIdentifier: {}", kvs.getValue().size(), kvs.getKey());
+                writeOutNum.addAndGet(kvs.getValue().size());
+                // Clean the data that has been loaded.
+                kvs.getValue().clear();
             } catch (Exception e) {
                 flushExceptionMap.put(kvs.getKey(), e);
+                errorNum.getAndAdd(kvs.getValue().size());
                 if (!ignoreSingleTableErrors) {
                     throw new RuntimeException(
-                            String.format("Writing records to streamload of tableIdentifier:%s failed.", kvs.getKey()),
-                            e);
+                            String.format("Writing records to streamload of tableIdentifier:%s failed, the value: %s.",
+                                    kvs.getKey(), loadValue), e);
                 }
-                batchMap.remove(kvs.getKey());
+                errorTables.add(kvs.getKey());
+                LOG.warn("The tableIdentifier: {} load failed and the data will be throw away in the future"
+                        + " because the option 'sink.multiple.ignore-single-table-errors' is 'true'", kvs.getKey());
             }
         }
+        if (!errorTables.isEmpty()) {
+            // Clean the key that has erros

Review Comment:
   errors



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org