presto-main/src/main/java/io/prestosql/execution/scheduler/ScaledOutputBufferManager.java/ScaledOutputBufferManager/addOutputBuffers
class ScaledOutputBufferManager:    @SuppressWarnings("ObjectEquality")
    @Override
    public void addOutputBuffers(List<OutputBufferId> newBuffers, boolean noMoreBuffers)
    {
        OutputBuffers newOutputBuffers;
        synchronized (this) {
            if (outputBuffers.isNoMoreBufferIds()) {
                // a stage can move to a final state (e.g., failed) while scheduling,
                // so ignore the new buffers
                return;
            }

            OutputBuffers originalOutputBuffers = outputBuffers;

            for (OutputBufferId newBuffer : newBuffers) {
                outputBuffers = outputBuffers.withBuffer(newBuffer, newBuffer.getId());
            }

            if (noMoreBuffers) {
                outputBuffers = outputBuffers.withNoMoreBufferIds();
            }

            // don't update if nothing changed
            if (outputBuffers == originalOutputBuffers) {
                return;
            }
            newOutputBuffers = this.outputBuffers;
        }
        outputBufferTarget.accept(newOutputBuffers);
    }