Called when you wish to finish adding batches to your request, this method rewrites the aggregate
 batch file to the final LitleRequest xml doc with the appropos LitleRequest tags.
512547
def finish_request

      File.open(@path_to_request, 'w') do |f|
        #jam dat header in there
        f.puts(build_request_header())
        #read into the request file from the batches file
        File.foreach(@path_to_batches) do |li|
          f.puts li
        end
        #finally, let's poot in a header, for old time's sake
        f.puts '</litleRequest>'
      end

      #rename the requests file
      File.rename(@path_to_request, @path_to_request + COMPLETE_FILE_SUFFIX)
      #we don't need the master batch file anymore
      File.delete(@path_to_batches)
    end
714081
def _submit_batch(self, url, batch):
        """"""
        # TODO: validate column_name
        batch_parts = batch.parts()

        guid = ""
        headers = {
            'User-Agent': 'kentik-python-api/0.1',
            'Content-Type': 'application/json',
            'X-CH-Auth-Email': self.api_email,
            'X-CH-Auth-API-Token': self.api_token
        }

        # submit each part
        last_part = dict()
        for batch_part in batch_parts:
            # submit
            resp = requests.post(url, headers=headers, data=batch_part.build_json(guid))

            # print the HTTP response to help debug
            print(resp.text)

            # break out at first sign of trouble
            resp.raise_for_status()
            last_part = resp.json()
            guid = last_part['guid']
            if guid is None or len(guid) == 0:
                raise RuntimeError('guid not found in batch response')

        return last_part
895728
function appendModel(url, model, done){
		var list = utils.flatten_tree(JSON.parse(JSON.stringify(model)))

		var errormodel = null

		list = list.filter(function(model){
			if(!model._digger.path || !model._digger.inode){
				errormodel = model;
				return false;
			}
			return true
		})

		if(errormodel){
			return done('no path or inode in level-append: ' + JSON.stringify(model))
		}

		var batch = list.map(function(model){
			return {
				type:'put',
				key:model._digger.path + '/' + model._digger.inode,
				value:model
			}
		})

		tree.batch(batch, function(err){
			if(err) return done(err)
			done(null, model)
		})
	}
447748
def file_add_tags(object_id, input_params={}, always_retry=True, **kwargs):
    
    return DXHTTPRequest('/%s/addTags' % object_id, input_params, always_retry=always_retry, **kwargs)
944778
def _do_batched_insert(collection_name, docs, check_keys,
                       safe, last_error_args, continue_on_error, opts,
                       ctx):
    
    def _insert_message(insert_message, send_safe):
        """Build the insert message with header and GLE.
        """
        request_id, final_message = __pack_message(2002, insert_message)
        if send_safe:
            request_id, error_message, _ = __last_error(collection_name,
                                                        last_error_args)
            final_message += error_message
        return request_id, final_message

    send_safe = safe or not continue_on_error
    last_error = None
    data = StringIO()
    data.write(struct.pack("<i", int(continue_on_error)))
    data.write(_make_c_string(collection_name))
    message_length = begin_loc = data.tell()
    has_docs = False
    to_send = []
    encode = _dict_to_bson  # Make local
    compress = ctx.compress and not (safe or send_safe)
    for doc in docs:
        encoded = encode(doc, check_keys, opts)
        encoded_length = len(encoded)
        too_large = (encoded_length > ctx.max_bson_size)

        message_length += encoded_length
        if message_length < ctx.max_message_size and not too_large:
            data.write(encoded)
            to_send.append(doc)
            has_docs = True
            continue

        if has_docs:
            # We have enough data, send this message.
            try:
                if compress:
                    rid, msg = None, data.getvalue()
                else:
                    rid, msg = _insert_message(data.getvalue(), send_safe)
                ctx.legacy_bulk_insert(
                    rid, msg, 0, send_safe, to_send, compress)
            # Exception type could be OperationFailure or a subtype
            # (e.g. DuplicateKeyError)
            except OperationFailure as exc:
                # Like it says, continue on error...
                if continue_on_error:
                    # Store exception details to re-raise after the final batch.
                    last_error = exc
                # With unacknowledged writes just return at the first error.
                elif not safe:
                    return
                # With acknowledged writes raise immediately.
                else:
                    raise

        if too_large:
            _raise_document_too_large(
                "insert", encoded_length, ctx.max_bson_size)

        message_length = begin_loc + encoded_length
        data.seek(begin_loc)
        data.truncate()
        data.write(encoded)
        to_send = [doc]

    if not has_docs:
        raise InvalidOperation("cannot do an empty bulk insert")

    if compress:
        request_id, msg = None, data.getvalue()
    else:
        request_id, msg = _insert_message(data.getvalue(), safe)
    ctx.legacy_bulk_insert(request_id, msg, 0, safe, to_send, compress)

    # Re-raise any exception stored due to continue_on_error
    if last_error is not None:
        raise last_error
