cshannon commented on code in PR #3151:
URL: https://github.com/apache/accumulo/pull/3151#discussion_r1063596711


##########
core/src/main/java/org/apache/accumulo/core/data/Value.java:
##########
@@ -181,6 +182,15 @@ public void readFields(final DataInput in) throws 
IOException {
     in.readFully(this.value, 0, this.value.length);
   }
 
+  public void readFields(final DataInput in, Supplier<Long> 
freeMemorySupplier) throws IOException {
+    int length = in.readInt();
+    while (freeMemorySupplier.get() < length) {
+      Thread.onSpinWait();
+    }
+    this.value = new byte[length];

Review Comment:
   I haven't fully thought about this approach yet in terms of the consequences 
of trying to wait for free memory as I've never tried to do it before but one 
thing that stands out to me is that there seems like there's always going to be 
a race condition here. Even if you wait and get the ok that there is memory to 
proceed by the time you continue and get to this line and go to allocate memory 
for the byte array there's no guarantee the JVM hasn't already allocated some 
of the memory you'd need for this to work in another thread. In fact, if you 
were right on the edge and barely had enough memory then I would think this 
could fail often with the JVM allocating memory in other threads. In practice 
though I don't know if that's true without testing but it seems a bit non 
deterministic since you don't have much control over the GC process and what 
other threads are doing.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to