private static boolean isValidMagicString(FileChannel channel) throws IOException {
    ByteBuffer magicStringBytes = ByteBuffer.allocate(WALFileVersion.V2.getVersionBytes().length);
    channel.read(magicStringBytes, channel.size() - WALFileVersion.V2.getVersionBytes().length);
    magicStringBytes.flip();
    String magicString = new String(magicStringBytes.array(), StandardCharsets.UTF_8);
    return magicString.equals(WALFileVersion.V2.getVersionString())
        || magicString.contains(WALFileVersion.V1.getVersionString());
  }
Metadata exists at the end of each wal file, including each entry's size, search index of first
entry and the number of entries.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/io/WALMetaData.java