160923
def submit_tag_batch(self, batch):
        """"""
        url = '%s/api/v5/batch/tags' % self.base_url
        self._submit_batch(url, batch)
414528
function mergeBatchResults(batches) {
    let files = [];
    let unformattedFiles = [];
    let formattedFiles = [];
    let errors = [];

    batches.forEach(batch => {
        files.push(...batch.files);
        unformattedFiles.push(...batch.unformattedFiles);
        formattedFiles.push(...batch.formattedFiles);
        errors.push(...batch.errors);
    });

    return { files, formattedFiles, unformattedFiles, errors };
}
210074
def submitBatches(self, batches):
    
    self._seqid += 1
    future = self._reqs[self._seqid] = concurrent.Future()
    self.send_submitBatches(batches)
    return future
1069524
public void performAdd(InputStream in, String baseURI, RDFFormat dataFormat, Transaction tx, Resource... contexts) throws RDFParseException, MarkLogicSesameException {
        try {
            graphManager.setDefaultMimetype(dataFormat.getDefaultMIMEType());
            if (dataFormat.equals(RDFFormat.NQUADS) || dataFormat.equals(RDFFormat.TRIG)) {
                graphManager.mergeGraphs(new InputStreamHandle(in),tx);
            } else {
                if (notNull(contexts) && contexts.length > 0) {
                    for (int i = 0; i < contexts.length; i++) {
                        if (notNull(contexts[i])) {
                            graphManager.mergeAs(contexts[i].toString(), new InputStreamHandle(in), getGraphPerms(), tx);
                        } else {
                            graphManager.mergeAs(DEFAULT_GRAPH_URI, new InputStreamHandle(in),getGraphPerms(), tx);
                        }
                    }
                } else {
                    graphManager.mergeAs(DEFAULT_GRAPH_URI, new InputStreamHandle(in),getGraphPerms(), tx);
                }
            }
            in.close();
        } catch (FailedRequestException e) {
            logger.error(e.getLocalizedMessage());
            throw new RDFParseException("Request to MarkLogic server failed, check input is valid.");
        } catch (IOException e) {
            logger.error(e.getLocalizedMessage());
            throw new MarkLogicSesameException("IO error");
        }
    }
841453
def add_to_batch(self, batch):
        '''
        
        '''
        for name in self.paths:
            svg_path = self.paths[name]
            svg_path.add_to_batch(batch)
891809
private boolean updateBatch(DBObjectBatch dbObjBatch, BatchResult batchResult) throws IOException {
        Map<String, Map<String, String>> objCurrScalarMap = getCurrentScalars(dbObjBatch);
        Map<String, Map<String, Integer>> targObjShardNos = getLinkTargetShardNumbers(dbObjBatch);
        for (DBObject dbObj : dbObjBatch.getObjects()) {
            checkCommit();
            Map<String, String> currScalarMap = objCurrScalarMap.get(dbObj.getObjectID());
            ObjectResult objResult = updateObject(dbObj, currScalarMap, targObjShardNos);
            batchResult.addObjectResult(objResult);
        }
        commitTransaction();
        return batchResult.hasUpdates();
    }
1277457
def prepare_batch(self, batch: mx.io.DataBatch):
        
        self.module.prepare(batch)
536695
def job_add_tags(object_id, input_params={}, always_retry=True, **kwargs):
    
    return DXHTTPRequest('/%s/addTags' % object_id, input_params, always_retry=always_retry, **kwargs)
