Buffers the given edit and possibly flushes the buffer if needed. If the edit buffer grows beyond a certain size, we will flush it even though the flush interval specified by the client hasn't elapsed yet. @param request An edit to sent to HBase.
(final BatchableRpc request)
| 827 | * @param request An edit to sent to HBase. |
| 828 | */ |
| 829 | private void bufferEdit(final BatchableRpc request) { |
| 830 | MultiAction batch; |
| 831 | boolean schedule_flush = false; |
| 832 | |
| 833 | synchronized (this) { |
| 834 | if (batched_rpcs == null) { |
| 835 | batched_rpcs = new MultiAction(); |
| 836 | addMultiActionCallbacks(batched_rpcs); |
| 837 | schedule_flush = true; |
| 838 | } |
| 839 | batch = batched_rpcs; |
| 840 | // Unfortunately we have to hold the monitor on `this' while we do |
| 841 | // this entire atomic dance. |
| 842 | batch.add(request); |
| 843 | if (batch.size() < batch_size) { |
| 844 | batch = null; // We're going to buffer this edit for now. |
| 845 | } else { |
| 846 | // Execute the edits buffered so far. But first we must clear |
| 847 | // the reference to the buffer we're about to send to HBase. |
| 848 | batched_rpcs = new MultiAction(); |
| 849 | addMultiActionCallbacks(batched_rpcs); |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | if (schedule_flush) { |
| 854 | scheduleNextPeriodicFlush(); |
| 855 | } else if (batch != null) { |
| 856 | sendRpc(batch); |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | /** |
| 861 | * Creates callbacks to handle a multi-put and adds them to the request. |
no test coverage detected