@Override
    public TaskDataWriter<T> getDataWriter(DataWriterKey writerKey) throws IOException {
      if (!writerKey.equals(currentKey)) {
        if (currentKey != null) {
          closeCurrentWriter();
          completedKeys.add(currentKey);
        }

        if (completedKeys.contains(writerKey)) {
          throw new IllegalStateException(
              "The write key " + writerKey + " has already been completed");
        }

        currentKey = writerKey.copy();
        currentWriter = newWriter(currentKey);
      } else if (shouldRollToNewFile(currentWriter)) {
        closeCurrentWriter();
        currentWriter = newWriter(writerKey);
      }

      return currentWriter;
    }
a writer holder which require records had been sorted before write. The holder will hold only
one writer in open, and will throw an IllegalStateException exception if TaskWriter request a
data writer via a write key which has been already closed.
amoro-format-iceberg/src/main/java/org/apache/amoro/io/writer/BaseTaskWriter.java