~ubuntu-branches/ubuntu/wily/trafficserver/wily

« back to all changes in this revision

Viewing changes to proxy/congest/Congestion.cc

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2012-12-17 22:28:16 UTC
  • mfrom: (5.1.8 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121217222816-7xwjsx5k76zkb63d
Tags: 3.2.0-1ubuntu1
* Revert FreeBSD strerror_r() fixes that give errors with glibc 2.16.
* Apply patch from Konstantinos Margaritis to define barriers on ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
 
80
80
CongestionControlRecord::CongestionControlRecord(const CongestionControlRecord & rec)
81
81
{
82
 
  prefix = xstrdup(rec.prefix);
 
82
  prefix = ats_strdup(rec.prefix);
83
83
  prefix_len = rec.prefix_len;
84
84
  port = rec.port;
85
85
  congestion_scheme = rec.congestion_scheme;
86
 
  error_page = xstrdup(rec.error_page);
 
86
  error_page = ats_strdup(rec.error_page);
87
87
  max_connection_failures = rec.max_connection_failures;
88
88
  fail_window = rec.fail_window;
89
89
  proxy_retry_interval = rec.proxy_retry_interval;
128
128
 
129
129
#define IsGt0(var)\
130
130
  if ( var < 1 ) { \
131
 
    error_buf = (char*) xmalloc(error_len); \
 
131
    error_buf = (char*)ats_malloc(error_len); \
132
132
    snprintf(error_buf, error_len, "line %d: invalid %s = %d, %s must > 0", \
133
133
            line_num, #var, var, #var); \
134
134
    cleanup(); \
136
136
  }
137
137
 
138
138
  if (error_page == NULL)
139
 
    error_page = xstrdup(DEFAULT_error_page);
 
139
    error_page = ats_strdup(DEFAULT_error_page);
140
140
  if (max_connection_failures >= CONG_RULE_MAX_max_connection_failures ||
141
141
      (max_connection_failures <= 0 && max_connection_failures != CONG_RULE_ULIMITED_max_connection_failures)
142
142
    ) {
143
 
    error_buf = (char *) xmalloc(error_len);
 
143
    error_buf = (char *)ats_malloc(error_len);
144
144
    snprintf(error_buf, error_len, "line %d: invalid %s = %d not in [1, %d) range",
145
145
             line_num, "max_connection_failures", max_connection_failures, CONG_RULE_MAX_max_connection_failures);
146
146
    cleanup();
212
212
        congestion_scheme = PER_IP;
213
213
      }
214
214
    } else if (strcasecmp(label, "error_page") == 0) {
215
 
      error_page = xstrdup(val);
 
215
      error_page = ats_strdup(val);
216
216
    } else if (strcasecmp(label, "prefix") == 0) {
217
 
      prefix = xstrdup(val);
 
217
      prefix = ats_strdup(val);
218
218
      prefix_len = strlen(prefix);
219
219
      rank += 1;
220
220
      // prefix will be used in the ControlBase
234
234
    tmp = ProcessModifiers(line_info);
235
235
 
236
236
    if (tmp != NULL) {
237
 
      errBuf = (char *) xmalloc(errBufLen * sizeof(char));
 
237
      errBuf = (char *)ats_malloc(errBufLen * sizeof(char));
238
238
      snprintf(errBuf, errBufLen, "%s %s at line %d in congestion.config", congestPrefix, tmp, line_num);
239
239
      return errBuf;
240
240
    }
275
275
      }
276
276
    }
277
277
    pRule->record = this;
278
 
    Debug("congestion_config", "Matched with record 0x%x at line %d", this, line_num);
 
278
    Debug("congestion_config", "Matched with record %p at line %d", this, line_num);
279
279
  }
280
280
}
281
281
 
455
455
}
456
456
 
457
457
uint64_t
458
 
make_key(char *hostname, unsigned long ip, CongestionControlRecord * record)
 
