Commit e52e88ff authored by Jesse Mapel's avatar Jesse Mapel Committed by Makayla Shepherd
Browse files

Changed ControlNetVersioner to avoid protobuf errors with large networks.

parent ef1368de
Loading
Loading
Loading
Loading
+16 −20
Original line number Diff line number Diff line
@@ -81,36 +81,32 @@ namespace Isis {
      }
      headerCodedInStream.PopLimit(oldLimit);

      // Without closing and re-opening the protocol buffers break... no clue
      //   why other than it's got some static data around keeping track
      //   maybe. We need to do this for it to reset it's idea of the total
      //   bytes though. Doing it every time is too expensive - so we're going
      //   to just do it periodically.
      IstreamInputStream *pointInStream = NULL;
      CodedInputStream *pointCodedInStream = NULL;
      
      for (int cp = 0; cp < p_networkHeader->pointmessagesizes_size(); cp ++) {
        if (cp % 50000 == 0 && pointCodedInStream && pointInStream) {
          delete pointCodedInStream;
          pointCodedInStream = NULL;
      // We need to regenerate the coded input stream every so many bytes
      // choose 64 MB as a safe amount
      int streamThreshold = 1024 * 1024 * 64;
      int currentStreamSize = 0;
      input.seekg(filePos, ios::beg);
      IstreamInputStream *pointInStream = new IstreamInputStream(&input);
      CodedInputStream *pointCodedInStream = new CodedInputStream(pointInStream);
      pointCodedInStream->SetTotalBytesLimit(1024 * 1024 * 512,
                                             1024 * 1024 * 400);

          delete pointInStream;
          pointInStream = NULL;
        }
      for (int cp = 0; cp < p_networkHeader->pointmessagesizes_size(); cp ++) {

        if (pointInStream == NULL) {
          input.close();
          input.open(file.expanded().toLatin1().data(), ios::in | ios::binary);
          input.seekg(filePos, ios::beg);
        int size = p_networkHeader->pointmessagesizes(cp);
        currentStreamSize += size;

          pointInStream = new IstreamInputStream(&input);
        if (currentStreamSize > streamThreshold) {
          currentStreamSize = size;
          delete pointCodedInStream;
          pointCodedInStream = NULL;
          pointCodedInStream = new CodedInputStream(pointInStream);
          // max 512MB, warn at 400MB
          pointCodedInStream->SetTotalBytesLimit(1024 * 1024 * 512,
                                                 1024 * 1024 * 400);
        }

        int size = p_networkHeader->pointmessagesizes(cp);
        oldLimit = pointCodedInStream->PushLimit(size);

        filePos += size;
+2 −0
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ namespace Isis {
   *   @history 2016-04-22 Jeannie Backer - Removed thrown exception in
   *                           toPvl() when unable to find TargetRadii values. Instead, we
   *                           will just leave these values blank. References #3892
   *   @history 2017-12-07 Jesse Mapel - Changed how often read streams are recreated to avoid
   *                           protobuf errors.
   */
  class ControlNetFileV0002 : public ControlNetFile {
    public: