Logo Search packages:      
Sourcecode: condor version File versions  Download package

FileOpErrCode ClassAdLogParser::readLogEntry ( int &  op_type,
bool  ex = false 
)

read a classad log entry in the current offset of a file

read a classad log entry in the current offset of a job queue log file

Parameters:
ex determine if the file is through standard file I/O or stream file I/O (default is false, which means standard file I/O).
Returns:
operation result status and command type

Definition at line 174 of file classadlogparser.cpp.

References curCALogEntry, ClassAdLogEntry::init(), lastCALogEntry, ClassAdLogEntry::next_offset, nextOffset, ClassAdLogEntry::offset, ClassAdLogEntry::op_type, MyString::readLine(), and MyString::Value().

Referenced by JobQueueDBManager::buildJobQueue(), Prober::probe(), and JobQueueDBManager::readAndWriteLogEntries().

{
      int   rval;

      if (ex == false) { // Standard File I/O Operations
            // move to the current offset
            if (lseek(log_fd, nextOffset, SEEK_SET) != nextOffset) {
                  close(log_fd);
                  log_fd = -1;
                  return FILE_READ_EOF;
            }

            rval = readHeader(log_fd, op_type);
            if (rval < 0) {
              close(log_fd);
              log_fd = -1;
              return FILE_READ_EOF;
            }

      }
      else { // File Stream I/O Operations
            // move to the current offset
            if (fseek(log_fp, nextOffset, SEEK_SET) != nextOffset) {
                  fclose(log_fp);
                  log_fp = NULL;
                  return FILE_READ_EOF;
            }

            rval = readHeader(log_fp, op_type);
            if (rval < 0) {
              fclose(log_fp);
              log_fp = NULL;
              return FILE_READ_EOF;
            }
      }

            // initialize of current & last ClassAd Log Entry objects
      lastCALogEntry.init(curCALogEntry.op_type);
      lastCALogEntry = curCALogEntry;
      curCALogEntry.init(op_type);
      curCALogEntry.offset = nextOffset;


            // read a ClassAd Log Entry Body
      switch(op_type) {
          case CondorLogOp_LogHistoricalSequenceNumber:
                  if(ex == false) {
                        rval = readLogHistoricalSNBody(log_fd);
                  }
                  else {
                        rval = readLogHistoricalSNBody(log_fp);
                  }
                  break;
          case CondorLogOp_NewClassAd:
                  if (ex == false) {
                        rval = readNewClassAdBody(log_fd);
                  }
                  else {
                        rval = readNewClassAdBody(log_fp);
                  }
                  break;
          case CondorLogOp_DestroyClassAd:
                  if (ex == false) {
                        rval = readDestroyClassAdBody(log_fd);
                  }
                  else {
                        rval = readDestroyClassAdBody(log_fp);
                  }
                  break;
          case CondorLogOp_SetAttribute:
                  if (ex == false) {
                        rval = readSetAttributeBody(log_fd);
                  }
                  else {
                        rval = readSetAttributeBody(log_fp);
                  }
                  break;
          case CondorLogOp_DeleteAttribute:
                  if (ex == false) {
                        rval = readDeleteAttributeBody(log_fd);
                  }
                  else {
                        rval = readDeleteAttributeBody(log_fp);
                  }
                  break;
            case CondorLogOp_BeginTransaction:
                  if (ex == false) {
                        rval = readBeginTransactionBody(log_fd);
                  }
                  else {
                        rval = readBeginTransactionBody(log_fp);
                  }
                  break;
            case CondorLogOp_EndTransaction:
                  if (ex == false) {
                        rval = readEndTransactionBody(log_fd);
                  }
                  else {
                        rval = readEndTransactionBody(log_fp);
                  }
                  break;
          default:
                  if(ex == false) {
                        close(log_fd);
                        log_fd = -1;
                  }
                  else {
                        fclose(log_fp);
                        log_fp = NULL;
                  }
                return FILE_READ_ERROR;
                  break;
      }

      if (rval < 0) {

                  //
                  // This code block is borrowed from log.C 
                  //
            
                  // check if this bogus record is in the midst of a transaction
                  // (try to find a CloseTransaction log record)
            
            MyString    line;
            FILE  *fp;
            if (ex == false) {
                  fp = fdopen(log_fd, "r" );
            }
            else {
              fp = log_fp;
            }
            int         op;

            if( !fp ) {
                  EXCEPT("Failed fdopen() when recovering corrupt log file");
            }

            while( line.readLine( fp ) ) {
                  if( sscanf( line.Value(), "%d ", &op ) != 1 ) {
                              // no op field in line; more bad log records...
                        continue;
                  }
                  if( op == CondorLogOp_EndTransaction ) {
                              // aargh!  bad record in transaction.  abort!
                        EXCEPT("Bad record with op=%d in corrupt logfile",
                                 op_type);
                  }
            }
            
            if( !feof( fp ) ) {
                  fclose(fp);
                  EXCEPT("Failed recovering from corrupt file, errno=%d",
                           errno );
            }

                  // there wasn't an error in reading the file, and the bad log 
                  // record wasn't bracketed by a CloseTransaction; ignore all
                  // records starting from the bad record to the end-of-file, and
            
                  // pretend that we hit the end-of-file.
            fclose( fp );

            curCALogEntry = lastCALogEntry;
            curCALogEntry.offset = nextOffset;

            return FILE_READ_EOF;
      }


      // get and set the new current offset
      if (ex == false) {
            nextOffset = lseek(log_fd, 0, SEEK_CUR);
      }
      else {
            nextOffset = ftell(log_fp);
      }

      curCALogEntry.next_offset = nextOffset;

      return FILE_READ_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index