private WriteBatch BuildBatchGroup(Writer last_writer) {
		assert (!writers_.isEmpty());
		Writer first = writers_.peek();
		WriteBatch result = first.batch;
		assert (result != null);

		int size = WriteBatchInternal.ByteSize(first.batch);

		// Allow the group to grow up to a maximum size, but if the
		// original write is small, limit the growth so we do not slow
		// down the small write too much.
		int max_size = 1 << 20;
		if (size <= (128 << 10)) {
			max_size = size + (128 << 10);
		}

		last_writer = first;
		java.util.Iterator<Writer> iter = writers_.iterator();// begin();
		iter.next();
		// ++iter; // Advance past "first"
		while (iter.hasNext()) {
			Writer w = iter.next();
			if (w.sync && !first.sync) {
				// Do not include a sync write into a batch handled by a
				// non-sync write.
				break;
			}

			if (w.batch != null) {
				size += WriteBatchInternal.ByteSize(w.batch);
				if (size > max_size) {
					// Do not make batch too big
					break;
				}

				// Append to *reuslt
				if (result == first.batch) {
					// Switch to temporary batch instead of disturbing caller's
					// batch
					result = tmp_batch_;
					assert (WriteBatchInternal.Count(result) == 0);
					WriteBatchInternal.Append(result, first.batch);
				}
				WriteBatchInternal.Append(result, w.batch);
			}
			last_writer = w;
		}
		return result;
	}