458
make_key(char *hostname, sockaddr const* ip, CongestionControlRecord * record)
459
459
{
460
460
  int host_len = 0;
461
461
  if (hostname) {
465
465
}
466
466
 
467
467
uint64_t
468
 
make_key(char *hostname, int len, unsigned long ip, CongestionControlRecord * record)
 
468
make_key(char *hostname, int len, sockaddr const* ip, CongestionControlRecord * record)
469
469
{
470
470
  INK_MD5 md5;
471
471
#ifdef USE_MMH
474
474
  if (record->congestion_scheme == PER_HOST && len > 0)
475
475
    ink_code_incr_MMH_update(&ctx, hostname, len);
476
476
  else
477
 
    ink_code_incr_MMH_update(&ctx, (char *) &ip, sizeof(ip));
 
477
    ink_code_incr_MMH_update(&ctx, reinterpret_cast<char const*>(ats_ip_addr8_cast(ip)), ats_ip_addr_size(ip));
478
478
  if (record->port != 0) {
479
479
    unsigned short p = port;
480
480
    p = htons(p);
490
490
  if (record->congestion_scheme == PER_HOST && len > 0)
491
491
    ink_code_incr_md5_update(&ctx, hostname, len);
492
492
  else
493
 
    ink_code_incr_md5_update(&ctx, (char *) &ip, sizeof(ip));
 
493
    ink_code_incr_md5_update(&ctx, reinterpret_cast<char const*>(ats_ip_addr8_cast(ip)), ats_ip_addr_size(ip));
494
494
  if (record->port != 0) {
495
495
    unsigned short p = record->port;
496
496
    p = htons(p);
505
505
}
506
506
 
507
507
uint64_t
508
 
make_key(char *hostname, int len, unsigned long ip, char *prefix, int prelen, short port)
 
508
make_key(char *hostname, int len, sockaddr const* ip, char *prefix, int prelen, short port)
509
509
{
510
510
  /* if the hostname != NULL, use hostname, else, use ip */
511
511
  INK_MD5 md5;
515
515
  if (hostname && len > 0)
516
516
    ink_code_incr_MMH_update(&ctx, hostname, len);
517
517
  else
518
 
    ink_code_incr_MMH_update(&ctx, (char *) &ip, sizeof(ip));
 
518
    ink_code_incr_MMH_update(&ctx, reinterpret_cast<char const*>(ats_ip_addr8_cast(ip)), ats_ip_addr_size(ip));
519
519
  if (port != 0) {
520
520
    unsigned short p = port;
521
521
    p = htons(p);
531
531
  if (hostname && len > 0)
532
532
    ink_code_incr_md5_update(&ctx, hostname, len);
533
533
  else
534
 
    ink_code_incr_md5_update(&ctx, (char *) &ip, sizeof(ip));
 
534
    ink_code_incr_md5_update(&ctx, reinterpret_cast<char const*>(ats_ip_addr8_cast(ip)), ats_ip_addr_size(ip));
535
535
  if (port != 0) {
536
536
    unsigned short p = port;
537
537
    p = htons(p);
608
608
//----------------------------------------------------------
609
609
// CongestionEntry Implementation
610
610
//----------------------------------------------------------
611
 
CongestionEntry::CongestionEntry(const char *hostname, ip_addr_t ip, CongestionControlRecord * rule, uint64_t key)
 
611
CongestionEntry::CongestionEntry(const char *hostname, sockaddr const* ip, CongestionControlRecord * rule, uint64_t key)
612
612
:m_key(key),
613
 
m_ip(ip),
614
613
m_last_congested(0),
615
614
m_congested(0),
616
615
m_stat_congested_conn_failures(0),
617
616
m_M_congested(0), m_last_M_congested(0), m_num_connections(0), m_stat_congested_max_conn(0), m_ref_count(1)
618
617
{
619
 
  m_hostname = xstrdup(hostname);
 
618
  memset(&m_ip, 0, sizeof(m_ip));
 
619
  if (ip != NULL) {
 
620
    ats_ip_copy(&m_ip.sa, ip);
 
621
  }
 
622
  m_hostname = ats_strdup(hostname);
620
623
  rule->get();
621
624
  pRecord = rule;
622
625
  clearFailHistory();
648
651
  }
649
652
 
650
653
  uint64_t key = make_key(m_hostname,
651
 
                        m_ip,
 
654
                        &m_ip.sa,
652
655
                        p);
653
656
  if (key != m_key) {
654
657
    return false;
696
699
int
697
700
CongestionEntry::sprint(char *buf, int buflen, int format)
698
701
{
699
 
  struct in_addr addr;
700
702
  char str_time[100] = " ";
 
703
  char addrbuf[INET6_ADDRSTRLEN];
701
704
  int len = 0;
702
705
  ink_hrtime timestamp = 0;
703
706
  char state;
711
714
  len += snprintf(buf + len, buflen - len, "%" PRId64 "|%d|%s|%s",
712
715
                      timestamp,
713
716
                      pRecord->line_num,
714
 
                      (m_hostname ? m_hostname : " "), (m_ip ? (addr.s_addr = htonl(m_ip), inet_ntoa(addr)) : " "));
 
717
                      (m_hostname ? m_hostname : " "), (ats_is_ip(&m_ip) ? ats_ip_ntop(&m_ip.sa, addrbuf, sizeof(addrbuf)) : " "));
715
718
 
716
719
  len += snprintf(buf + len, buflen - len, "|%s|%s|%c",
717
720
                      (pRecord->congestion_scheme == PER_IP ? "per_ip" : "per_host"),
761
764
    return;
762
765
  // long time = ink_hrtime_to_sec(t);
763
766
  long time = t;
764
 
  Debug("congestion_control", "failed_at: %d", time);
 
767
  Debug("congestion_control", "failed_at: %ld", time);
765
768
  MUTEX_TRY_LOCK(lock, m_hist_lock, this_ethread());
766
769
  if (lock) {
767
770
    m_history.regist_event(time);
774
777
      }
775
778
    }
776
779
  } else {
777
 
    Debug("congestion_control", "failure info lost due to lock contention(Entry: 0x%x, Time: %d)", (void *) this, time);
 
780
    Debug("congestion_control", "failure info lost due to lock contention(Entry: %p, Time: %ld)", (void *) this, time);
778
781
  }
779
782
}
780
783