ENG-6472 Added histogram latency stats to web studio

I will change it. WeakReference is a bit tricky to use, now I know how to
use it properly.

Thanks,
Yang Lu


On Fri, Jun 20, 2014 at 11:36 AM, aweisberg <notifications@github.com>
wrote:

> In src/frontend/org/voltdb/dtxn/LatencyStats.java:
>
> > +                    }
> > +                }
> > +                m_compressedCache = null;
> > +                m_serializedCache = null;
> > +
> > +                return m_totals;
> > +            }
> > +        }, EXPIRATION, TimeUnit.MILLISECONDS);
> > +    }
> > +    private Supplier<AbstractHistogram> m_histogramSupplier = getHistogramSupplier();
> > +
> > +    public byte[] getSerializedCache() {
> > +        if (m_serializedCache == null || m_serializedCache.get() == null) {
> > +            m_serializedCache = new WeakReference<byte[]>(m_histogramSupplier.get().toUncompressedBytes());
> > +        }
> > +        return m_serializedCache.get();
>
> This has the issue that when you check if the vaue from the cache is null,
> you don't retain the reference. What you want is to assign the value of the
> cache to a variable on the stack, and if it isn't null return that. If it
> is null, construct the value on to the stack variable, then create the weak
> reference.
>
> byte[] retval = null;
> if (m_serializedCache == null || (retval = m_serializedCache.get()) ==
> null) {
> retval = m_histogramSupplier.get().toUncompressedBytes();
> m_serializedCache = new WeakReference(retval);
> }
> return retval;
>
> --
> Reply to this email directly or view it on GitHub
> <https://github.com/VoltDB/voltdb/pull/1429/files#r14025814>.
>