Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-589

Driver should sanity check the size of the request document and fail fast

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.7.0
    • Component/s: bulk, libmongoc
    • Labels:
      None
    • Story Points:
      4

      Description

      The driver should fail fast on document bounds. For large document, i.e. the ones going beyond the 16 MB document limit (or whatever server publishes to be the limits) the server may either return an error or close the connection which leaves the client with a failed socket but without any specific error information based on which it make any intelligent decision to skip documents.

      It would be much more efficient if the driver layer can perform the necessary validations in terms of document size etc. The java driver already performs these checks before sending the request to the MongoDB instance.

      // CC insert.c -o insert -Isrc/mongoc/ -I src/libbson/src/bson/ -L src/libbson/.libs/ -L .libs/ -lbson -lmongoc-1.0
      #include "mongoc.h"
       
      const char* const TEST_NS = "test.big_document";
       
      int main(int argc, const char* argv[]) {
          mongoc_client_t *client;
          char longStr[5 * 1024*1024] = {};
       
          fprintf(stderr, "Will continue with memsetting the values.\n");
          memset(longStr, 'a', sizeof(longStr));
          longStr[sizeof(longStr) - 1] = '\0';
       
          mongoc_init();
          client = mongoc_client_new("mongodb://127.0.0.1:27017");
          if (!client) {
              fprintf(stderr, "Failed to make client connection to mongod");
              return 1;
          }
       
          fprintf(stderr, "Will continue with creating the object.\n");
       
          bson_t *doc;
          doc = bson_new();
          BSON_APPEND_UTF8(doc, "key_1", longStr);
          BSON_APPEND_UTF8(doc, "key_2", longStr);
          BSON_APPEND_UTF8(doc, "key_3", longStr);
          BSON_APPEND_UTF8(doc, "key_4", longStr);
       
          fprintf(stderr, "Completed creating the document.. will continue with insertion.\n");
          mongoc_collection_t *collection = mongoc_client_get_collection (client, "test", "test");
       
          bson_error_t error;
          if (!mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)) {
              printf ("%s\n", error.message);
          }
       
          bson_destroy(doc);
          mongoc_collection_destroy(collection);
       
          mongoc_client_destroy(client);
          return 0;
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              backlog-c-driver Backlog - C Driver Team
              Reporter:
              anil.kumar Anil Kumar
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: