code: protected boolean mergeEventsToLastBatch() throws IOException {
          // Checks if we can merge _batch into _lastBatch
          if(_lastBatch != null && _eventBatchSize >= (_lastBatch.getSize() + _batch.getSize())) {
              _batch.setCompletionTime(System.currentTimeMillis());
              
              if(_flushListener != null) {
                  _flushListener.beforeFlush(_batch);
              }
              
              // Creates a copy of the _lastBatch
              SimpleEventBatch<T> copy = ((SimpleEventBatch<T>)_lastBatch).clone();
              
              try {
                  // Add events from _batch to the copy
                  Iterator<Event<T>> iter = _batch.iterator();
                  while(iter.hasNext()) {
                      copy.put(iter.next());
                  }
                  copy.setCompletionTime(_batch.getCompletionTime());
                  
                  /* Flush starts automatically upon adding _batch to BytesDB
                   * because the constructor sets update batchSize to 1.
                   */
                  byte[] bytes = _eventBatchSerializer.serialize(copy);
                  _store.set(_lastBatchCursor.getLookup(), bytes, getOffset());
              } catch (Exception e) {
                  _logger.info("events merge aborted", e);
                  return false;
              }
              
              if(_flushListener != null) {
                  _flushListener.afterFlush(_batch);
              }
              
              _batchLock.lock();
              try {
                  // Updated _lastBatch
                  _lastBatch = copy;
                  _lastBatchCursor.setHeader(copy.getHeader());
                  _logger.info(_batch.getSize() + " events merged to EventBatch " + _lastBatchCursor.getLookup());
                  
                  // Create the next batch
                  _batch = nextEventBatch(_batch.getOrigin() + _batch.getSize(), _batch.getMaxClock());
              } finally {
                  _batchLock.unlock();
              }
              
              return true;
          }
          
          return false;
      }
docs: Try to merge events from the current batch to the last persisted batch
  in order to reduce the number of smaller batches in the retention.
  
  @return <code>true</code> if the merge operation is performed successfully
  @throws IOException