You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2021/09/15 08:25:08 UTC

[GitHub] [incubator-doris] xy720 commented on a change in pull request #6646: [Meta][Refactor] Use lambda expressions to save Image

xy720 commented on a change in pull request #6646:
URL: https://github.com/apache/incubator-doris/pull/6646#discussion_r708956968



##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/MetaWriter.java
##########
@@ -65,67 +67,70 @@
 public class MetaWriter {
     private static final Logger LOG = LogManager.getLogger(MetaWriter.class);
 
+    public static MetaWriter writer = new MetaWriter();
+
+    private interface Delegate {
+        long doWork(String name, WriteMethod method) throws IOException;
+    }
+
+    private interface WriteMethod {
+        long write() throws IOException;
+    }
+
+    private Delegate delegate;
+
+    public void setDelegate(CountingDataOutputStream dos, List<MetaIndex> indices) {
+        this.delegate = (name, method) -> {
+            indices.add(new MetaIndex(name, dos.getCount()));
+            return method.write();
+        };
+    }
+
+    public long doWork(String name, WriteMethod method) throws IOException {
+        if(delegate == null){
+            return method.write();
+        }
+        return delegate.doWork(name, method);
+    }
+
     public static void write(File imageFile, Catalog catalog) throws IOException {
         // save image does not need any lock. because only checkpoint thread will call this method.
         LOG.info("start save image to {}. is ckpt: {}", imageFile.getAbsolutePath(), Catalog.isCheckpointThread());
 
-        long checksum = 0;
+        final AtomicReference<Long> checksum = new AtomicReference<>(0L);

Review comment:
       Yes. It's not about concurrent problem but final. I used Reference instead of AtomicReference.




-- 
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@doris.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org