526661
private void afterBatch(BatchBackend backend) {
		IndexedTypeSet targetedTypes = searchFactoryImplementor.getIndexedTypesPolymorphic( rootIndexedTypes );
		if ( this.optimizeAtEnd ) {
			backend.optimize( targetedTypes );
		}
		backend.flush( targetedTypes );
	}
975918
@Override
    public void close() {
        try {
            if (!hadWriteErrors) {
                flush();
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Dirty close; ignoring last existing write batch...");
                }
            }

            if (requiresRefreshAfterBulk && executedBulkWrite) {
                // refresh batch
                restClient.refresh(resource);

                if (LOG.isDebugEnabled()) {
                    LOG.debug(String.format("Refreshing index [%s]", resource));
                }
            }
        } finally {
            for (IBulkWriteErrorHandler handler : documentBulkErrorHandlers) {
                handler.close();
            }
        }
    }
231907
protected void insertBatch(Content[] batch, int id) 
    throws IOException {
        retry = 0;
        sleepTime = 500;
        while (retry < maxRetries) {
            try {
                if (retry == 1) { 
                    LOG.info("Retrying document insert");
                }
                List<RequestException> errors = 
                    sessions[id].insertContentCollectErrors(batch);
                if (errors != null) {
                    for (RequestException ex : errors) {
                        Throwable cause = ex.getCause();
                        if (cause != null) {
                            if (cause instanceof QueryException) {
                                LOG.error(
                                    ((QueryException)cause).getFormatString());
                            } else {
                                LOG.error(cause.getMessage());
                            }
                        }
                        if (ex instanceof ContentInsertException) {
                            Content content = 
                                    ((ContentInsertException)ex).getContent();
                            DocumentURI failedUri = 
                                    pendingUris[id].remove(content);
                            failed++;
                            if (failedUri != null) {
                                LOG.warn("Failed document " + failedUri);
                            }
                        }
                    }
                }
                if (retry > 0) { 
                    LOG.debug("Retry successful");
                }
            } catch (Exception e) {
                boolean retryable = true;
                if (e instanceof QueryException) {
                    LOG.error("QueryException:" + ((QueryException)e).getFormatString());
                    retryable = ((QueryException)e).isRetryable();
                } else if (e instanceof RequestServerException) {
                    // log error and continue on RequestServerException
                    // not retryable so trying to connect to the replica
                    LOG.error("RequestServerException:" + e.getMessage());
                } else {
                    LOG.error("Exception:" + e.getMessage());
                }

                // necessary to roll back in certain scenarios.
                if (needCommit) {
                    rollback(id);
                }

                if (retryable && ++retry < maxRetries) {
                    // necessary to close the session too.
                    sessions[id].close();
                    try {
                        InternalUtilities.sleep(sleepTime);
                    } catch (Exception e2) {
                    }
                    sleepTime = sleepTime * 2;
                    if (sleepTime > maxSleepTime) 
                        sleepTime = maxSleepTime;
                    
                    // We need to switch host even for RetryableQueryException
                    // because it could be "sync replicating" (bug:45785)
                    sessions[id] = getSession(id, true);
                    continue;
                } else if (retryable) {
                    LOG.info("Exceeded max retry");
                }
                failed += batch.length;
                // remove the failed content from pendingUris
                for (Content fc : batch) {
                    DocumentURI failedUri = pendingUris[id].remove(fc);
                    LOG.warn("Failed document " + failedUri);
                }
                throw new IOException(e);
            } 
            break;
        }

        if (needCommit) {
            // move uris from pending to commit
            for (DocumentURI uri : pendingUris[id].values()) {
                commitUris[id].add(uri);
            }
        } else {
            succeeded += pendingUris[id].size();
        }
        pendingUris[id].clear();
    }
34126
def populate(self, deserialized_txs=None, filename=None, retry=None):
        
        if not deserialized_txs:
            raise BatchError("Failed to populate batch. There are no objects to add.")
        self.filename = filename
        if not self.filename:
            raise BatchError("Invalid filename. Got None")
        try:
            for deserialized_tx in deserialized_txs:
                self.peek(deserialized_tx)
                self.objects.append(deserialized_tx.object)
                break
            for deserialized_tx in deserialized_txs:
                self.objects.append(deserialized_tx.object)
        except DeserializationError as e:
            raise BatchDeserializationError(e) from e
        except JSONFileError as e:
            raise BatchDeserializationError(e) from e