protected File rollLogWriter(long searchIndex, WALFileStatus fileStatus) throws IOException {
    // close file
    currentWALFileWriter.close();
    addDiskUsage(currentWALFileWriter.size());
    addFileNum(1);
    File lastFile = currentWALFileWriter.getLogFile();
    String lastName = lastFile.getName();
    if (WALFileUtils.parseStatusCode(lastName) != fileStatus) {
      String targetName =
          WALFileUtils.getLogFileName(
              WALFileUtils.parseVersionId(lastName),
              WALFileUtils.parseStartSearchIndex(lastName),
              fileStatus);
      File targetFile = SystemFileFactory.INSTANCE.getFile(logDirectory, targetName);
      Files.move(
          lastFile.toPath(),
          targetFile.toPath(),
          StandardCopyOption.REPLACE_EXISTING,
          StandardCopyOption.ATOMIC_MOVE);
      lastFile = targetFile;
    }
    // roll file
    long nextFileVersion = currentWALFileVersion + 1;
    File nextLogFile =
        SystemFileFactory.INSTANCE.getFile(
            logDirectory,
            WALFileUtils.getLogFileName(
                nextFileVersion, searchIndex, WALFileStatus.CONTAINS_SEARCH_INDEX));
    currentWALFileWriter = new WALWriter(nextLogFile);
    currentWALFileVersion = nextFileVersion;
    logger.debug("Open new wal file {} for wal node-{}'s buffer.", nextLogFile, identifier);
    return lastFile;
  }
Notice: only called by syncBufferThread and old log writer will be closed by this function.

@return last wal file
@throws IOException If failing to close or open the log writer
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/wal/buffer/AbstractWALBuffer.java