Kids.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 54 Interprocess Communication */
10 
11 #include "squid.h"
12 #include "base/TextException.h"
13 #include "globals.h"
14 #include "ipc/Kids.h"
15 #include "SquidConfig.h"
16 #include "tools.h"
17 
20 
22 {
23 }
24 
26 void Kids::init()
27 {
28  storage.clear();
29 
30  storage.reserve(NumberOfKids());
31 
32  char kid_name[32];
33 
34  // add Kid records for all workers
35  for (int i = 0; i < Config.workers; ++i) {
36  snprintf(kid_name, sizeof(kid_name), "(squid-%d)", (int)(storage.size()+1));
37  storage.push_back(Kid(kid_name));
38  }
39 
40  // add Kid records for all disk processes
41  for (int i = 0; i < Config.cacheSwap.n_strands; ++i) {
42  snprintf(kid_name, sizeof(kid_name), "(squid-disk-%d)", (int)(storage.size()+1));
43  storage.push_back(Kid(kid_name));
44  }
45 
46  // if coordination is needed, add a Kid record for Coordinator
47  if (storage.size() > 1) {
48  snprintf(kid_name, sizeof(kid_name), "(squid-coord-%d)", (int)(storage.size()+1));
49  storage.push_back(Kid(kid_name));
50  }
51 
52  Must(storage.size() == static_cast<size_t>(NumberOfKids()));
53 }
54 
57 {
58  assert(pid > 0);
59  assert(count() > 0);
60 
61  for (size_t i = 0; i < storage.size(); ++i) {
62  if (storage[i].getPid() == pid)
63  return &storage[i];
64  }
65  return NULL;
66 }
67 
69 Kid& Kids::get(size_t i)
70 {
71  assert(i < count());
72  return storage[i];
73 }
74 
76 bool Kids::allHopeless() const
77 {
78  for (size_t i = 0; i < storage.size(); ++i) {
79  if (!storage[i].hopeless())
80  return false;
81  }
82  return true;
83 }
84 
85 void
87 {
88  for (auto &kid: storage)
89  kid.forgetFailures();
90 }
91 
92 time_t
94 {
95  time_t nextCheckDelay = 0;
96  for (auto &kid: storage) {
97  if (!kid.hopeless())
98  continue;
99 
100  const auto deathDuration = kid.deathDuration(); // protect from time changes
101  if (Config.hopelessKidRevivalDelay <= deathDuration) {
102  kid.forgetFailures(); // this kid will be revived now
103  continue;
104  }
105 
106  const auto remainingDeathTime = Config.hopelessKidRevivalDelay - deathDuration;
107  assert(remainingDeathTime > 0);
108  if (remainingDeathTime < nextCheckDelay || !nextCheckDelay)
109  nextCheckDelay = remainingDeathTime;
110  }
111  return nextCheckDelay; // still zero if there were no still-hopeless kids
112 }
113 
116 {
117  for (size_t i = 0; i < storage.size(); ++i) {
118  if (!storage[i].exitedHappy())
119  return false;
120  }
121  return true;
122 }
123 
125 bool Kids::someSignaled(const int sgnl) const
126 {
127  for (size_t i = 0; i < storage.size(); ++i) {
128  if (storage[i].signaled(sgnl))
129  return true;
130  }
131  return false;
132 }
133 
135 bool Kids::someRunning() const
136 {
137  for (size_t i = 0; i < storage.size(); ++i) {
138  if (storage[i].running())
139  return true;
140  }
141  return false;
142 }
143 
146 {
147  for (size_t i = 0; i < storage.size(); ++i) {
148  if (storage[i].shouldRestart())
149  return true;
150  }
151  return false;
152 }
153 
155 size_t Kids::count() const
156 {
157  return storage.size();
158 }
159 
std::vector< Kid > storage
Definition: Kids.h:62
KidName TheKidName
current Squid process name
Definition: Kids.cc:19
#define assert(EX)
Definition: assert.h:17
char KidName[64]
Squid process name (e.g., "squid-coord")
Definition: Kids.h:67
int i
Definition: membanger.c:49
size_t count() const
returns the number of kids
Definition: Kids.cc:155
void forgetAllFailures()
forgets all failures in all kids
Definition: Kids.cc:86
bool allHopeless() const
whether all kids are hopeless
Definition: Kids.cc:76
int n_strands
number of disk processes required to support all cache_dirs
Definition: SquidConfig.h:62
bool someRunning() const
whether some kids are running
Definition: Kids.cc:135
void init()
initialize all kid records based on Config
Definition: Kids.cc:26
Kid * find(pid_t pid)
returns kid by pid
Definition: Kids.cc:56
int NumberOfKids()
number of Kid processes as defined in src/ipc/Kid.h
Definition: tools.cc:686
a collection of kids
Definition: Kids.h:17
#define Must(cond)
Definition: TextException.h:89
static pid_t pid
Definition: IcmpSquid.cc:35
Definition: Kid.h:17
Store::DiskConfig cacheSwap
Definition: SquidConfig.h:418
time_t forgetOldFailures()
Definition: Kids.cc:93
bool shouldRestartSome() const
whether some kids should be restarted by master
Definition: Kids.cc:145
bool someSignaled(const int sgnl) const
whether some kids died from a given signal
Definition: Kids.cc:125
time_t hopelessKidRevivalDelay
hopeless_kid_revival_delay
Definition: SquidConfig.h:99
Kids TheKids
All kids being maintained.
Definition: Kids.cc:18
Kid & get(size_t i)
returns the kid by index, useful for kids iteration
Definition: Kids.cc:69
Kids()
Definition: Kids.cc:21
class SquidConfig Config
Definition: SquidConfig.cc:12
#define NULL
Definition: types.h:166
bool allExitedHappy() const
whether all kids called exited happy
Definition: Kids.cc:115

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors