Called the first time we get a buffered increment. Lazily creates the increment buffer and sets up a timer to regularly flush buffered increments.
()
| 1823 | * flush buffered increments. |
| 1824 | */ |
| 1825 | private synchronized void setupMultiColumnIncrementCoalescing() { |
| 1826 | // If multiple threads attempt to setup coalescing at the same time, the |
| 1827 | // first one to get here will make `increment_buffer' non-null, and thus |
| 1828 | // subsequent ones will return immediately. This is important to avoid |
| 1829 | // creating more than one FlushBufferedIncrementsTimer below. |
| 1830 | if (multi_column_increment_buffer != null) { |
| 1831 | return; |
| 1832 | } |
| 1833 | makeMultiColumnIncrementBuffer(); // Volatile-write. |
| 1834 | |
| 1835 | // Start periodic buffered increment flushes. |
| 1836 | final class FlushBufferedMultiColumnIncrementsTimer implements TimerTask { |
| 1837 | public void run(final Timeout timeout) { |
| 1838 | try { |
| 1839 | flushBufferedMultiColumnIncrements(multi_column_increment_buffer); |
| 1840 | } finally { |
| 1841 | final short interval = flush_interval; // Volatile-read. |
| 1842 | // Even if we paused or disabled the client side buffer by calling |
| 1843 | // setFlushInterval(0), we will continue to schedule this timer |
| 1844 | // forever instead of pausing it. Pausing it is troublesome because |
| 1845 | // we don't keep a reference to this timer, so we can't cancel it or |
| 1846 | // tell if it's running or not. So let's just KISS and assume that |
| 1847 | // if we need the timer once, we'll need it forever. If it's truly |
| 1848 | // not needed anymore, we'll just cause a bit of extra work to the |
| 1849 | // timer thread every 100ms, no big deal. |
| 1850 | newTimeout(this, interval > 0 ? interval : 100); |
| 1851 | } |
| 1852 | } |
| 1853 | } |
| 1854 | final short interval = flush_interval; // Volatile-read. |
| 1855 | // Handle the extremely unlikely yet possible racy case where: |
| 1856 | // flush_interval was > 0 |
| 1857 | // A buffered increment came in |
| 1858 | // It was the first one ever so we landed here |
| 1859 | // Meanwhile setFlushInterval(0) to disable buffering |
| 1860 | // In which case we just flush whatever we have in 1ms. |
| 1861 | timer.newTimeout(new FlushBufferedMultiColumnIncrementsTimer(), |
| 1862 | interval > 0 ? interval : 1, MILLISECONDS); |
| 1863 | } |
| 1864 | |
| 1865 | /** |
| 1866 | * Flushes all buffered increments. |
no test coverage detected