Kids.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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  for (int i = 0; i < Config.workers; ++i)
33  storage.emplace_back("squid", storage.size() + 1);
34 
35  // add Kid records for all disk processes
36  for (int i = 0; i < Config.cacheSwap.n_strands; ++i)
37  storage.emplace_back("squid-disk", storage.size() + 1);
38 
39  // if coordination is needed, add a Kid record for Coordinator
40  if (storage.size() > 1)
41  storage.emplace_back("squid-coord", storage.size() + 1);
42 
43  Must(storage.size() == static_cast<size_t>(NumberOfKids()));
44 }
45 
48 {
49  assert(pid > 0);
50  assert(count() > 0);
51 
52  for (size_t i = 0; i < storage.size(); ++i) {
53  if (storage[i].getPid() == pid)
54  return &storage[i];
55  }
56  return NULL;
57 }
58 
60 Kid& Kids::get(size_t i)
61 {
62  assert(i < count());
63  return storage[i];
64 }
65 
67 bool Kids::allHopeless() const
68 {
69  for (size_t i = 0; i < storage.size(); ++i) {
70  if (!storage[i].hopeless())
71  return false;
72  }
73  return true;
74 }
75 
76 void
78 {
79  for (auto &kid: storage)
80  kid.forgetFailures();
81 }
82 
83 time_t
85 {
86  time_t nextCheckDelay = 0;
87  for (auto &kid: storage) {
88  if (!kid.hopeless())
89  continue;
90 
91  const auto deathDuration = kid.deathDuration(); // protect from time changes
92  if (Config.hopelessKidRevivalDelay <= deathDuration) {
93  kid.forgetFailures(); // this kid will be revived now
94  continue;
95  }
96 
97  const auto remainingDeathTime = Config.hopelessKidRevivalDelay - deathDuration;
98  assert(remainingDeathTime > 0);
99  if (remainingDeathTime < nextCheckDelay || !nextCheckDelay)
100  nextCheckDelay = remainingDeathTime;
101  }
102  return nextCheckDelay; // still zero if there were no still-hopeless kids
103 }
104 
107 {
108  for (size_t i = 0; i < storage.size(); ++i) {
109  if (!storage[i].exitedHappy())
110  return false;
111  }
112  return true;
113 }
114 
116 bool Kids::someSignaled(const int sgnl) const
117 {
118  for (size_t i = 0; i < storage.size(); ++i) {
119  if (storage[i].signaled(sgnl))
120  return true;
121  }
122  return false;
123 }
124 
126 bool Kids::someRunning() const
127 {
128  for (size_t i = 0; i < storage.size(); ++i) {
129  if (storage[i].running())
130  return true;
131  }
132  return false;
133 }
134 
137 {
138  for (size_t i = 0; i < storage.size(); ++i) {
139  if (storage[i].shouldRestart())
140  return true;
141  }
142  return false;
143 }
144 
146 size_t Kids::count() const
147 {
148  return storage.size();
149 }
150 
std::vector< Kid > storage
Definition: Kids.h:62
SBuf TheKidName
current Squid process name (e.g., &quot;squid-coord&quot;)
Definition: Kids.cc:19
#define assert(EX)
Definition: assert.h:17
Definition: SBuf.h:86
int i
Definition: membanger.c:49
#define Must(condition)
Like assert() but throws an exception instead of aborting the process.
Definition: TextException.h:69
size_t count() const
returns the number of kids
Definition: Kids.cc:146
void forgetAllFailures()
forgets all failures in all kids
Definition: Kids.cc:77
bool allHopeless() const
whether all kids are hopeless
Definition: Kids.cc:67
int n_strands
number of disk processes required to support all cache_dirs
Definition: SquidConfig.h:66
bool someRunning() const
whether some kids are running
Definition: Kids.cc:126
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:47
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
static pid_t pid
Definition: IcmpSquid.cc:35
Definition: Kid.h:17
Store::DiskConfig cacheSwap
Definition: SquidConfig.h:422
time_t forgetOldFailures()
Definition: Kids.cc:84
bool shouldRestartSome() const
whether some kids should be restarted by master
Definition: Kids.cc:136
bool someSignaled(const int sgnl) const
whether some kids died from a given signal
Definition: Kids.cc:116
time_t hopelessKidRevivalDelay
hopeless_kid_revival_delay
Definition: SquidConfig.h:103
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:60
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:106

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors