public static void checkMetaDir() throws InvalidMetaDirException,
                                             IOException {
        // check meta dir
        //   if metaDir is the default config: StarRocksFE.STARROCKS_HOME_DIR + "/meta",
        //   we should check whether both the new default dir (STARROCKS_HOME_DIR + "/meta")
        //   and the old default dir (DORIS_HOME_DIR + "/doris-meta") are present. If both are present,
        //   we need to let users keep only one to avoid starting from outdated metadata.
        Path oldDefaultMetaDir = Paths.get(System.getenv("DORIS_HOME") + "/doris-meta");
        Path newDefaultMetaDir = Paths.get(System.getenv("STARROCKS_HOME") + "/meta");
        Path metaDir = Paths.get(Config.meta_dir);
        if (metaDir.equals(newDefaultMetaDir)) {
            File oldMeta = new File(oldDefaultMetaDir.toUri());
            File newMeta = new File(newDefaultMetaDir.toUri());
            if (oldMeta.exists() && newMeta.exists()) {
                LOG.error("New default meta dir: {} and Old default meta dir: {} are both present. " +
                                "Please make sure {} has the latest data, and remove the another one.",
                        newDefaultMetaDir, oldDefaultMetaDir, newDefaultMetaDir);
                throw new InvalidMetaDirException();
            }
        }

        File meta = new File(metaDir.toUri());
        if (!meta.exists()) {
            // If metaDir is not the default config, it means the user has specified the other directory
            // We should not use the oldDefaultMetaDir.
            // Just exit in this case
            if (!metaDir.equals(newDefaultMetaDir)) {
                LOG.error("meta dir {} dose not exist", metaDir);
                throw new InvalidMetaDirException();
            }
            File oldMeta = new File(oldDefaultMetaDir.toUri());
            if (oldMeta.exists()) {
                // For backward compatible
                Config.meta_dir = oldDefaultMetaDir.toString();
            } else {
                LOG.error("meta dir {} does not exist", meta.getAbsolutePath());
                throw new InvalidMetaDirException();
            }
        }

        long lowerFreeDiskSize = Long.parseLong(EnvironmentParams.FREE_DISK.getDefault());
        FileStore store = Files.getFileStore(Paths.get(Config.meta_dir));
        if (store.getUsableSpace() < lowerFreeDiskSize) {
            LOG.error("Free capacity left for meta dir: {} is less than {}",
                    Config.meta_dir, new ByteSizeValue(lowerFreeDiskSize));
            throw new InvalidMetaDirException();
        }

        Path imageDir = Paths.get(Config.meta_dir + GlobalStateMgr.IMAGE_DIR);
        Path bdbDir = Paths.get(BDBEnvironment.getBdbDir());
        boolean haveImageData = false;
        if (Files.exists(imageDir)) {
            try (Stream<Path> stream = Files.walk(imageDir)) {
                haveImageData = stream.anyMatch(path -> path.getFileName().toString().startsWith("image."));
            }
        }
        boolean haveBDBData = false;
        if (Files.exists(bdbDir)) {
            try (Stream<Path> stream = Files.walk(bdbDir)) {
                haveBDBData = stream.anyMatch(path -> path.getFileName().toString().endsWith(".jdb"));
            }
        }
        if (haveImageData && !haveBDBData && !Config.start_with_incomplete_meta) {
            LOG.error("image exists, but bdb dir is empty, " +
                    "set start_with_incomplete_meta to true if you want to forcefully recover from image data, " +
                    "this may end with stale meta data, so please be careful.");
            throw new InvalidMetaDirException();
        }
    }
@Test
    public void testImageExistBDBNotExistWithConfig() throws IOException,
            InvalidMetaDirException {
        Config.start_with_incomplete_meta = true;
        Config.meta_dir = testDir + "/meta";
        mkdir(Config.meta_dir + "/image");
        File file = new File(Config.meta_dir + "/image/image.123");
        Assert.assertTrue(file.createNewFile());

        try {
            MetaHelper.checkMetaDir();
        } finally {
            deleteDir(new File(testDir + "/"));
        }
    }