Fix PrestoSparkRowBuffer synchronization
Otherwise newly added row can be pulled out of buffer
even before the memory context is updated resulting in assertion
failures in memory context as overall memory utilization can become
negative
@@ -49,9 +49,9 @@ public class PrestoSparkRowBuffer
requireNonNull(row, "row is null");
synchronized (monitor) {
buffer.add(row);
+ memoryManager.updateMemoryUsage(row.getRetainedSize());
monitor.notify();
}
- memoryManager.updateMemoryUsage(row.getRetainedSize());
}
public void setNoMoreRows()
@@ -81,10 +81,10 @@ public class PrestoSparkRowBuffer
if (!buffer.isEmpty()) {
row = buffer.poll();
}
- }
if (row != null) {
memoryManager.updateMemoryUsage(-row.getRetainedSize());
}
+ }
return row;
}
}
