示例#1
0
static gboolean
_open_diskq(LogThreadedFetcherDriver *s)
{
  ThreadedDiskqSourceDriver *self = (ThreadedDiskqSourceDriver *) s;

  struct stat new_diskq_file_stat;
  if (stat(self->filename, &new_diskq_file_stat) != 0)
    {
      msg_info("Diskq file does now exist, retrying", evt_tag_str("file", self->filename));
      return FALSE;
    }

  if (self->waiting_for_file_change)
    {
      if(!_new_diskq_file_exists(self, &new_diskq_file_stat))
        {
          msg_debug("Still waiting for new file", evt_tag_str("file", self->filename));
          return FALSE;
        }

      self->waiting_for_file_change = FALSE;
    }

  if (!_load_queue(self))
    return FALSE;

  self->diskq_file_stat = new_diskq_file_stat;
  return TRUE;
}
示例#2
0
static gboolean
_load_state(QDisk *self, GQueue *qout, GQueue *qbacklog, GQueue *qoverflow)
{
  gint64 qout_ofs;
  gint qout_count, qout_len;
  gint64 qbacklog_ofs;
  gint qbacklog_count, qbacklog_len;
  gint64 qoverflow_ofs;
  gint qoverflow_count, qoverflow_len;
  gint64 end_ofs;

  if (memcmp(self->hdr->magic, self->file_id, 4) != 0)
    {
      msg_error("Error reading disk-queue file header",
                evt_tag_str("filename", self->filename));
      return FALSE;
    }

  qout_count = self->hdr->qout_count;
  qout_len = self->hdr->qout_len;
  qout_ofs = self->hdr->qout_ofs;
  qbacklog_count = self->hdr->qbacklog_count;
  qbacklog_len = self->hdr->qbacklog_len;
  qbacklog_ofs = self->hdr->qbacklog_ofs;
  qoverflow_count = self->hdr->qoverflow_count;
  qoverflow_len = self->hdr->qoverflow_len;
  qoverflow_ofs = self->hdr->qoverflow_ofs;
  self->read_qout_ofs = qout_ofs;

  if ((self->hdr->read_head < QDISK_RESERVED_SPACE) ||
      (self->hdr->write_head < QDISK_RESERVED_SPACE) ||
      (self->hdr->read_head == self->hdr->write_head && self->hdr->length != 0))
    {
      msg_error("Inconsistent header data in disk-queue file, ignoring",
                evt_tag_str("filename", self->filename),
                evt_tag_int("read_head", self->hdr->read_head),
                evt_tag_int("write_head", self->hdr->write_head),
                evt_tag_int("qdisk_length",  self->hdr->length));
      return FALSE;
    }

  if (!self->options->reliable)
    {
      if (!(qout_ofs > 0 && qout_ofs < self->hdr->write_head))
        {
           if (!_load_queue(self, qout, qout_ofs, qout_len, qout_count))
             return !self->options->read_only;
        }
      else
        {
           msg_error("Inconsistent header data in disk-queue file, ignoring qout",
                    evt_tag_str("filename", self->filename),
                    evt_tag_int("qout_ofs", qout_ofs),
                    evt_tag_int("qdisk_length",  self->hdr->length));
        }

      if (!(qbacklog_ofs > 0 && qbacklog_ofs < self->hdr->write_head))
        {
          if(!_load_queue(self, qbacklog, qbacklog_ofs, qbacklog_len, qbacklog_count))
            return !self->options->read_only;
        }
      else
        {
           msg_error("Inconsistent header data in disk-queue file, ignoring qbacklog",
                    evt_tag_str("filename", self->filename),
                    evt_tag_int("qbacklog_ofs", qbacklog_ofs),
                    evt_tag_int("qdisk_length",  self->hdr->length));
        }

      if (!(qoverflow_ofs > 0 && qoverflow_ofs < self->hdr->write_head))
        {
          if(!_load_queue(self, qoverflow, qoverflow_ofs, qoverflow_len, qoverflow_count))
            return !self->options->read_only;
        }
      else
        {
           msg_error("Inconsistent header data in disk-queue file, ignoring qoverflow",
                    evt_tag_str("filename", self->filename),
                    evt_tag_int("qoverflow_ofs", qoverflow_ofs),
                    evt_tag_int("qdisk_length",  self->hdr->length));
        }
    }

  if (!self->options->read_only)
    {
      end_ofs = qout_ofs;
      if (qbacklog_ofs && qbacklog_ofs < end_ofs)
        end_ofs = qbacklog_ofs;
      if (qoverflow_ofs && qoverflow_ofs < end_ofs)
        end_ofs = qoverflow_ofs;
      if(end_ofs > QDISK_RESERVED_SPACE)
        _truncate_file(self, end_ofs);
    }

  if (!self->options->reliable)
    {
      self->file_size = qout_ofs;

      msg_info("Disk-buffer state loaded",
          evt_tag_str("filename", self->filename),
          evt_tag_int("qout_length", qout_count),
          evt_tag_int("qbacklog_length", qbacklog_count),
          evt_tag_int("qoverflow_length", qoverflow_count),
          evt_tag_int("qdisk_length", self->hdr->length));
    }
  else
    {
      struct stat st;
      fstat(self->fd, &st);
      self->file_size = st.st_size;
      msg_info("Reliable disk-buffer state loaded",
          evt_tag_str("filename", self->filename),
          evt_tag_int("queue_length", self->hdr->length),
          evt_tag_int("size", self->hdr->write_head - self->hdr->read_head));
    }

  return TRUE;
}