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/07/12 19:51:55 UTC

[GitHub] [incubator-doris] xy720 opened a new pull request #6207: [New Feature][Meta][Image] Add file header for image

xy720 opened a new pull request #6207:
URL: https://github.com/apache/incubator-doris/pull/6207


   ## Proposed changes
   
   #6206 
   
   ## Types of changes
   
   What types of changes does your code introduce to Doris?
   _Put an `x` in the boxes that apply_
   
   - [x] New feature (non-breaking change which adds functionality)
   
   ## Checklist
   
   _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
   
   - [x] I have created an issue on (Fix #6206 ) and described the bug/feature there in detail
   - [x] Compiling and unit tests pass locally with my changes
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...
   


-- 
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


[GitHub] [incubator-doris] xy720 commented on a change in pull request #6207: [New Feature][Meta][Image] Add file header and footer for image

Posted by GitBox <gi...@apache.org>.
xy720 commented on a change in pull request #6207:
URL: https://github.com/apache/incubator-doris/pull/6207#discussion_r670973120



##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/MetaWriter.java
##########
@@ -0,0 +1,131 @@
+// 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.doris.common;
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.common.io.CountingDataOutputStream;
+import com.google.common.collect.Lists;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Image Format:
+ * |- Image --------------------------------------|
+ * | - Magic String (4 bytes)                     |
+ * | - Header Length (4 bytes)                    |
+ * | |- Header -----------------------------|     |
+ * | | |- Json Header ---------------|      |     |
+ * | | | - version                   |      |     |
+ * | | | - other key/value(undecided)|      |     |
+ * | | |-----------------------------|      |     |
+ * | |--------------------------------------|     |
+ * |                                              |
+ * | |- Image Body -------------------------|     |
+ * | | Object a                             |     |
+ * | | Object b                             |     |
+ * | | ...                                  |     |
+ * | |--------------------------------------|     |
+ * |                                              |
+ * | |- Footer -----------------------------|     |
+ * | | |- object index --------------|      |     |
+ * | | | - index a                   |      |     |
+ * | | | - index b                   |      |     |
+ * | | | ...                         |      |     |
+ * | | |-----------------------------|      |     |
+ * | | - other value(undecided)             |     |
+ * | |--------------------------------------|     |
+ * | - Footer Length (8 bytes)                    |
+ * | - Magic String (4 bytes)                     |
+ * |----------------------------------------------|
+ */
+
+public class MetaWriter {
+    private static final Logger LOG = LogManager.getLogger(MetaWriter.class);
+
+    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;
+        long saveImageStartTime = System.currentTimeMillis();
+        long startPosition = MetaHeader.write(imageFile);
+        List<MetaIndex> metaIndices = Lists.newArrayList();
+        try (CountingDataOutputStream dos = new CountingDataOutputStream(new BufferedOutputStream(
+                new FileOutputStream(imageFile, true)), startPosition)) {
+            long replayedJournalId = catalog.getReplayedJournalId();
+            metaIndices.add(new MetaIndex("header", dos.getCount()));
+            checksum = catalog.saveHeader(dos, replayedJournalId, checksum);
+            metaIndices.add(new MetaIndex("masterInfo", dos.getCount()));
+            checksum = catalog.saveMasterInfo(dos, checksum);
+            metaIndices.add(new MetaIndex("frontends", dos.getCount()));
+            checksum = catalog.saveFrontends(dos, checksum);
+            metaIndices.add(new MetaIndex("backends", dos.getCount()));
+            checksum = Catalog.getCurrentSystemInfo().saveBackends(dos, checksum);
+            metaIndices.add(new MetaIndex("db", dos.getCount()));
+            checksum = catalog.saveDb(dos, checksum);
+            metaIndices.add(new MetaIndex("loadJob", dos.getCount()));
+            checksum = catalog.saveLoadJob(dos, checksum);
+            metaIndices.add(new MetaIndex("alterJob", dos.getCount()));
+            checksum = catalog.saveAlterJob(dos, checksum);
+            metaIndices.add(new MetaIndex("recycleBin", dos.getCount()));
+            checksum = catalog.saveRecycleBin(dos, checksum);
+            metaIndices.add(new MetaIndex("globalVariable", dos.getCount()));
+            checksum = catalog.saveGlobalVariable(dos, checksum);
+            metaIndices.add(new MetaIndex("cluster", dos.getCount()));
+            checksum = catalog.saveCluster(dos, checksum);
+            metaIndices.add(new MetaIndex("broker", dos.getCount()));
+            checksum = catalog.saveBrokers(dos, checksum);
+            metaIndices.add(new MetaIndex("resources", dos.getCount()));
+            checksum = catalog.saveResources(dos, checksum);
+            metaIndices.add(new MetaIndex("exportJob", dos.getCount()));
+            checksum = catalog.saveExportJob(dos, checksum);
+            metaIndices.add(new MetaIndex("backupHandler", dos.getCount()));
+            checksum = catalog.saveBackupHandler(dos, checksum);
+            metaIndices.add(new MetaIndex("paloAuth", dos.getCount()));
+            checksum = catalog.savePaloAuth(dos, checksum);
+            metaIndices.add(new MetaIndex("transactionState", dos.getCount()));
+            checksum = catalog.saveTransactionState(dos, checksum);
+            metaIndices.add(new MetaIndex("colocateTableIndex", dos.getCount()));
+            checksum = catalog.saveColocateTableIndex(dos, checksum);
+            metaIndices.add(new MetaIndex("routineLoadJobs", dos.getCount()));
+            checksum = catalog.saveRoutineLoadJobs(dos, checksum);
+            metaIndices.add(new MetaIndex("loadJobV2", dos.getCount()));
+            checksum = catalog.saveLoadJobsV2(dos, checksum);
+            metaIndices.add(new MetaIndex("smallFiles", dos.getCount()));
+            checksum = catalog.saveSmallFiles(dos, checksum);
+            metaIndices.add(new MetaIndex("plugins", dos.getCount()));
+            checksum = catalog.savePlugins(dos, checksum);
+            metaIndices.add(new MetaIndex("deleteHandler", dos.getCount()));
+            checksum = catalog.saveDeleteHandler(dos, checksum);
+            dos.writeLong(checksum);

Review comment:
       ok




-- 
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


[GitHub] [incubator-doris] xy720 commented on a change in pull request #6207: [New Feature][Meta][Image] Add file header and footer for image

Posted by GitBox <gi...@apache.org>.
xy720 commented on a change in pull request #6207:
URL: https://github.com/apache/incubator-doris/pull/6207#discussion_r670971608



##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/MetaFooter.java
##########
@@ -0,0 +1,86 @@
+// 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.doris.common;
+
+import com.google.common.collect.Lists;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Arrays;
+import java.util.List;
+
+public class MetaFooter {
+    private static final Logger LOG = LogManager.getLogger(MetaFooter.class);
+
+    private static final long FOOTER_LENGTH_SIZE = 8L;
+    public static final MetaFooter EMPTY_FOOTER = new MetaFooter(null, 0L);
+
+    // length of footer
+    private long length;
+    // meta indices
+    public List<MetaIndex> metaIndices;
+
+    public static MetaFooter read(File imageFile) throws IOException {
+        try(RandomAccessFile raf = new RandomAccessFile(imageFile, "r")) {
+            long fileLength = raf.length();
+            long footerLengthIndex = fileLength - FOOTER_LENGTH_SIZE - MetaMagicNumber.MAGIC_STR.length();
+            raf.seek(footerLengthIndex);
+            long footerLength = raf.readLong();
+            MetaMagicNumber magicNumber = MetaMagicNumber.read(raf);
+            if (!Arrays.equals(MetaMagicNumber.MAGIC, magicNumber.getBytes())) {
+                LOG.warn("Image file {} format mismatch. Expected magic number is {}, actual is {}",
+                        imageFile.getPath(), Arrays.toString(MetaMagicNumber.MAGIC), Arrays.toString(magicNumber.getBytes()));
+                return EMPTY_FOOTER;

Review comment:
       When we read a old version image, the magic number is not exist, if we throw a exception here, it will fail to read the image. So my idea is, if we can't read the correct magic number here, then read this file as an old version of the image, and the old version of the image has no header or footer, so an empty header or footer is returned here.




-- 
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


[GitHub] [incubator-doris] xy720 commented on a change in pull request #6207: [New Feature][Meta][Image] Add file header and footer for image

Posted by GitBox <gi...@apache.org>.
xy720 commented on a change in pull request #6207:
URL: https://github.com/apache/incubator-doris/pull/6207#discussion_r670987923



##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/MetaHeader.java
##########
@@ -0,0 +1,103 @@
+// 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.doris.common;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Arrays;
+
+public class MetaHeader {

Review comment:
       done

##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/MetaFooter.java
##########
@@ -0,0 +1,86 @@
+// 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.doris.common;
+
+import com.google.common.collect.Lists;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Arrays;
+import java.util.List;
+
+public class MetaFooter {

Review comment:
       done




-- 
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


[GitHub] [incubator-doris] morningman merged pull request #6207: [New Feature][Meta][Image] Add file header and footer for image

Posted by GitBox <gi...@apache.org>.
morningman merged pull request #6207:
URL: https://github.com/apache/incubator-doris/pull/6207


   


-- 
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


[GitHub] [incubator-doris] xy720 commented on a change in pull request #6207: [New Feature][Meta][Image] Add file header and footer for image

Posted by GitBox <gi...@apache.org>.
xy720 commented on a change in pull request #6207:
URL: https://github.com/apache/incubator-doris/pull/6207#discussion_r670973120



##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/MetaWriter.java
##########
@@ -0,0 +1,131 @@
+// 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.doris.common;
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.common.io.CountingDataOutputStream;
+import com.google.common.collect.Lists;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Image Format:
+ * |- Image --------------------------------------|
+ * | - Magic String (4 bytes)                     |
+ * | - Header Length (4 bytes)                    |
+ * | |- Header -----------------------------|     |
+ * | | |- Json Header ---------------|      |     |
+ * | | | - version                   |      |     |
+ * | | | - other key/value(undecided)|      |     |
+ * | | |-----------------------------|      |     |
+ * | |--------------------------------------|     |
+ * |                                              |
+ * | |- Image Body -------------------------|     |
+ * | | Object a                             |     |
+ * | | Object b                             |     |
+ * | | ...                                  |     |
+ * | |--------------------------------------|     |
+ * |                                              |
+ * | |- Footer -----------------------------|     |
+ * | | |- object index --------------|      |     |
+ * | | | - index a                   |      |     |
+ * | | | - index b                   |      |     |
+ * | | | ...                         |      |     |
+ * | | |-----------------------------|      |     |
+ * | | - other value(undecided)             |     |
+ * | |--------------------------------------|     |
+ * | - Footer Length (8 bytes)                    |
+ * | - Magic String (4 bytes)                     |
+ * |----------------------------------------------|
+ */
+
+public class MetaWriter {
+    private static final Logger LOG = LogManager.getLogger(MetaWriter.class);
+
+    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;
+        long saveImageStartTime = System.currentTimeMillis();
+        long startPosition = MetaHeader.write(imageFile);
+        List<MetaIndex> metaIndices = Lists.newArrayList();
+        try (CountingDataOutputStream dos = new CountingDataOutputStream(new BufferedOutputStream(
+                new FileOutputStream(imageFile, true)), startPosition)) {
+            long replayedJournalId = catalog.getReplayedJournalId();
+            metaIndices.add(new MetaIndex("header", dos.getCount()));
+            checksum = catalog.saveHeader(dos, replayedJournalId, checksum);
+            metaIndices.add(new MetaIndex("masterInfo", dos.getCount()));
+            checksum = catalog.saveMasterInfo(dos, checksum);
+            metaIndices.add(new MetaIndex("frontends", dos.getCount()));
+            checksum = catalog.saveFrontends(dos, checksum);
+            metaIndices.add(new MetaIndex("backends", dos.getCount()));
+            checksum = Catalog.getCurrentSystemInfo().saveBackends(dos, checksum);
+            metaIndices.add(new MetaIndex("db", dos.getCount()));
+            checksum = catalog.saveDb(dos, checksum);
+            metaIndices.add(new MetaIndex("loadJob", dos.getCount()));
+            checksum = catalog.saveLoadJob(dos, checksum);
+            metaIndices.add(new MetaIndex("alterJob", dos.getCount()));
+            checksum = catalog.saveAlterJob(dos, checksum);
+            metaIndices.add(new MetaIndex("recycleBin", dos.getCount()));
+            checksum = catalog.saveRecycleBin(dos, checksum);
+            metaIndices.add(new MetaIndex("globalVariable", dos.getCount()));
+            checksum = catalog.saveGlobalVariable(dos, checksum);
+            metaIndices.add(new MetaIndex("cluster", dos.getCount()));
+            checksum = catalog.saveCluster(dos, checksum);
+            metaIndices.add(new MetaIndex("broker", dos.getCount()));
+            checksum = catalog.saveBrokers(dos, checksum);
+            metaIndices.add(new MetaIndex("resources", dos.getCount()));
+            checksum = catalog.saveResources(dos, checksum);
+            metaIndices.add(new MetaIndex("exportJob", dos.getCount()));
+            checksum = catalog.saveExportJob(dos, checksum);
+            metaIndices.add(new MetaIndex("backupHandler", dos.getCount()));
+            checksum = catalog.saveBackupHandler(dos, checksum);
+            metaIndices.add(new MetaIndex("paloAuth", dos.getCount()));
+            checksum = catalog.savePaloAuth(dos, checksum);
+            metaIndices.add(new MetaIndex("transactionState", dos.getCount()));
+            checksum = catalog.saveTransactionState(dos, checksum);
+            metaIndices.add(new MetaIndex("colocateTableIndex", dos.getCount()));
+            checksum = catalog.saveColocateTableIndex(dos, checksum);
+            metaIndices.add(new MetaIndex("routineLoadJobs", dos.getCount()));
+            checksum = catalog.saveRoutineLoadJobs(dos, checksum);
+            metaIndices.add(new MetaIndex("loadJobV2", dos.getCount()));
+            checksum = catalog.saveLoadJobsV2(dos, checksum);
+            metaIndices.add(new MetaIndex("smallFiles", dos.getCount()));
+            checksum = catalog.saveSmallFiles(dos, checksum);
+            metaIndices.add(new MetaIndex("plugins", dos.getCount()));
+            checksum = catalog.savePlugins(dos, checksum);
+            metaIndices.add(new MetaIndex("deleteHandler", dos.getCount()));
+            checksum = catalog.saveDeleteHandler(dos, checksum);
+            dos.writeLong(checksum);

Review comment:
       I think this is not compatible with the old image.




-- 
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


[GitHub] [incubator-doris] xy720 commented on a change in pull request #6207: [New Feature][Meta][Image] Add file header and footer for image

Posted by GitBox <gi...@apache.org>.
xy720 commented on a change in pull request #6207:
URL: https://github.com/apache/incubator-doris/pull/6207#discussion_r670972287



##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/MetaHeader.java
##########
@@ -0,0 +1,103 @@
+// 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.doris.common;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Arrays;
+
+public class MetaHeader {
+    private static final Logger LOG = LogManager.getLogger(MetaHeader.class);
+
+    public static final MetaHeader EMPTY_HEADER = new MetaHeader(null, 0);
+    private static final long HEADER_LENGTH_SIZE = 4L;
+
+    // length of Header
+    private long length;
+    // format of image
+    private FeMetaFormat metaFormat;
+    // json header
+    public MetaJsonHeader metaJsonHeader;
+
+    public static MetaHeader read(File imageFile) throws IOException {
+        try(RandomAccessFile raf = new RandomAccessFile(imageFile, "r")) {
+            raf.seek(0);
+            MetaMagicNumber magicNumber = MetaMagicNumber.read(raf);
+            if (!Arrays.equals(MetaMagicNumber.MAGIC, magicNumber.getBytes())) {
+                LOG.warn("Image file {} format mismatch. Expected magic number is {}, actual is {}",
+                        imageFile.getPath(), Arrays.toString(MetaMagicNumber.MAGIC), Arrays.toString(magicNumber.getBytes()));
+                return EMPTY_HEADER;

Review comment:
       The same as above.




-- 
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


[GitHub] [incubator-doris] xy720 commented on a change in pull request #6207: [New Feature][Meta][Image] Add file header and footer for image

Posted by GitBox <gi...@apache.org>.
xy720 commented on a change in pull request #6207:
URL: https://github.com/apache/incubator-doris/pull/6207#discussion_r670986228



##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/FeMetaFormat.java
##########
@@ -0,0 +1,44 @@
+// 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.doris.common;
+
+public enum FeMetaFormat {
+    COR1("COR1", "v1"),
+    ETL1("ETL1", "v1");

Review comment:
       May be shorter is better? Magic string is 4 bytes just like parquet file.




-- 
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


[GitHub] [incubator-doris] morningman commented on a change in pull request #6207: [New Feature][Meta][Image] Add file header and footer for image

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #6207:
URL: https://github.com/apache/incubator-doris/pull/6207#discussion_r669433023



##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/FeMetaFormat.java
##########
@@ -0,0 +1,44 @@
+// 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.doris.common;
+
+public enum FeMetaFormat {
+    COR1("COR1", "v1"),
+    ETL1("ETL1", "v1");

Review comment:
       ETL can be removed, and how about rename COR1 to DORIS_IMAGE? make it more readable

##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/MetaFooter.java
##########
@@ -0,0 +1,86 @@
+// 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.doris.common;
+
+import com.google.common.collect.Lists;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Arrays;
+import java.util.List;
+
+public class MetaFooter {
+    private static final Logger LOG = LogManager.getLogger(MetaFooter.class);
+
+    private static final long FOOTER_LENGTH_SIZE = 8L;
+    public static final MetaFooter EMPTY_FOOTER = new MetaFooter(null, 0L);
+
+    // length of footer
+    private long length;
+    // meta indices
+    public List<MetaIndex> metaIndices;
+
+    public static MetaFooter read(File imageFile) throws IOException {
+        try(RandomAccessFile raf = new RandomAccessFile(imageFile, "r")) {
+            long fileLength = raf.length();
+            long footerLengthIndex = fileLength - FOOTER_LENGTH_SIZE - MetaMagicNumber.MAGIC_STR.length();
+            raf.seek(footerLengthIndex);
+            long footerLength = raf.readLong();
+            MetaMagicNumber magicNumber = MetaMagicNumber.read(raf);
+            if (!Arrays.equals(MetaMagicNumber.MAGIC, magicNumber.getBytes())) {
+                LOG.warn("Image file {} format mismatch. Expected magic number is {}, actual is {}",
+                        imageFile.getPath(), Arrays.toString(MetaMagicNumber.MAGIC), Arrays.toString(magicNumber.getBytes()));
+                return EMPTY_FOOTER;

Review comment:
       I think we should throw an exception here, because this is an invalid file, not a "empty" one.
   And why put MagicNumber in both header and footer? I think one place is enough.

##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/MetaFooter.java
##########
@@ -0,0 +1,86 @@
+// 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.doris.common;
+
+import com.google.common.collect.Lists;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Arrays;
+import java.util.List;
+
+public class MetaFooter {

Review comment:
       You can add comment of the format of this footer

##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/MetaHeader.java
##########
@@ -0,0 +1,103 @@
+// 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.doris.common;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Arrays;
+
+public class MetaHeader {

Review comment:
       Add format in comment

##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/MetaHeader.java
##########
@@ -0,0 +1,103 @@
+// 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.doris.common;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Arrays;
+
+public class MetaHeader {
+    private static final Logger LOG = LogManager.getLogger(MetaHeader.class);
+
+    public static final MetaHeader EMPTY_HEADER = new MetaHeader(null, 0);
+    private static final long HEADER_LENGTH_SIZE = 4L;
+
+    // length of Header
+    private long length;
+    // format of image
+    private FeMetaFormat metaFormat;
+    // json header
+    public MetaJsonHeader metaJsonHeader;
+
+    public static MetaHeader read(File imageFile) throws IOException {
+        try(RandomAccessFile raf = new RandomAccessFile(imageFile, "r")) {
+            raf.seek(0);
+            MetaMagicNumber magicNumber = MetaMagicNumber.read(raf);
+            if (!Arrays.equals(MetaMagicNumber.MAGIC, magicNumber.getBytes())) {
+                LOG.warn("Image file {} format mismatch. Expected magic number is {}, actual is {}",
+                        imageFile.getPath(), Arrays.toString(MetaMagicNumber.MAGIC), Arrays.toString(magicNumber.getBytes()));
+                return EMPTY_HEADER;

Review comment:
       throw exception

##########
File path: fe/fe-core/src/main/java/org/apache/doris/common/MetaWriter.java
##########
@@ -0,0 +1,131 @@
+// 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.doris.common;
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.common.io.CountingDataOutputStream;
+import com.google.common.collect.Lists;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Image Format:
+ * |- Image --------------------------------------|
+ * | - Magic String (4 bytes)                     |
+ * | - Header Length (4 bytes)                    |
+ * | |- Header -----------------------------|     |
+ * | | |- Json Header ---------------|      |     |
+ * | | | - version                   |      |     |
+ * | | | - other key/value(undecided)|      |     |
+ * | | |-----------------------------|      |     |
+ * | |--------------------------------------|     |
+ * |                                              |
+ * | |- Image Body -------------------------|     |
+ * | | Object a                             |     |
+ * | | Object b                             |     |
+ * | | ...                                  |     |
+ * | |--------------------------------------|     |
+ * |                                              |
+ * | |- Footer -----------------------------|     |
+ * | | |- object index --------------|      |     |
+ * | | | - index a                   |      |     |
+ * | | | - index b                   |      |     |
+ * | | | ...                         |      |     |
+ * | | |-----------------------------|      |     |
+ * | | - other value(undecided)             |     |
+ * | |--------------------------------------|     |
+ * | - Footer Length (8 bytes)                    |
+ * | - Magic String (4 bytes)                     |
+ * |----------------------------------------------|
+ */
+
+public class MetaWriter {
+    private static final Logger LOG = LogManager.getLogger(MetaWriter.class);
+
+    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;
+        long saveImageStartTime = System.currentTimeMillis();
+        long startPosition = MetaHeader.write(imageFile);
+        List<MetaIndex> metaIndices = Lists.newArrayList();
+        try (CountingDataOutputStream dos = new CountingDataOutputStream(new BufferedOutputStream(
+                new FileOutputStream(imageFile, true)), startPosition)) {
+            long replayedJournalId = catalog.getReplayedJournalId();
+            metaIndices.add(new MetaIndex("header", dos.getCount()));
+            checksum = catalog.saveHeader(dos, replayedJournalId, checksum);
+            metaIndices.add(new MetaIndex("masterInfo", dos.getCount()));
+            checksum = catalog.saveMasterInfo(dos, checksum);
+            metaIndices.add(new MetaIndex("frontends", dos.getCount()));
+            checksum = catalog.saveFrontends(dos, checksum);
+            metaIndices.add(new MetaIndex("backends", dos.getCount()));
+            checksum = Catalog.getCurrentSystemInfo().saveBackends(dos, checksum);
+            metaIndices.add(new MetaIndex("db", dos.getCount()));
+            checksum = catalog.saveDb(dos, checksum);
+            metaIndices.add(new MetaIndex("loadJob", dos.getCount()));
+            checksum = catalog.saveLoadJob(dos, checksum);
+            metaIndices.add(new MetaIndex("alterJob", dos.getCount()));
+            checksum = catalog.saveAlterJob(dos, checksum);
+            metaIndices.add(new MetaIndex("recycleBin", dos.getCount()));
+            checksum = catalog.saveRecycleBin(dos, checksum);
+            metaIndices.add(new MetaIndex("globalVariable", dos.getCount()));
+            checksum = catalog.saveGlobalVariable(dos, checksum);
+            metaIndices.add(new MetaIndex("cluster", dos.getCount()));
+            checksum = catalog.saveCluster(dos, checksum);
+            metaIndices.add(new MetaIndex("broker", dos.getCount()));
+            checksum = catalog.saveBrokers(dos, checksum);
+            metaIndices.add(new MetaIndex("resources", dos.getCount()));
+            checksum = catalog.saveResources(dos, checksum);
+            metaIndices.add(new MetaIndex("exportJob", dos.getCount()));
+            checksum = catalog.saveExportJob(dos, checksum);
+            metaIndices.add(new MetaIndex("backupHandler", dos.getCount()));
+            checksum = catalog.saveBackupHandler(dos, checksum);
+            metaIndices.add(new MetaIndex("paloAuth", dos.getCount()));
+            checksum = catalog.savePaloAuth(dos, checksum);
+            metaIndices.add(new MetaIndex("transactionState", dos.getCount()));
+            checksum = catalog.saveTransactionState(dos, checksum);
+            metaIndices.add(new MetaIndex("colocateTableIndex", dos.getCount()));
+            checksum = catalog.saveColocateTableIndex(dos, checksum);
+            metaIndices.add(new MetaIndex("routineLoadJobs", dos.getCount()));
+            checksum = catalog.saveRoutineLoadJobs(dos, checksum);
+            metaIndices.add(new MetaIndex("loadJobV2", dos.getCount()));
+            checksum = catalog.saveLoadJobsV2(dos, checksum);
+            metaIndices.add(new MetaIndex("smallFiles", dos.getCount()));
+            checksum = catalog.saveSmallFiles(dos, checksum);
+            metaIndices.add(new MetaIndex("plugins", dos.getCount()));
+            checksum = catalog.savePlugins(dos, checksum);
+            metaIndices.add(new MetaIndex("deleteHandler", dos.getCount()));
+            checksum = catalog.saveDeleteHandler(dos, checksum);
+            dos.writeLong(checksum);

Review comment:
       checksum should be wrote in footer.




-- 
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